标签:function return public method null
/**
* Call the given Closure / class@method and inject its dependencies.
*
* @param callable|string $callback
* @param array $parameters
* @param string|null $defaultMethod
* @return mixed
*/
// call the given Closure like class method
// then inject its dependencies.
public function call($callback, array $parameters = [], $defaultMethod = null)
{// parameter has callback parameters and defaultMethod
if ($this->isCallableWithAtSign($callback) || $defaultMethod) {// if it can be call and has the defaultMethod
return $this->callClass($callback, $parameters, $defaultMethod);// everything has two branch at least
}
$dependencies = $this->getMethodDependencies($callback, $parameters);// get the dependencies method by callback and parameter
return call_user_func_array($callback, $dependencies);// call is a big call method
}// call the function by callback and parameter and default method
/**
* Determine if the given string is in Class@method syntax.
*
* @param mixed $callback
* @return bool
*/
// check the given string is in Class@method type
// syntax is a normal type
protected function isCallableWithAtSign($callback)
{
if (! is_string($callback)) {
return false;
}// must be string
return strpos($callback, ‘@‘) !== false; // must has @
}// or return false
/**
* Get all dependencies for a given method.
*
* @param callable|string $callback
* @param array $parameters
* @return array
*/
// Get all dependencies for a given method.
protected function getMethodDependencies($callback, array $parameters = [])// callback and parameter
{
$dependencies = [];// set array store
foreach ($this->getCallReflector($callback)->getParameters() as $parameter) {
// loop the reflector functions as the parameter
$this->addDependencyForCallParameter($parameter, $parameters, $dependencies);// add the Depend
}
return array_merge($dependencies, $parameters);// get the result
}本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1774962
每天laravel-20160810| Container -13
标签:function return public method null
原文地址:http://jingshanls.blog.51cto.com/3357095/1774962