Can the constructor in Laravel automatically pass in a new parameter?

Source: Internet
Author: User
This is the AuthGuard constructor in Laravel: {code ...} the SessionStore $ session parameter is passed in, but the session constructor is like this: {code ...} here there are parameters. Why does the Guard constructor automatically generate a session? Is provided by php native... this is LaravelMedium Auth\GuardConstructor:

    /**     * 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;    }

Parameters are input.SessionStore $session
HoweversessionThe constructor of is as follows:

public function __construct($name, SessionHandlerInterface $handler, $id = null)    {        $this->setId($id);        $this->name = $name;        $this->handler = $handler;        $this->metaBag = new MetadataBag;    }

There are parameters here. Why?GuardThe constructor of can be automatically generated.session?
YesphpNative providesLaravelProvided?

Reply content:

This isLaravelMediumAuth\GuardConstructor:

    /**     * 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;    }

Parameters are input.SessionStore $session
HoweversessionThe constructor of is as follows:

public function __construct($name, SessionHandlerInterface $handler, $id = null)    {        $this->setId($id);        $this->name = $name;        $this->handler = $handler;        $this->metaBag = new MetadataBag;    }

There are parameters here. Why?GuardThe constructor of can be automatically generated.session?
YesphpNative providesLaravelProvided?

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']);}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.