首页 后端开发 php教程 每天laravel-20160813| Container -16

每天laravel-20160813| Container -16

Jun 23, 2016 pm 01:05 PM

   /**    * 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.
登录后复制


本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

11个最佳PHP URL缩短脚本(免费和高级) 11个最佳PHP URL缩短脚本(免费和高级) Mar 03, 2025 am 10:49 AM

11个最佳PHP URL缩短脚本(免费和高级)

Instagram API简介 Instagram API简介 Mar 02, 2025 am 09:32 AM

Instagram API简介

在Laravel中使用Flash会话数据 在Laravel中使用Flash会话数据 Mar 12, 2025 pm 05:08 PM

在Laravel中使用Flash会话数据

构建具有Laravel后端的React应用程序:第2部分,React 构建具有Laravel后端的React应用程序:第2部分,React Mar 04, 2025 am 09:33 AM

构建具有Laravel后端的React应用程序:第2部分,React

简化的HTTP响应在Laravel测试中模拟了 简化的HTTP响应在Laravel测试中模拟了 Mar 12, 2025 pm 05:09 PM

简化的HTTP响应在Laravel测试中模拟了

php中的卷曲:如何在REST API中使用PHP卷曲扩展 php中的卷曲:如何在REST API中使用PHP卷曲扩展 Mar 14, 2025 am 11:42 AM

php中的卷曲:如何在REST API中使用PHP卷曲扩展

在Codecanyon上的12个最佳PHP聊天脚本 在Codecanyon上的12个最佳PHP聊天脚本 Mar 13, 2025 pm 12:08 PM

在Codecanyon上的12个最佳PHP聊天脚本

宣布 2025 年 PHP 形势调查 宣布 2025 年 PHP 形势调查 Mar 03, 2025 pm 04:20 PM

宣布 2025 年 PHP 形势调查

See all articles