Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ApplicationConfigInjectionDelegator more than once (in multiple modules simultaneously) results results in a DuplicateRouteException. #93

Open
settermjd opened this issue Sep 29, 2021 · 1 comment
Labels
Bug Something isn't working

Comments

@settermjd
Copy link
Contributor

Bug Report

Q A
Version(s) 3.6.0 (likely earlier as well)

Summary

Using ApplicationConfigInjectionDelegator more than once (in multiple modules simultaneously) results results in a DuplicateRouteException. I found out about this after being contacted by a reader of Mezzio Essentials.

Current behavior

If you load the ApplicationConfigInjectionDelegator in more than one module in a Mezzio project, such as in the example below, in the module's ConfigProvider, then a DuplicateRouteException is thrown.

    public function getDependencies() : array
    {
        return [
            // ... existing configuration
            'delegators' => [
                Application::class => [
                    ApplicationConfigInjectionDelegator::class,
                ],
            ],
        ];
    }

This happens because ApplicationConfigInjectionDelegator::injectRoutesFromConfig calls Mezzio\Application::route, which ultimately throws a DuplicateRouteException because it injectRoutesFromConfig doesn't check if a route is in the routing table before attempting to add the existing routing table to the routing table. I don't know if this is the intended functionality, but thought that if a route was added, that it would overwrite an existing one.

How to reproduce

Add the above code snippet in more than one module. You don't need to add any further configuration.

Expected behavior

That if there are no, actual, duplicate routes, that no DuplicateRouteException would be thrown.

@settermjd settermjd added the Bug Something isn't working label Sep 29, 2021
@boesing
Copy link
Member

boesing commented Jan 31, 2022

This is a tough one. Delegators are not meant to be used more than once.
What is the use-case of providing that delegator more than once?


The only thing to avoid this is to do some kind of de-duplication in laminas-servicemanager but I am unsure what kind of implications this might have in projects which do actually rely on this.
I, personally, can not imagine a use-case where delegators should be applied more than once to the same service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants