2017 © Pedro Peláez
 

library di

PHP DI

image

vakata/di

PHP DI

  • Friday, October 28, 2016
  • by vakata
  • Repository
  • 1 Watchers
  • 0 Stars
  • 580 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 14 % Grown

The README.md

DI

Latest Version on Packagist ![Software License][ico-license], (*1)

PHP dependency injection / factory., (*2)

Install

Via Composer, (*3)

``` bash $ composer require vakata/di, (*4)


## Usage ``` php namespace test; $di = new \vakata\di\Container(); interface I { } class A implements I {} class B { public function __construct(I $instance) { } } class C { public function __construct($firstParam, $secondParam) { } public function test($arg = 1) { return 1; } } // this will register class A, and an alias I for class A as the class implements that interface $di->register('\test\A'); $di->instance('\test\B'); // a B instance is created // when registering you can prevent interfaces being added as aliases as adding the aliases manually $di->register('\test\B', ['aliasedB']); // you can also pass default constructor params, which can be named $di->register('\test\C', null, ['secondParam' => 1, 2]); $di->instance('\test\C'); // this will invoke \test\C::__construct(2,1); $di->instance('\test\C', [2,4]); // this will invoke \test\C::__construct(2,4); // you can also register instances: $d = new D(); $di->register($d); // this is the same as \test\D // you can also make sure that there is only one instance of a given class $di->register('\some\class', ['aliases'], [/* default params */], true); // aside from register and instance there is an invoke method $di->invoke('\test\C', 'sum'); // returns 1 // you can also pass in arguments $di->invoke('\test\C', 'sum', [2]); // returns 2 // and even constructor parameters $di->invoke('\test\C', 'sum', [2], [5,6]); // invoke works with instances too $c1 = new C(); $di->invoke($c1, 'sum'); // returns 1

Testing

bash $ composer test, (*5)

Contributing

Please see CONTRIBUTING for details., (*6)

Security

If you discover any security related issues, please email github@vakata.com instead of using the issue tracker., (*7)

Credits

License

The MIT License (MIT). Please see License File for more information., (*8)

The Versions

28/10 2016

dev-master

9999999-dev https://github.com/vakata/di

PHP DI

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

vakata kvstore

28/10 2016

1.0.5

1.0.5.0 https://github.com/vakata/di

PHP DI

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

vakata kvstore

27/10 2016

1.0.4

1.0.4.0 https://github.com/vakata/di

PHP DI

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

vakata kvstore

15/08 2016

1.0.3

1.0.3.0 https://github.com/vakata/di

PHP DI

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

vakata kvstore

09/04 2016

1.0.2

1.0.2.0 https://github.com/vakata/di

PHP DI

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

vakata kvstore

08/04 2016

1.0.1

1.0.1.0 https://github.com/vakata/di

PHP DI

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

vakata kvstore

11/01 2016

1.0.0

1.0.0.0 https://github.com/vakata/di

PHP DI

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

vakata kvstore