/** * Call the given Closure / [email protected] 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 [email protected] syntax. * * @param mixed $callback * @return bool */ // check the given string is in [email protected] 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 }
时间: 2024-11-06 19:24:03