lapaz / aura-di-ext
Aura.Di Vocabulary Extension
0.2.0
2017-06-08 14:22 UTC
Requires
- php: ^5.6||^7.0
- aura/di: ^3.0
- lapaz/plain-php: ^0.1.0
Requires (Dev)
- phpunit/phpunit: ^6.0||^5.5
This package is auto-updated.
Last update: 2024-12-05 19:45:13 UTC
README
- Optionally
->modifiedBy()
and->modifiedByScript()
enabled after$di->lazyNew()
and$di->newFactory()
. - New method
->newLocator()
to create pure callable object that returns the service. - Optional parameter
$params = []
added to->lazyRequire()
andlazyInclude()
.
(newLocator()
is simply non lazy version of lazyGet()
.)
Unlike ContainerConfig::modify()
, every modification is called on demand at the 1st time of ->get()
.
Before
$di->set('routerContainer', $di->lazy(function () use ($di) { $routerContainer = $di->newInstance(\Aura\Router\RouterContainer::class, [], [ 'setLoggerFactory' => function () use ($di) { return $di->get('logger'); }, // Don't use ->lazyGet() because the returned lazy object would be evaluated before injection. ]); $map = $routerContainer->getMap(); $map->get('index', '/'); // ... return $routerContainer; ));
After
$dix = ContainerExtension::createFrom($di); $di->set('routerContainer', $dix->lazyNew(\Aura\Router\RouterContainer::class, [], [ 'setLoggerFactory' => $dix->newLocator('logger'), ])->modifiedBy(function ($routerContainer) { $map = $routerContainer->getMap(); $map->get('index', '/'); // ... ));
Require/Include
$dix = ContainerExtension::createFrom($di); $di->params[\Aura\Dispatcher\Dispatcher::class]['objects'] = $dix->lazyRequire(__DIR__ . '/objects.php', [ 'di' => $di, // 'anotherConfig' => ... ]);
You can use $di
in objects.php
to return configured lazy instances.