symfony: [Routing] "exclude" option ignored when "resource" doesn't end with "*?{["

Symfony version(s) affected: 4.4.*

Description

As described in Routing docs (v4.4), adding the exclude option should be possible when defining routes as annotations. But, looking at https://github.com/symfony/config/blob/4.4/Loader/FileLoader.php#L81, it seems that exclude option is handled only when resource options ends with *?{[

To note:

  • I encountered this (to be confirmed) bug during development, I didn’t run many tests
  • code in branch FileLoader.php v5.* has changed, so I don’t know if the bug still exists in 5.*

How to reproduce
Very simple routes configuration:

# config/routes/annotations.yaml
app:
    resource: '../../src/Controller/'
    type: annotation
    exclude: '../../src/Controller/ExcludedController.php'

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 22 (13 by maintainers)

Commits related to this issue

Most upvoted comments

for my case it worked to go with this glob:

controllers:
    resource: ../../src/Controller/**/*
    exclude: ../../src/Controller/Blog
    type: annotation

blog:
    resource: ../../src/Controller/Blog
    type: annotation
    name_prefix: blog_
    prefix: /blog/

Since version 6.2 there is a new default routes.yaml. For exclusions to work, the following change was necessary for me:

controllers:
+    resource: ../src/Controller/**/*
-    resource:
-        path: ../src/Controller/
-        namespace: App\Controller
    exclude: ../src/Controller/Blog
    type: attribute

blog:
    resource: ../src/Controller/Blog
    type: annotation
    name_prefix: blog_
    prefix: /blog/

Just adding the glob pattern to resource.path did not work for me, it produces the error “The file “…/src/Controller/**/*” does not exist”.

Issue still persists in 7.0 and is quite confusing. Why is the /src/Controller/**/* not the default?

Hello? This issue is about to be closed if nobody replies.

I also just suffered from time lost to trying to work this by following the documentation for v7.1.

Could we at least update the docs to advise on this behaviour until we come up with a proper solution for this? I’ve raised https://github.com/symfony/symfony-docs/pull/20241 to address this.