2017 © Pedro Peláez
 

library di

Simple PHP DI class

image

hongjh/di

Simple PHP DI class

  • Thursday, May 26, 2016
  • by hongjh
  • Repository
  • 0 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Di

Di is a simple, open source PHP DI class., (*1)

Install

If you have Composer, just include Router as a project dependency in your composer.json. If you don't just install it by downloading the .ZIP file and extracting it to your project directory., (*2)

require: {
    "hongjh/di": "dev-master"
}

example

$di = new Di();
//匿名函数方式注册一个名为a1的服务
$di->setShared('a1', function($name = "") {
    return new A($name);
});
//直接以类名方式注册
$di->set('a2', 'A');
//直接传入实例化的对象
$di->set('a3', new A("小唐"));

$di->setShared('a4', 'A');

$a1 = $di->get('a1', array("小李"));
echo $a1->name . "<br/>"; //小李
$a1_1 = $di->get('a1', array("小王"));
echo $a1->name . "<br/>"; //小李
echo $a1_1->name . "<br/>"; //小李

$a2 = $di->get('a2', array("小张"));
echo $a2->name . "<br/>"; //小张
$a2_1 = $di->get('a2', array("小徐"));
echo $a2->name . "<br/>"; //小张
echo $a2_1->name . "<br/>"; //小徐

$a3 = $di['a3']; //可以直接通过数组方式获取服务对象
echo $a3->name . "<br/>"; //小唐

The Versions

26/05 2016

dev-master

9999999-dev

Simple PHP DI class

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

by Avatar hongjh