/** * get the contextual concrete binding for the given abstract. * * @param string $abstract * @return string|null */ protected function getcontextualconcrete($abstract) { if (isset($this->contextual[end($this->buildstack)][$abstract])) { return $this->contextual[end($this->buildstack)][$abstract]; } }//has it then return it,// this array is too complex /** * normalize the given class name by removing leading slashes. * * @param mixed $service * @return mixed */ protected function normalize($service) { return is_string($service) ? ltrim($service, '\\') : $service;// back the normal string like namespace }// normalize the given class name by removing leading slashes /** * get the extender callbacks for a given type. * * @param string $abstract * @return array */ protected function getextenders($abstract) { if (isset($this->extenders[$abstract])) {// has then return return $this->extenders[$abstract]; } return []; }// get the extender callbacks for a given type. /** * instantiate a concrete instance of the given type. * * @param string $concrete * @param array $parameters * @return mixed * * @throws \illuminate\contracts\container\bindingresolutionexception */// make a concrete instance of the given type live. public function build($concrete, array $parameters = [])// like to make a floor { // if the concrete type is actually a closure, we will just execute it and // hand back the results of the functions, which allows functions to be // used as resolvers for more fine-tuned resolution of these objects. if ($concrete instanceof closure) { return $concrete($this, $parameters); }// if it a concrete as closure. $reflector = new reflectionclass($concrete);// else throw the concrete function to get the class name // if the type is not instantiable, the developer is attempting to resolve // an abstract type such as an interface of abstract class and there is // no binding registered for the abstractions so we need to bail out. if (! $reflector->isinstantiable()) {// if it a abstract class so can not be instance if (! empty($this->buildstack)) {// if has the buildstack $previous = implode(', ', $this->buildstack);//implode the buildstack $message = target [$concrete] is not instantiable while building [$previous].;// it is a trace } else { $message = target [$concrete] is not instantiable.; } throw new bindingresolutionexception($message);// throw a exception } $this->buildstack[] = $concrete;// add the concrete to the concrete $constructor = $reflector->getconstructor();// get the constructor // if there are no constructors, that means there are no dependencies then // we can just resolve the instances of the objects right away, without // resolving any other types or dependencies out of these containers. if (is_null($constructor)) { array_pop($this->buildstack);// if no has the array_pop delete the concrete return new $concrete;// return new concrete } $dependencies = $constructor->getparameters();//get parameters // once we have all the constructor's parameters we can create each of the // dependency instances and then use the reflection instances to make a // new instance of this class, injecting the created dependencies in. $parameters = $this->keyparametersbyargument( $dependencies, $parameters );// get $instances = $this->getdependencies( $dependencies, $parameters ); array_pop($this->buildstack); return $reflector->newinstanceargs($instances); }// build function is so powerful, can use a instance and a parameters to new a new instance.