您的位置:首页 > 编程语言 > PHP开发

每天laravel-20160811| Container -14

2016-05-20 09:37 501 查看
/**
* 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 Class@method 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
// class@method 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
}


本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1775281
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: