From 6f5d3b3c2ba58707e41cdc2c578610f97d07e74a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 16 Apr 2020 10:50:59 +0300 Subject: [PATCH] Fix formatting, promote static functions --- README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5ad2131..e06d677 100644 --- a/README.md +++ b/README.md @@ -18,20 +18,19 @@ $ 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 @@ -39,8 +38,8 @@ Or with setter 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']); @@ -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 ``` @@ -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 \ No newline at end of file +[license-url]: https://github.com/flotzilla/container/blob/master/LICENCE.md