Daily laravel-20160812| Container-15

Source: Internet
Author: User

/** * resolve the given type from the container. * * @ param  string   $abstract  *  @param   array    $parameters  *  @return  mixed */ // get the given type from the  containerpublic function make ($abstract, array  $parameters  = []) {//  this function name  "Make"  like compile c file to binary file  in the linux     $abstract  =  $this->getalias ($this Normalize ($abstract));     // first get the alias as the  new name    // if an instance of the type is  currently being managed as a singleton we ' ll    //  just return an existing instance instead of instantiating new instances     // so the developer can keep using the same objects  instance every time.    if  (Isset ($this->instances[$abstract])  {         return  $this->instances[$abstract];     }// like normal method // if it is exist ,we will  return it, that ok;     $concrete  =  $this->getconcrete ($ abstract);// concrete like create it done    // we ' re  Ready to instantiate an instance of the concrete type registered  for    // the binding. This will instantiate the  Types, as well as resolve any of    // its  "Nested"  dependencies  recursively until all have gotten resolved.    if  ($this- >isbuildable ($concrete,  $abstract))  {// isBuildable          $object  =  $this->build ($concrete,  $parameters);// check it is  can be Builda    } else {          $object  =  $this->make ($concrete,  $parameters);    }     // If we defined any extenders for this type,  we ' ll need to spin through them    // and apply  them to the object being built. this allows for the  extension    // of services, such as changing configuration or decorating the  object.    foreach  ($this->getextenders ($abstract)  as  $extender)  {          $object  =  $extender ($object,  $this);     }// to though , a extender done is too trouble     // if the requested type is registered as a  singleton we ' ll want to cache off    // the  instances in  "Memory"  so we can return it later without  Creating an    // entirely new instance of an object  on each subsequent request for it.    if  ($this IsShared ($abstract))  {         $this->instances[$abstract] =  $object;     }// get the instance from the  "Memory"      $this Fireresolvingcallbacks ($abstract,  $object);     $this->resolved[$abstract] =  true;    return  $object;}  in the last we will found it is a compatible way  to get you want object./** * get the concrete type for  a given abstract. * *  @param   string   $abstract  *   @return  mixed    $concrete  */protected function getconcrete ($abstract) {// get a concrete type for a abstract    if  (!  is_null ($concrete  =  $this->getcontextualconcrete ($abstract)) &NBSp {        return  $concrete;     }// if  you can get it ,then return it // otherwise see next     // if we don ' T have a registered resolver or  concrete for the type, we ' ll just    // assume  Each type is a concrete name and will attempt to resolve  it as is    // since the container should be  able to resolve concretes automatically.    if  (!  Isset ($this->bindings[$abstract])  {        return $ abstract;    }// return it back    return  $this- >bindings[$abstract [' Concrete '];}Last we will binding it 

This article is from the "Focus on PHP" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1782012

Daily laravel-20160812| Container-15

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.