Daily laravel-20160804| Container-7

Source: Internet
Author: User

 /**  * Wrap a Closure such that it is shared.   *  *  @param   \Closure   $closure   *  @return  \ Closure  */ public function share (closure  $closure)// because this  so we need php version is 5.4+ {// wrap a closure  such that is shared     return function  ($container)  use  ($closure)  {         // we ' ll  simply declare a static variable within the closures and if  it has         // not been set we  will execute the given closures to resolve this value         &nbsP;// and return it back to these consumers of the method  as an instance.         static  $object;//  check has, or closure it.         if   (Is_null ($object))  {             $ object =  $closure ($container);// use a closure class to bind to  the container         }          return  $object;      };// a closure class  is a special class } /**  *  "Extend"  an abstract  type in the container.  *  *  @param   string      $abstract  &Nbsp;*  @param   \Closure   $closure   *  @return  void  *   *  @throws  \invalidargumentexception  */ public function extend ( $abstract, closure  $closure)// a extend type ,parameter is a  abstract class,and other is closure. {      $abstract  =   $this->normalize ($abstract);// get  a normal string that we  need     if  (Isset ($this->instances[$abstract])  {// check it  is set in the instance array,           $this->instances[$abstract] =  $closure ($this->instances[$abstract],  $this);//  if isset ,use the closure function to action about it.           $this->rebound ($abstract);// get the rebound function      } else {          $this->extenders[ $abstract][] =  $closure;// set the extender     } }


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

Daily laravel-20160804| Container-7

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.