每天laravel-20160812| Container -15

php中文网
发布: 2016-06-20 12:28:06
原创
1271人浏览过

/** * resolve the given type from the container. * * @param  string  $abstract * @param  array   $parameters * @return mixed */ // get the given type from the containerpublic function make($abstract, array $parameters = []){// this function name "make" like compile c file to binary file in the linux    $abstract = $this->getalias($this->normalize($abstract));    // first get the alias as the new name    // if an instance of the type is currently being managed as a singleton we'll    // just return an existing instance instead of instantiating new instances    // so the developer can keep using the same objects instance every time.    if (isset($this->instances[$abstract])) {        return $this->instances[$abstract];    }// like normal method // if it is exist ,we will return it, that ok;    $concrete = $this->getconcrete($abstract);// concrete like create it done    // we're ready to instantiate an instance of the concrete type registered for    // the binding. this will instantiate the types, as well as resolve any of    // its "nested" dependencies recursively until all have gotten resolved.    if ($this->isbuildable($concrete, $abstract)) {// isbuildable        $object = $this->build($concrete, $parameters);// check it is can be builda    } else {        $object = $this->make($concrete, $parameters);    }    // if we defined any extenders for this type, we'll need to spin through them    // and apply them to the object being built. this allows for the extension    // of services, such as changing configuration or decorating the object.    foreach ($this->getextenders($abstract) as $extender) {        $object = $extender($object, $this);    }// to though , a extender done is too trouble    // if the requested type is registered as a singleton we'll want to cache off    // the instances in "memory" so we can return it later without creating an    // entirely new instance of an object on each subsequent request for it.    if ($this->isshared($abstract)) {        $this->instances[$abstract] = $object;    }// get the instance from the "memory"    $this->fireresolvingcallbacks($abstract, $object);    $this->resolved[$abstract] = true;    return $object;}// in the last we will found it is a compatible way to get you want object./** * get the concrete type for a given abstract. * * @param  string  $abstract * @return mixed   $concrete */protected function getconcrete($abstract){// get a concrete type for a abstract    if (! is_null($concrete = $this->getcontextualconcrete($abstract))) {        return $concrete;    }// if you can get it ,then return it // otherwise see next    // if we don't have a registered resolver or concrete for the type, we'll just    // assume each type is a concrete name and will attempt to resolve it as is    // since the container should be able to resolve concretes automatically.    if (! isset($this->bindings[$abstract])) {        return $abstract;    }// return it back    return $this->bindings[$abstract]['concrete'];}//last we will binding it
登录后复制


天工
天工

昆仑万维推出的通用AI智能体平台,原天工AI

天工 212
查看详情 天工
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号