每天laravel-20160808| Container -11

/**
    * Bind a new callback to an abstract‘s rebind event.
    *
    * @param  string    $abstract
    * @param  \Closure  $callback
    * @return mixed
    */
   public function rebinding($abstract, Closure $callback)// means binding again
   {
       $this->reboundCallbacks[$this->normalize($abstract)][] = $callback;// set the callback function insert into the array store

       if ($this->bound($abstract)) {// if has bound function set
           return $this->make($abstract);// return the make result to what you want
       }
   }

   /**
    * Refresh an instance on the given target and method.
    *
    * @param  string  $abstract
    * @param  mixed   $target
    * @param  string  $method
    * @return mixed
    */
   public function refresh($abstract, $target, $method)// refresh means to make or fire it again
   {// use the set target and method
       return $this->rebinding($this->normalize($abstract), function ($app, $instance) use ($target, $method) {
           $target->{$method}($instance);
       });// return the rebinding
   }//"function use" type way to import  a closure function.
// that will use a variable out the function,
// the first good place i can see is reduce the parameters

   /**
    * Fire the "rebound" callbacks for the given abstract type.
    *
    * @param  string  $abstract
    * @return void
    */
   protected function rebound($abstract)// start to run the rebound callbacks for the given abstract type
   {
       $instance = $this->make($abstract);// the make function is the get the instance of the ab

       foreach ($this->getReboundCallbacks($abstract) as $callback) {//loop the abstract to call it
           call_user_func($callback, $this, $instance);// call user function
       }
   }
时间: 2024-08-28 02:29:14

每天laravel-20160808| Container -11的相关文章

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 非常强悍,但文档中

Laravel(5)你的第一个应用4

创建你的视图app/views/master.blade.php 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Cats DB</title> 6 <link rel="stylesheet" href="{{asset('bootstrap-3.

laravel 入门

Laravel5.0学习--01 入门 本文以laravel5.0.22为例. 生产环境建议使用laravel5.1版本,因为该版本是长期支持版本.5.1文档更详细:http://laravel-china.org/docs/5.1. 环境需求 Laravel5.0 框架有一些系统上的需求: PHP 版本 >= 5.4 Mcrypt PHP 扩展 OpenSSL PHP 扩展 Mbstring PHP 扩展 Tokenizer PHP 扩展 在 PHP 5.5 之后, 有些操作系统需要手动安装

laravel-- 在laravel操作redis数据库的数据类型(string、哈希、无序集合、list链表、有序集合)

安装redis和连接redis数据库 在controller头部引入 一.基本使用 1 public function RedisdDbOne() { 2 // 清空Redis数据库 3 Redis::flushall(); 4 5 6 // redis的string类型 7 Redis::set("laravel","Hello woshi laravel"); 8 dump(Redis::get("laravel")) ; 9 10 11 /

Laravel 开发 API

1. 起因 随着前后端完全分离,PHP 也基本告别了 view 模板嵌套开发,转而专门写资源接口.Laravel 是 PHP 框架中最优雅的框架,国内也越来越多人告别 ThinkPHP 选择了 Laravel.Laravel 框架本身对 API 有支持,但是感觉再工作中还是需要再做一些处理.Lumen 用起来不顺手,有些包不能很好地支持.所以,将 Laravel 框架进行一些配置处理,让其在开发 API 时更得心应手. 当然,你也可以点击这里 , 直接跳到成果- 2. 准备工作 2.1. 环境

手摸手教你让Laravel开发Api更得心应手

https://www.guaosi.com/2019/02/26/laravel-api-initialization-preparation/ 1. 起因 随着前后端完全分离,PHP也基本告别了view模板嵌套开发,转而专门写资源接口.Laravel是PHP框架中最优雅的框架,国内也越来越多人告别ThinkPHP选择了Laravel.Laravel框架本身对API有支持,但是感觉再工作中还是需要再做一些处理.Lumen用起来不顺手,有些包不能很好地支持.所以,将Laravel框架进行一些配置

ASP.NET MVC下的四种验证编程方式[续篇]

在<ASP.NET MVC下的四种验证编程方式>一文中我们介绍了ASP.NET MVC支持的四种服务端验证的编程方式("手工验证"."标注ValidationAttribute特性"."让数据类型实现IValidatableObject或者IDataErrorInfo"),那么在ASP.NET MVC框架内部是如何提供针对这四种不同编程方式的支持的呢?接下来我们就来聊聊这背后的故事. 一.ModelValidator与ModelVal

CSS position:absolute浅析

一.绝对定位的特征 绝对定位有着与浮动一样的特性,即包裹性和破坏性. 就破坏性而言,浮动仅仅破坏了元素的高度,保留了元素的宽度:而绝对定位的元素高度和宽度都没有了. 请看下面代码: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>绝对定位的特征</title> 6 <style> 7 .box1,.box2,.b