2017 © Pedro Peláez
 

library di

some di tool library of the php

image

toolkit/di

some di tool library of the php

  • Monday, April 30, 2018
  • by inhere
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Dependency injection container

简单的容器管理实现, (*1)

Install

composer require toolkit/di

注册服务

public function set(string $id, mixed $definition, array $opts = []): Container

参数说明

服务ID名

string $id 服务组件注册id, (*2)

服务定义

mixed(string|array|object|callback) $definition 服务实例对象|服务信息定义, (*3)

  • string:
   $definition = className
  • array:
   $definition = [
      // 1. 仅类名 参数($definition[0])则传入对应构造方法
      'class' => 'className',
      // 2. 类的静态方法,  参数($definition[0])则传入对应方法 className::staticMethod(args...)
      'class' => 'className::staticMethod',
      // 3. 类的动态方法,  参数($definition[0]) 则传入对应方法 (new className)->method(args...)
      'class' => 'className->method',

      // 设置参数方式, 没有key
      [
          arg1,arg2,arg3,...
      ]

      // 设置属性 , // prop1 prop2 prop3 将会被收集 作为属性
      prop1 => value1,
      prop2 => value2,
      ... ...

      // 一些服务设置(别名,是否共享). 将会合并到最后一个参数中
      '_options' => [...] 
   ]
  • object:
   $definition = new xxClass();
  • closure:
   $definition = function($di){ 
        return object;
   };

选项

  • array $opts 选项
  [
   'shared' => (bool), 是否共享,单例
   'locked' => (bool), 是否锁定服务
   'aliases' => (array), 别名
   'init' => (bool), 立即初始化
  ]

License

MIT, (*4)

The Versions

30/04 2018

dev-master

9999999-dev https://github.com/php-toolkit/di

some di tool library of the php

  Sources   Download

MIT

The Requires

 

php library tool

30/04 2018

v1.0.2

1.0.2.0 https://github.com/php-toolkit/di

some di tool library of the php

  Sources   Download

MIT

The Requires

 

php library tool

20/03 2018

v1.0.1

1.0.1.0 https://github.com/php-mylib/di

some di tool library of the php

  Sources   Download

MIT

The Requires

 

php library tool

05/03 2018

v1.0.0

1.0.0.0 https://github.com/php-mylib/di

some di tool library of the php

  Sources   Download

MIT

The Requires

 

php library tool