Skip to content

LapazPhp/Aura.Di-ext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aura.Di Vocabulary Extension

Build Status

  • 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() and lazyInclude().

(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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages