时间:2021-07-01 10:21:17 帮助过:103人阅读
Laravel
中Auth\Guard
的构造函数:
/**
* Create a new authentication guard.
*
* @param \Illuminate\Auth\UserProviderInterface $provider
* @param \Illuminate\Session\Store $session
* @param \Symfony\Component\HttpFoundation\Request $request
* @return void
*/
public function __construct(UserProviderInterface $provider,
SessionStore $session,
Request $request = null)
{
$this->session = $session;
$this->request = $request;
$this->provider = $provider;
}
其中传入了参数SessionStore $session
但是session
的构造函数是这样的:
public function __construct($name, SessionHandlerInterface $handler, $id = null)
{
$this->setId($id);
$this->name = $name;
$this->handler = $handler;
$this->metaBag = new MetadataBag;
}
这里是有参数的,为什么Guard
的构造函数可以自动生成session
?
是php
原生提供的还是Laravel
提供的?
这是Laravel
中Auth\Guard
的构造函数:
/**
* Create a new authentication guard.
*
* @param \Illuminate\Auth\UserProviderInterface $provider
* @param \Illuminate\Session\Store $session
* @param \Symfony\Component\HttpFoundation\Request $request
* @return void
*/
public function __construct(UserProviderInterface $provider,
SessionStore $session,
Request $request = null)
{
$this->session = $session;
$this->request = $request;
$this->provider = $provider;
}
其中传入了参数SessionStore $session
但是session
的构造函数是这样的:
public function __construct($name, SessionHandlerInterface $handler, $id = null)
{
$this->setId($id);
$this->name = $name;
$this->handler = $handler;
$this->metaBag = new MetadataBag;
}
这里是有参数的,为什么Guard
的构造函数可以自动生成session
?
是php
原生提供的还是Laravel
提供的?
https://github.com/laravel/framework/blob/4.2/src/Illuminate/Auth/AuthManager.php#L51
/**
* Create an instance of the Eloquent driver.
*
* @return \Illuminate\Auth\Guard
*/
public function createEloquentDriver()
{
$provider = $this->createEloquentProvider();
return new Guard($provider, $this->app['session.store']);
}