diff --git a/src/Extension/Laravel/Auth.php b/src/Extension/Laravel/Auth.php index fffa0783..1b2a96c3 100644 --- a/src/Extension/Laravel/Auth.php +++ b/src/Extension/Laravel/Auth.php @@ -49,10 +49,27 @@ public function getName() public function getFunctions() { return [ - new Twig_SimpleFunction('auth_check', [$this->auth, 'check']), - new Twig_SimpleFunction('auth_guest', [$this->auth, 'guest']), - new Twig_SimpleFunction('auth_user', [$this->auth, 'user']), + new Twig_SimpleFunction('auth_check', $this->generateCallable('check')), + new Twig_SimpleFunction('auth_guest', $this->generateCallable('guest')), + new Twig_SimpleFunction('auth_user', $this->generateCallable('user')), new Twig_SimpleFunction('auth_guard', [$this->auth, 'guard']), ]; } + + /** + * Generates a callable using a guard for the AuthManager + * + * @param $methodName + * + * @return \Closure + */ + private function generateCallable($methodName) + { + return function ($guard = 'web') use ($methodName) { + $params = func_get_args(); + $guard = array_shift($params); + + return $this->auth->guard($guard)->$methodName($params); + }; + } }