interface First { public function first(); } interface Second { public function second(); } interface Third { public function third(); } class Foo implements First { public function first() { /* ... */ } } class Boo implements Second { public function __construct(First $first) { /* ... */ } public function second() { /* ... */ } } class Woo implements Third { public function __construct(First $first, Second $first) { /* ... */ } public function third() { /* ... */ } } $ioc = IoC\Container::getInstance(); $ioc->register('Foo'); $ioc->register('Boo'); $ioc->register('Woo'); class Manager { use IoC\Creatable; public function __construct(First $first, Second $second, Third $third) { /* ... */ } } $manager = Manager::create(); class Manager { public static function create() { return \IoC\Factory::create(get_called_class(), func_get_args()); } /* ... */ } class Manager { use IoC\Creatable; public function __construct(First $first, Second $second, Third $third, $value, $anotherValue = 'default') { /* ... */ } } $manager = Manager::create('value', 'another value'); $managerWithDefault = Manager::create('value'); $ioc->register('Foo'); $ioc->register(new Foo()); $ioc->prototype(new Foo()); $ioc->assoc(new MyAssoc('Foo')); $ioc->register('Foo', 'First'); $ioc->register(new Foo(), 'Second'); $ioc->prototype('Foo', 'First'); $ioc->register('FooBoo', array('First', 'Second')); // Boo extends Foo $ioc->register('Boo', 'Foo'); Source: https://habr.com/ru/post/132084/
All Articles