Daily laravel-20160811| Container-14

Source: Internet
Author: User

   /**    * get the proper reflection instance  for the given callback.    *    *  @param   callable|string   $callback     *  @return  \ reflectionfunctionabstract    */   protected function  Getcallreflector ($callback)// function name is getcallreflectior   {//  has a way to get the right reflection instance about  the given callback.       if  (is_string ($callback)   && strpos ($callback,  ':: ')  !== false)  {             $callback  = explode (':: ',  $callback);        }// check the callback string is a string , and has the  "::"  then      explode it to the  #callback  array ();        if  (Is_array ($callback))  {            Return new reflectionmethod ($callback [0],  $callback [1]);        }// if is a array , net this reflection Method        return new reflectionfunction ($callback);// third: back  the Reflection Function   }   /**    *  get the dependency for the given call parameter.    *     *  @param   \ReflectionParameter   $parameter      *  @param   array   $parameters     *  @param   array   $dependencies     *  @return  mixed    */// Get the  Dependency for the given call parameter.   protected function  adddependencyforcallparameter (reflectionparameter  $parameter, array & $parameters,  & $dependencies)    {// function name is funny        if  (array_key_exists ($parameter->name,  $parameters))  {// first             $dependencies [] =  $parameters [$ Parameter->name];// if has this array ()           // bad logic           unset ($ parameters[$parameter->name]);// unsEt the array value by key       } elseif   ($parameter->getclass ())  {// second        //  if can get something by  this function             $dependencies [] =  $this->make ($parameter->getclass ()->name); / can be use by       } elseif  ($parameter- >isdefaultvalueavailable ())  {// third             $dependencies [] =  $parameter->getdefaultvalue ();// set the dependencies        }   }// so in the end.// we  find the function has a action to set the dependendcies  by all the parameter   /**    * call a string reference  to a class using [email protected] syntax.    *     *  @param   string   $target     *  @param    array   $parameters     *  @param   string|null  $ defaultmethod    *  @return  mixed    *     *  @throws  \InvalidArgumentException    */   protected  Function callclass ($target, array  $parameters  = [],  $defaultMethod  =  NULL)    {// call a string reference to a class using     // [email protected] syntax       $ Segments = explode ('@ ',  $target);// change string to array       //  If the listener has an @ sign, we will assume it  Is being used to delimit       // the class  name from the handle method name. this allows for handlers        // to run multiple handler methods in  a single class for convenience.        $method  = count ($segments)  == 2 ?  $segments [1] :  $defaultMethod;     // set the default method is null, are you joke,     // they said, if the string include the @  variable    // we will delimit    // maybe it support the  multiple handler,       if  (Is_null ($method))  {            throw new invalidargumentexception (' method not provided. ');        }// throw  Exception        return  $this->call ([$this->make ($segments [0]),  $method],  $parameters);//if  everthing is ok then call it   }


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

Daily laravel-20160811| Container-14

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.