Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,28 @@ $ composer require flotzilla/container

Init service container with constructor parameters
```php
$container = new \flotzilla\Container\Container(
$container = new \flotzilla\Container\Container(
[
'EmptyTestClassDI' => EmptyTestClass::class, // class without dependencies, init by classname
'TestClassDI' => [TestClass::class, 'message'], // class with constructor string parameter
'TestClassDI2' => function () { // closure, that returns new class instance
'TestClassDI2' => static function () { // closure, that returns new class instance
return new TestClass('test');
},
'ClosureDI' => function ($x, $y) { // closure, that returns sum result
'ClosureDI' => static function ($x, $y) { // closure, that returns sum result
return $x + $y;
},

'TestClassWithDependecyDI' => [TestClassWithDependecy::class, 'TestClassDI'] // class with dependency of another service
]
);
],
);
```

Or with setter
```php
use \flotzilla\Container\Container;
$container = new Container();

$container->set('LoggerDI', function () { return new Logger();});
$container->set('ClosureDI', function ($x, $y) { return $x + $y;});
$container->set('LoggerDI', static function () { return new Logger();});
$container->set('ClosureDI', static function ($x, $y) { return $x + $y;});
$container->set('EmptyTestClassDI', ClassWithoutConstructor::class);
$container->set('ClassDIWithDependency', [SomeClass::class, 'message']);
$container->set('AnotherClassWithDIDependency', [TestClass::class, 'LoggerDI']);
Expand All @@ -53,7 +52,7 @@ $logger = $container->get('LoggerDI');

Get your closure with arguments
```php
$container->set('ClosureDI', function ($x, $y) { return $x + $y;});
$container->set('ClosureDI', static function ($x, $y) { return $x + $y;});
$logger = $container->getWithParameters('ClosureDI', [1, 2]); // will return 3
```

Expand All @@ -68,4 +67,4 @@ $ composer test
The MIT License (MIT). Please see [License File](https://github.com/flotzilla/container/blob/master/LICENCE.md) for more information.

[license-shield]: https://img.shields.io/github/license/othneildrew/Best-README-Template.svg?style=flat-square
[license-url]: https://github.com/flotzilla/container/blob/master/LICENCE.md
[license-url]: https://github.com/flotzilla/container/blob/master/LICENCE.md