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