laminas / laminas-pimple-config

PSR-11 Pimple container configurator for Laminas and Mezzio applications
BSD 3-Clause "New" or "Revised" License
10 stars 7 forks source link

Delegator not looking for aliases #1

Closed weierophinney closed 7 months ago

weierophinney commented 4 years ago

Good morning,

I've the following configuration:

    // Container configuration
    'dependencies'      => [
        'invokables' => [
            CommandBus::class => SimpleCommandBus::class,
        ],
        'factories'  => [
            EventBus::class                  => EventBusFactory::class,
            EventStore::class                => EventStoreFactory::class,
            PhpVersionRepository::class      => PhpVersionEventStoreRepositoryFactory::class,
            PhpVersionCommandHandlers::class => PhpVersionCommandHandlersFactory::class,
        ],
        'delegators' => [
            CommandBus::class => [
                PhpVersionCommandBusDelegatorFactory::class
            ]
        ]
    ]

Problem is that when I get the Command::Bus service, the PhpVersionCommandBusDelegatorFactory isn't invoked.

However, the following works:

    // Container configuration
    'dependencies'      => [
        'invokables' => [
            CommandBus::class => SimpleCommandBus::class
        ],
        'factories'  => [
            EventBus::class                  => EventBusFactory::class,
            EventStore::class                => EventStoreFactory::class,
            PhpVersionRepository::class      => PhpVersionEventStoreRepositoryFactory::class,
            PhpVersionCommandHandlers::class => PhpVersionCommandHandlersFactory::class,
        ],
        'delegators' => [
            SimpleCommandBus::class => [
                PhpVersionCommandBusDelegatorFactory::class
            ]
        ]
    ]

Why there is no alias matching there?


Originally posted by @nuxwin at https://github.com/zendframework/zend-pimple-config/issues/12

pine3ree commented 4 years ago

Hello @nuxwin,

I believe the answer is in the following lines:

https://github.com/laminas/laminas-pimple-config/blob/master/src/Config.php#L112 https://github.com/laminas/laminas-pimple-config/blob/master/src/Config.php#L135

In the invokables config array if the key does not match the invokable FQCN the key is used as an alias, so in your first example the delegator factories are not called as their key does not match the actual service id (FQCN: SimpleCommandBus::class), bit its alias CommandBus::class

kind regards