每天laravel-20160817| Container -20

   /**
    * Register a new resolving callback by type of its first argument.
    *
    * @param  \Closure  $callback
    * @return void
    */
// Register a new resolving callback by type of its first argument
   protected function resolvingCallback(Closure $callback)
   {
       $abstract = $this->getFunctionHint($callback);// get the abstract function

       if ($abstract) {// if get the abstract function set in
           $this->resolvingCallbacks[$abstract][] = $callback;// one is abstract function
       } else {
           $this->globalResolvingCallbacks[] = $callback;// other set in the global Resolving Call backs
       }
   }

   /**
    * Register a new after resolving callback by type of its first argument.
    *
    * @param  \Closure  $callback
    * @return void
    */
   protected function afterResolvingCallback(Closure $callback)
   {
       $abstract = $this->getFunctionHint($callback);// get the result

       if ($abstract) {
           $this->afterResolvingCallbacks[$abstract][] = $callback;// one is in the abstract
       } else {
           $this->globalAfterResolvingCallbacks[] = $callback;
       }
   }

   /**
    * Get the type hint for this closure‘s first argument.
    *
    * @param  \Closure  $callback
    * @return mixed
    */
// hint is type  or a way
   protected function getFunctionHint(Closure $callback)
   {
       $function = new ReflectionFunction($callback);// get the new Reflection Function

       if ($function->getNumberOfParameters() == 0) {
           return;
       }// if $function

       $expected = $function->getParameters()[0];

       if (! $expected->getClass()) {// getClass
           return;
       }

       return $expected->getClass()->name;// get the class name.
   }
// sorry ,this too easy
时间: 2024-08-02 00:00:23

每天laravel-20160817| Container -20的相关文章

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实现的几款不错的菜单栏

前言 自从做了智慧城市这个项目之后,我一个做后端的开发者,瞬间转为前端开发,不过我还是很喜欢前端的.前端那些事,其实蛮有意思的,HTML实现的是静态的,使用ajax之后就可以和数据库交互了,加上js和jQuery之后就动起来了,加上CSS之后就更加炫酷了.因为项目中需要,查资料和编写了一些炫酷的二级菜单,分享给大家,好东西就要分享嘛! 一.滑动菜单 1.代码: 1 <!DOCTYPE HTML> 2 <html lang="en-US"> 3 <head&

友情链接的添加保存

linkaddsave.php (保存php页面) 1 <?php 2 include '../inc/db_mysqli.php'; 3 $ty = $_POST['ty']; 4 if($ty=='Y'){ 5 //纯文字友情链接,不用保存图片 6 $stmt = $m->prepare('insert into hnsc_link(ltype,title,url,flag,atime) values(?,?,?,?,?)'); 7 $stmt->bind_param('ssssi'

【单页应用】view与model相关梳理

前情回顾 根据之前的学习,我们形成了一个view与一个messageCenterview这块来说又内建了一套mvc的东西,我们这里来理一下首先View一层由三部分组成:① view② dataAdpter③ viewController view一块两个重要数据是模板以及对应data,一个状态机status这里view只负责根据状态取出对应的模板,而后根据传入的数据返回组装好的html这里一个view多种状态是什么意思呢?比如我有一个组件,但是里面有一圈数据是需要Ajax请求的,所以我的view

BFC详解

BFC(block formating context),翻译过来就是块级格式化上下文.我们可以理解为:BFC就是一个Block-level Box内部的Block-level Box布局的一系列规则.下面我们列出将有哪些布局规则并且举例解释说明. 布局规则: 1. 内部的Box会在垂直方向,从顶部开始一个接一个地放置.(即每个块级元素独占一行) 2. Box垂直方向的距离由margin决定.属于同一个BFC的两个相邻Box的margin会发生叠加.(垂直方向上margin塌陷) 3. 每个元素

Spring框架文档与API(4.3.6版本)

http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/ Table of Contents I. Overview of Spring Framework 1. Getting Started with Spring 2. Introduction to the Spring Framework 2.1. Dependency Injection and Inversion of Contr

检查一个实例的状态变化

使用情景: 一个实例在上次“保存”操作之后又被修改了,需要检查它的状态变化以便有选择的保存此实例. 解决方案: 一个有效的解决方案是创建一个mixin类,这个类可以从多个类继承并能对一个实例的状态进行快照操作,这样就可以用此实例的当前状态和上次的快照做比较了,来判断是否被修改过了. 1 import copy 2 class ChangeCheckerMixin: 3 containerItems = {dict: dict.iteritems, list: enumerate} 4 immut

扩展ToolBarManager、ListView和Grid控件以实现气球式的ToolTip

原文:扩展ToolBarManager.ListView和Grid控件以实现气球式的ToolTip infragistics是全球领先的UI工具和用户体验的专家,Infragistics开发了一系列的炫目的Windows.Web.WPF和Silverlight控件,相信很多人在使用它们.我们现在的项目就在使用Infragistics的Windows Form控件集.虽然这些控件功能强大,也不可能满足你所有的需求,尤其是那些比较苛刻的最终用户的需求.比如,我们最近就接收到这样一个变态的需求:让所以