-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Use glob pattern to include routing annotations #25633
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
Conversation
``FileLoader::import`` method can return an array, this PR fix the error "Call to a member function addPrefix() on array". Use case "I want to import routes from controllers in different directories"; given a ``route/annotation.yaml`` like this: ``` controllers: resource: ../../src/*/Controller/*Controller.php type: annotation ``` (``/*Controller.php`` is required to make the glob return something). I dont know how to code this properly, that why I just copied/paste the code like this, but the idea is here.
|
||
if (is_array($subCollection)) { | ||
/* @var $value RouteCollection */ | ||
foreach($subCollection as $value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a lot of duplicate code. What if you simply ensure it's always an array?
if (!is_array($subCollection)) {
$subCollection = array($subCollection);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely, I didnt know the best way to deal with, thanks you.
Could you add a test case please? If this is a bug fix, it should target the lowest maintained branch where the bug exists (either 2.7, 2.8, 3.3 or 3.4). Any hint in that aspect? |
Sure, I have taken a look on
|
so, this is a bug fix, isn't it?
please push a test case that you'd like to make work and we will be able to help I guess |
Oh, please also ensure that other loaders don't have the same issue. |
Closing in favor of #26600, thank you for working on this anyway! |
… that match multiple resources (skalpa) This PR was squashed before being merged into the 3.4 branch (closes #26600). Discussion ---------- [Routing] Fixed the importing of files using glob patterns that match multiple resources | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22160 | License | MIT | Doc PR | n/a This fixes the import of resources specified using glob patterns in `XmlFileLoader` and `YamlFileLoader`. @nicolas-grekas This supersedes #25633 that's been in limbo since December despite your comments, so I decided to take care of it as I need this to work. I took care of the two loaders that are affected, and added tests. Commits ------- 948b4cf [Routing] Fixed the importing of files using glob patterns that match multiple resources
FileLoader::import
method can return an array, this PR fix the error "Call to a member function addPrefix() on array".Use case "I want to import routes from controllers in different directories"; given a
route/annotation.yaml
like this:(
/*Controller.php
is required to make the glob return something).I dont know how to code this properly, that why I just copied/paste the code like this, but the idea is here.