自己写的一个简单的容器按需加载例子
2018-01-04 10:23
363 查看
<?php class Di { protected $providers = []; //注册服务 public function register($id,$val) { $this->providers[$id] = function () use ($val){ return new $val(); }; } //get方法 public function __get($id) { return $this->providers[$id](); } } class User{ public function test() { echo 'user:test'; } } class Student{ public function test() { echo 'student:test'; } } $di = new Di(); $di->register('user',User::class); $di->register('student',Student::class); $di->user->test()."/r/n"; $di->student->test();
相关文章推荐
- 写一个自己的Spring框架——简单实现IoC容器功能
- 一个简单的例子演示:模仿微博里面的通过浏览器的滚动条来动态加载数据
- 自己写一个简单的Spring IOC容器
- 通过一个简单的例子,说明class文件在运行过程中,import中class怎么被加载并执行的
- 将十进制整形数转换成二进制,然后通过字符型输出 自己实现的一个简单的例子
- CFX WebService做的一个简单的HelloWorld例子 也可与spring 整合 发布在容器里面
- 一个简单的js合并列的例子,大家可以自己改进哦!
- (2)自己写一个简单的servle容器
- 自己写的一个简单的IOC容器
- auto_ptr的一个简单例子
- 自己动手写一个简单正则表达式解析器(待续,未完成)
- 仿写自己的一个加载语言包的L函数
- 自己写一个简单的cordova插件
- Kotlin开发android:一个简单的登陆例子
- heritrix的一个简单例子
- IoC容器Autofac(2) - 一个简单示例(附demo源码)
- 一个简单的sql的游标处理结果集的例子
- ThinkPHP 学习(2)---一个简单的起步的例子
- 简单完整的代码,通过这个代码你将对RSA加密算法在Java中的实现方法有一个初步的了解,这个类,你可以直接使用,水平高的,就自己修改完善下代码。
- 写的委托的一个简单例子