Skip to content

[Config] Fix exclude path configuration #54236

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

Open
wants to merge 1 commit into
base: 5.4
Choose a base branch
from

Conversation

NeilPeyssard
Copy link
Contributor

@NeilPeyssard NeilPeyssard commented Mar 11, 2024

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? no
Issues Fix #54212, fix #39588
License MIT

Hello,

In the routing configuration, the exclude parameter is ignored if the the resource is not a path which can be used by the glob function. This PR is a starting point to work on this issue.

For example, if I have these controllers:

  • src/Controller/DebugController
  • src/Controller/DebugFooController
  • src/Controller/HelloController

And the following route configuration:

# config/routes/annotations.yaml
controllers:
    resource: '../../src/Controller/'
    type: annotation
    exclude: '../../src/Controller/{Debug*Controller.php}'

I expect to only see routes in HelloController active, but actually routes in DebugController and DebugFooController are also imported.

In this PR, I decided to transform all resource paths to a path which can be used by the glob function, only if there is an exclude parameter in the configuration. Not really sure if it's the good way to approach it, so do not hesitate to challenge it.

@xabbuh
Copy link
Member

xabbuh commented Mar 11, 2024

Will this also fix #39588?

@NeilPeyssard
Copy link
Contributor Author

Will this also fix #39588?

Yes it will !

To describe more in depth the behavior of this PR, let's take these controllers

  • src/Controller/Foo/BarController
  • src/Controller/DebugController
  • src/Controller/DebugFooController
  • src/Controller/HelloController

The following configurations will exclude DebugController and DebugFooController

# config/routes/annotations.yaml

controllers:
    resource: '../../src/Controller/'
    type: annotation
    exclude: '../../src/Controller/{Debug*Controller.php}'

# or

controllers:
    resource: '../../src/Controller/**/*'
    type: annotation
    exclude: '../../src/Controller/{Debug*Controller.php}'

And the following configuration will exclude DebugController, DebugFooController and Foo\BarController:

# config/routes/annotations.yaml
controllers:
    resource: '../../src/Controller/*'
    type: annotation
    exclude: '../../src/Controller/{Debug*Controller.php}'

@NeilPeyssard NeilPeyssard force-pushed the fix/54212-exclude-config branch from 3fcade1 to 1c2d559 Compare March 13, 2024 10:29
@NeilPeyssard
Copy link
Contributor Author

Hello,

Unfortunately, I realized the following exclude condition will not work in version 6.4:

controllers:
    resource:
        path: ../src/Controller/
        namespace: App\Controller
    exclude: '../src/Controller/{Debug*Controller.php}'
    type: attribute

This declaration will be handled by the Symfony\Component\Routing\Loader\Psr4DirectoryLoader, which hasn't access to the exclude parameter.

After digging a little deeper, I have the feeling there is a bad design here. In an ideal world each loader will have access to this exclude parameter, and deal with it to load or not their routes. But adding such a big change will involve some BC break...

What do you think guys ?

@GromNaN GromNaN added the Bug label Mar 15, 2024
@fabpot fabpot modified the milestones: 5.4, 6.4 Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants