Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from 1.1.0 to 1.2.1 breaks $blade->share() #31

Open
danhofmann-com opened this issue Jun 9, 2019 · 2 comments
Open

Update from 1.1.0 to 1.2.1 breaks $blade->share() #31

danhofmann-com opened this issue Jun 9, 2019 · 2 comments

Comments

@danhofmann-com
Copy link

danhofmann-com commented Jun 9, 2019

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?

@danhofmann-com danhofmann-com changed the title Update from 1.1.0 to 1.2.1 breaks $view->share() Update from 1.1.0 to 1.2.1 breaks $blade->share() Jun 9, 2019
@danhofmann-com
Copy link
Author

Here is another example of a use case:

use League\Container\ServiceProvider\AbstractServiceProvider;
use Jenssegers\Blade\Blade;

class TemplateServiceProvider extends AbstractServiceProvider
{
/**
* @var array
/
protected $provides = [
'Blade'
];
/
*
* {@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.

@amoutonbrady
Copy link
Contributor

I may have found the issue and started a pull request here : #37 hopefully this was the right fix and will solve our problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants