每天laravel-20160810| Container -13

   /**
    * Call the given Closure / [email protected] and inject its dependencies.
    *
    * @param  callable|string  $callback
    * @param  array  $parameters
    * @param  string|null  $defaultMethod
    * @return mixed
    */
// call the given Closure like class method
// then inject its dependencies.
   public function call($callback, array $parameters = [], $defaultMethod = null)
   {// parameter has callback parameters and defaultMethod
       if ($this->isCallableWithAtSign($callback) || $defaultMethod) {// if it can be call and has the defaultMethod
           return $this->callClass($callback, $parameters, $defaultMethod);// everything has two branch at least
       }

       $dependencies = $this->getMethodDependencies($callback, $parameters);// get the dependencies method by callback and parameter

       return call_user_func_array($callback, $dependencies);// call is a big call method
   }// call the function by callback and parameter and default method

   /**
    * Determine if the given string is in [email protected] syntax.
    *
    * @param  mixed  $callback
    * @return bool
    */
// check the given string is in [email protected] type
// syntax is a normal type
   protected function isCallableWithAtSign($callback)
   {
       if (! is_string($callback)) {
           return false;
       }// must be string

       return strpos($callback, ‘@‘) !== false; // must has @
   }// or return false

   /**
    * Get all dependencies for a given method.
    *
    * @param  callable|string  $callback
    * @param  array  $parameters
    * @return array
    */
// Get all dependencies for a given method.
   protected function getMethodDependencies($callback, array $parameters = [])// callback and parameter
   {
       $dependencies = [];// set array store

       foreach ($this->getCallReflector($callback)->getParameters() as $parameter) {
        // loop the reflector functions as the parameter
           $this->addDependencyForCallParameter($parameter, $parameters, $dependencies);// add the Depend
       }

       return array_merge($dependencies, $parameters);// get the result
   }
时间: 2024-08-28 16:56:12

每天laravel-20160810| Container -13的相关文章

laravel容器container 阅读记录

今天抽时间又仔细看了一下laravel的container,记录一下. 所谓容器,听名字就知道,是一个仓库,装东西用的,所以,container所有的功能,都围绕一个主题:管理装. 类名称:Illuminate\Container\Container 首先,生成一个数组绑定列表,用自定义名称作为主键,然后键值是闭包(输入的可能是闭包或者实体类,但是,在存储的时候,都统一转化成了闭包存储). 其次,根据绑定列表,生成对应的类的实例,供用户使用,调用的时候,发现如果已经生成,不需要重新生成使用,实际

[转载]Laravel Container (容器) 深入理解 (下)

本文大部分翻译自 DAVE JAMES MILLER 的 <Laravel's Dependency Injection Container in Depth> . 上文介绍了 Dependency Injection Containers (容器) 的基本概念,现在接着深入讲解 Laravel 的 Container. Laravel 中实现的 Inversion of Control (IoC) / Dependency Injection (DI) Container 非常强悍,但文档中

css那些事儿2 经典两列布局

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title> 5 <link rel="stylesheet" type="text/css" href="css/main.css"> 6 </head> 7 <body> 8 <div id="header">头部</

手动计算yarn和mapareduce的配置

Hadoop YARN同时支持内存和CPU两种资源的调度,本文介绍如何配置YARN对内存和CPU的使用. YARN作为一个资源调度器,应该考虑到集群里面每一台机子的计算资源,然后根据application申请的资源进行分配Container.Container是YARN里面资源分配的基本单位,具有一定的内存以及CPU资源. 在YARN集群中,平衡内存.CPU.磁盘的资源的很重要的,根据经验,每两个container使用一块磁盘以及一个CPU核的时候可以使集群的资源得到一个比较好的利用. 内存配置

安卓开发_慕课网_Fragment实现Tab(App主界面)

学习内容来自“慕课网” 这里用Fragment来实现APP主界面 思路: 底部横向排列4个LinearLayout,每个LinearLayout包含一个图片按钮和一个文字 1.默认显示第一个功能(微信)的图标为亮,其他三个为暗 2.点击相应的按钮,首先将所有的图标变暗,接着隐藏所有Fragment,再把点击的对应的Fragment显示出来,并把相应的图标显示亮 首先布局文件 activity_main.xml与ViewPager实现Tab的是不一样的 1 <LinearLayout xmlns:

slideDoor

写了一个slideDoor,reset.css就不放上来了,自行添加吧! 1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <meta charset="UTF-8"> 6 <title>slideDoor</title> 7 <link type="text/css" rel="stylesheet" href="../comm

Android高级编程笔记(七)两个Fragment简单跳转示例

在前两篇博文中分别介绍了Fragment得基础和Fragment的生命周期,然而说了这么多Fragment到底怎么用呢以及我们为什么要使用Fragment?本篇博文将主要探讨这两个问题,首先说下在APP中有这好好Activity,跳转起来有那么简单,我们为什么还要使用Fragment呢?这是因为Fragment相对Activity而言更加的轻量级,使用起来也更加灵活,在一个程序的内部界面切换,尽可能的用Fragment代替Activity会让我们的APP运行起来更加的流畅,更加的高效,同时也提高

Android学习笔记之fragment的静态加载和动态加载

1.xml布局文件: main.xml 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="match_parent" 3 android:layout_height="match_parent" > 4 5 <LinearLayout 6 android:id="@+i

From Apprentice To Artisan 翻译 03

The IoC Container 控制反转容器 Basic Binding 基础绑定 Now that we've learned about dependency injection, let's explore inversion of control containers. IoC containers make managing your class dependencies much more convenient, and Laravel ships with a very pow