Daily laravel-20160801| Container-4

Source: Internet
Author: User

    /** * Register A binding with the container.     * Register a binding with the container. * @param string|array $abstract * @param \closure|string|null $concrete * @param b Ool $shared * @return void * /     Public  function bind($abstract, $concrete = null, $shared = False )    {//bind abstract con        $abstract=$this->normalize ($abstract);//Get the right normalize        $concrete=$this->normalize ($concrete);//Get the right concrete        //If The given types is actually an array, we'll assume an alias is being        //defined and would grab this ' real ' abstract class name and register this        //alias with the container so, it can be used as a shortcut for it.        //Now I say,if they give us a array with a types.        //So we need does something for it,        //If the "real" abstract class name is too long,        //We can use alias to defined the real class name as a shortcut name.        if(Is_array ($abstract)) {//Check the abstract name is a array            List($abstract,$alias) =$this->extractalias ($abstract);//A array one is abstract, and other is alias            $this->alias ($abstract,$alias);//Return the result to the alias.}//If No concrete type was given, we'll simply set the concrete type to the        //abstract type. This would allow concrete type registered as shared        //without being forced to state their classes in both of the parameter.        //I coming, if never give us a concrete type class, we'll use a abstract type.        //So they would be registered as shared.        //No forced to state their classes in both of the parameter        $this->dropstaleinstances ($abstract);//Then can drop the state Instances.        if(Is_null ($concrete)) {$concrete=$abstract; }//If the concrete is null        //If The factory is not a Closure, it means it's just a class name which is        //bound into this container to the abstract type and we'll just wrap it        //Up inside it own Closure to give us more convenience when extending.        //If the instance of concrete not a Closure.        //So it means it just a class name is used bound to a container.        //May was it is a abstract type.        //So we can use this self own Closure to wrap it.        //To give us more function when it extending        if(!$concrete instanceofClosure) {$concrete=$this->getclosure ($abstract,$concrete); }//Get the Closure, more like hooks        $this->bindings[$abstract] = Compact (' Concrete ',' Shared ');//A shared        //If The abstract type is already resolved in this container we 'll fire the        //Rebound listener So, any objects which has already gotten resolved        //can have their copy of the object updated via the listener callbacks.        //If the class name is a ready resolved in the container.        //So we'll fire the rebound listener.        /So, any objects which has already gotten resolved can have their copy        //via the listener callbacks        if($this->resolved ($abstract)) {// has the resolved            $this->rebound ($abstract);//Set the rebound}    }//Too long too not simple

Laravel-20160801| per day Container-4

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.