每天laravel-20160815| Container -18

    /**
     * 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
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值