Skip to content

\TwigBridge\Extension\Laravel\Session is broken #280

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

Closed
mnpenner opened this issue Oct 2, 2016 · 5 comments
Closed

\TwigBridge\Extension\Laravel\Session is broken #280

mnpenner opened this issue Oct 2, 2016 · 5 comments

Comments

@mnpenner
Copy link

mnpenner commented Oct 2, 2016

\TwigBridge\Extension\Laravel\Session type-hints against \Illuminate\Session\SessionManager but I'm pretty sure it should be \Illuminate\Session\Store.

What you had there was working fine until just recently when I updated my packages. I wish I could tell you what exactly broke it, but I couldn't get it working again even after I rolled all my packages back to what I had in my old composer.lock file.

I upgraded from Laravel 5.2.5 to 5.2.45.

My log blows up with errors; here's just one of the exceptions I get:

Next exception 'ErrorException' with message 'An exception has been thrown during the compilation of a template ("Method Illuminate\Session\SessionManager::token() does not exist") in "partials/head.twig".' in /srv/myproject/resources/views/partials/head.twig:-1
Stack trace:
#0 /srv/myproject/vendor/rcrowe/twigbridge/src/Engine/Twig.php(92): TwigBridge\Engine\Twig->handleTwigError(Object(Twig_Error_Syntax))
#1 /srv/myproject/vendor/laravel/framework/src/Illuminate/View/View.php(149): TwigBridge\Engine\Twig->get('/srv/myproject...', Array)
#2 /srv/myproject/vendor/laravel/framework/src/Illuminate/View/View.php(120): Illuminate\View\View->getContents()
#3 /srv/myproject/vendor/laravel/framework/src/Illuminate/View/View.php(85): Illuminate\View\View->renderContents()
#4 /srv/myproject/vendor/laravel/framework/src/Illuminate/Http/Response.php(53): Illuminate\View\View->render()
#5 /srv/myproject/vendor/symfony/http-foundation/Response.php(201): Illuminate\Http\Response->setContent(Object(Illuminate\View\View))
#6 /srv/myproject/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(57): Symfony\Component\HttpFoundation\Response->__construct(Object(Illuminate\View\View), 500, Array)
#7 /srv/myproject/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(71): Illuminate\Routing\ResponseFactory->make(Object(Illuminate\View\View), 500, Array)
#8 /srv/myproject/app/Exceptions/Handler.php(99): Illuminate\Routing\ResponseFactory->view('errors/500', Array, 500)
#9 /srv/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(291): App\Exceptions\Handler->render(Object(Illuminate\Http\Request), Object(ErrorException))
#10 /srv/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(103): Illuminate\Foundation\Http\Kernel->renderException(Object(Illuminate\Http\Request), Object(ErrorException))
#11 /srv/myproject/public/index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#12 {main}
[2016-10-02 23:33:24] development.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Uncaught exception 'ReflectionException' with message 'Method Illuminate\Session\SessionManager::token() does not exist' in /srv/myproject/vendor/twig/twig/lib/Twig/Node/Expression/Call.php:262
Stack trace:
#0 /srv/myproject/vendor/twig/twig/lib/Twig/Node/Expression/Call.php(262): ReflectionMethod->__construct(Object(Illuminate\Session\SessionManager), 'token')
#1 /srv/myproject/vendor/twig/twig/lib/Twig/Node/Expression/Call.php(22): Twig_Node_Expression_Call->reflectCallable(Array)
#2 /srv/myproject/vendor/twig/twig/lib/Twig/Node/Expression/Function.php(36): Twig_Node_Expression_Call->compileCallable(Object(Twig_Compiler))
#3 /srv/myproject/vendor/twig/twig/lib/Twig/Compiler.php(105): Twig_Node_Expression_Function->compile(Object(Twig_Compiler))
#4 /srv/myproject/vendor/twig/twig/lib/Twig/Node/Print.php(30): Twig_Compiler->subcompile(Object(Twig_Node_Expression_Function))
#5 /srv/myproject/vendor/twig/twig/lib/Twig/Node.php(117): Twig_Node_Print->compile(Object(Twig_Compiler))
#6 /srv/myproject/vendo' in /srv/myproject/resources/views/partials/head.twig:-1
Stack trace:
#0 {main}

If you check out \Illuminate\Session\SessionManager, it indeed does not have a method called get but \Illuminate\Session\Store does, so I think this is right.

I was only able to figure this out because of Otwell's blog post in which has this snippet:

<?php

class HomeController extends BaseController {

    public function __construct(Illuminate\Session\Store $session)
    {
        $this->session = $session;
    }

}
@barryvdh
Copy link
Collaborator

barryvdh commented Oct 3, 2016

Can you submit a PR? And does it fix your problem?

@SergeyMiracle
Copy link

I guess same issue here
"Method Illuminate\Auth\AuthManager::user() does not exist"

@F1NaL
Copy link

F1NaL commented Oct 3, 2016

@SergeyMiracle
#282 - work to me

@JC5
Copy link

JC5 commented Oct 5, 2016

Same here, but I get An exception has been thrown during the compilation of a template ("Method Illuminate\Session\SessionManager::token() does not exist") in "./layout/default.twig".

@mnpenner
Copy link
Author

mnpenner commented Oct 5, 2016

Looks like @lbausch beat me to it. (Thank you!)

That's pretty much the exact fix I did locally, so that should work perfectly.

@barryvdh barryvdh closed this as completed Oct 5, 2016
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

5 participants