Open danhofmann-com opened 5 years ago
Here is another example of a use case:
use League\Container\ServiceProvider\AbstractServiceProvider; use Jenssegers\Blade\Blade;
class TemplateServiceProvider extends AbstractServiceProvider { /**
{@inheritdoc} */ public function register() { $config = $this->getContainer()->get('config');
$this->getContainer()->share('Blade', function () use ($config) {
$blade = new Blade($config['app']['template-views'], $config['app']['template-cache']);
// register view composers
$this->registerViewComposers($config, $blade);
return $blade;
});
}
protected function registerViewComposers(&$config, &$blade) { foreach ($config['app']['view-composers'] as $viewComposers) { foreach ($viewComposers as $view => $viewComposer) { $blade->composer($view, $viewComposer); } } } }
class PartCategories {
const MAX_PART_PER_CATEGORY = 40;
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$container = App::getStaticContainer();
$view = $container->get('Blade');
$hash = $this->createCategorySubCategoryUrlHash();
$view->share('categoryHash', $hash);
...
And even if i try to use the shared() method, to get a previously stored item, it is null
class ProductDetailController extends BaseController {
public function applicationDetail()
{
$container = App::getStaticContainer();
$view = $container->get('Blade');
$categoryHash= $view->shared('categoryHash');
print_pre($categoryHash); die(); // this is null after the update
If I downgrade back to 1.1.0, it works again.
I may have found the issue and started a pull request here : https://github.com/jenssegers/blade/pull/37 hopefully this was the right fix and will solve our problem
I just updated from 1.1.0 to 1.2.1, and $view->blade() no longer works.
In my middlware // this line actually is defined in the initialization portion of my app, and is then stored in a service container. In my middleware, I grab the $blade object from the container, and call share(), and then later, in my controller, I get the $blade object from the container once again, and call make() $blade = new Blade($config['app']['template-views'], $config['app']['template-cache']); // hash is not empty, it is an array $blade->share('categoryHash', $hash);
In my view: echo (bool) is_null($categoryHash); die();
And the output is 1 (or true), indicating the value is null, when it should contain an array
This works fine in <= 1.1.0, but breaks when I updated to 1.2.1. Am I missing something?