/**
     * Resolve a non-class hinted dependency.
     *
     * @param  \ReflectionParameter  $parameter
     * @return mixed
     *
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    protected function resolveNonClass(ReflectionParameter $parameter)
    {// the parameter is a RefectionParameter $parameter
        if (! is_null($concrete = $this->getContextualConcrete(‘$‘.$parameter->name))) {
           // if can get the concrete
            if ($concrete instanceof Closure) {// if the concrete is a instance of Closure
                return call_user_func($concrete, $this);// return the call_user_func
            } else {
                return $concrete;// return concrete
            }
        }
        if ($parameter->isDefaultValueAvailable()) {// if has
            return $parameter->getDefaultValue();// return it
        }
// other ,set the bad message and return it
       // some time the message is very good use double " ,yeah
        $message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}";
        throw new BindingResolutionException($message);// throw bad message
    }
    /**
     * Resolve a class based dependency from the container.
     *
     * @param  \ReflectionParameter  $parameter
     * @return mixed
     *
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    protected function resolveClass(ReflectionParameter $parameter)
    {// the class is based dependency from the container.
        try {
            return $this->make($parameter->getClass()->name);
        }// try check this class name whether can be make
        // If we can not resolve the class instance, we will check to see if the value
        // is optional, and if it is we will return the optional parameter value as
        // the value of the dependency, similarly to how we do this with scalars.
        catch (BindingResolutionException $e) {// catch the exception
            if ($parameter->isOptional()) {// if we has the Optional
                return $parameter->getDefaultValue();
            }
            throw $e;// throw $e
        }
    }本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1783327
每天laravel-20160815| Container -18
原文地址:http://jingshanls.blog.51cto.com/3357095/1783327