您好,欢迎访问一九零五行业门户网

Laravel中类中的构造函数传参是可以自动new一个传递进去的吗?

这是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']);}
其它类似信息

推荐信息