php.basic.functions
array_unshift
call_user_func_array闭包 下面是学院的代码
class Container
{
protected $binds; protected $instances; public function bind($abstract, $concrete)
{
if ($concrete instanceof Closure) {
$this->binds[$abstract] = $concrete;
} else {
$this->instances[$abstract] = $concrete;
}
} public function make($abstract, $parameters = [])
{
if (isset($this->instances[$abstract])) {
return $this->instances[$abstract];
} array_unshift($parameters, $this); return call_user_func_array($this->binds[$abstract], $parameters);
}
} // 创建一个容器(后面称作超级工厂)
$container = new Container; // 向该 超级工厂添加超人的生产脚本
$container->bind('superman', function($container, $moduleName) {
return new Superman($container->make($moduleName));
}); // 向该 超级工厂添加超能力模组的生产脚本
$container->bind('xpower', function($container) {
return new XPower;
}); // 同上
$container->bind('ultrabomb', function($container) {
return new UltraBomb;
}); // ****************** 华丽丽的分割线 **********************
// 开始启动生产
$superman_1 = $container->make('superman', 'xpower');
$superman_2 = $container->make('superman', 'ultrabomb');
$superman_3 = $container->make('superman', 'xpower');
// ...随意添加
php.basic.functions的更多相关文章
- Basic Vlan Concepts
1. Vlan Benefit ·To reduce CPU overhead on each device by reducing the number of devices that recei ...
- Basic Vim Configuration
原文: https://computers.tutsplus.com/tutorials/basic-vim-configuration--cms-21498 原来,vim的配置文件,.vimrc也是 ...
- jasmine入门
本文来自http://blog.fens.me/nodejs-jasmine-bdd 粉丝日志 张丹 前言TDD(Test Driven Development)测试驱动开发,是敏捷开发中提出的最 ...
- GO语言的开源库
Indexes and search engines These sites provide indexes and search engines for Go packages: godoc.org ...
- (转载)SQL Reporting Services (Expression Examples)
https://msdn.microsoft.com/en-us/library/ms157328(v=SQL.100).aspx Expressions are used frequently in ...
- XDebug 自动开启PHP Stack Trace, 导致PHP Log 超1G
昨天早上突然发现测试服务器空间满了,用du挨个文件夹查看,发现是php debug log占地极大,有的log直接有1G,打开后发现极其多的php stack trace. 立刻到主服务器查看,主服务 ...
- ebox学习之SD & fat 配置
fatfs可配置项很多,相关的配置均在ffconfig.h文件中 /*----------------------------------------------------------------- ...
- SharePoint Calculated Columns 分类: Sharepoint 2015-07-09 01:49 8人阅读 评论(0) 收藏
SharePoint Calculated Columns are powerful tools when creating out-of-the-box solutions. With these ...
- 现代DOJO(翻译)
http://dojotoolkit.org/documentation/tutorials/1.10/modern_dojo/index.html 你可能已经不用doio一段时间了,或者你一直想保持 ...
随机推荐
- mac下安装并启动RabbitMQ
前言 RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件).RabbitMQ服务器是用Erlang语言编写的,而群集和故障转移是构建在开放电信平台框架上的 ...
- Batch批量替换hosts
hosts文件替换 工作需要,要修改很多计算机的hosts文件,采用bat批量完成 解决的问题: 1.pc工作在非管理员权限,右键管理员权限太麻烦,因此采用执行中申请管理员权限的方式 2.hosts和 ...
- A. Hotelier
A. Hotelier 题意:一家有10间房间的旅馆(10个房间排成一排),在旅馆的左右两端都有一个办理入住的前台,L代表在左端办理入住,R代表在右端办理入住,顾客都会挑选距离最近的空房间入住,数 ...
- android7.0关于TelephonyManager.getDeviceId()返回null的问题
在android7.0的系统下发现TelephonyManager.getDeviceId()在权限允许的情况下取得返回值也为null,解决方法如下: public static String get ...
- 如何在cmd中连接数据库
数据库连接时遇到的问题 : https://www.cnblogs.com/xyzdw/archive/2011/08/11/2135227.htmlping +ip地址: 查看本机ip:ipconf ...
- Jsp有哪些内置对象?作用分别是什么?
Page,pageContext,request,response,session,application,out,config,exception Page指的是JSP被翻译成Servlet的对象的 ...
- Day3-G - Task HDU4864
Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this ...
- FPGA流程设计
做fpga也有四年时间了,该有个总结.刚开始那会,学习东西都是死记硬背,去面试也是直接带着答案去了. 时间久了,才懂得设计一些基本思路. 1. 设计输入: verilog代码和原理图.画原理图都是懒得 ...
- 黑马客户管理系统(SSM)
黑马客户管理系统 1系统概述 1.1系统功能介绍 本系统后台使用SSM框架编写,前台页面使用当前主流的Bootstrap和jQuery框架完成页面信息展示功能(关于Bootstrap的知识,有兴趣的读 ...
- SpringBoo-Thymeleaf
SpringBoo-Thymeleaf SpringBoo-Thymeleaf简介 SpringBoot并不推荐使用JSP,它推荐我们使用模板引擎Thymeleaf,它与Velocity.Free ...