-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] [Routing] [Config] Recursive directory loading #13246
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
As of now, some Travis tests fail for a reason I can’t identify. The tests run fine on my computer. |
To reproduce on your local computer: |
@nicolas-grekas And do you know what could be causing the issue? AFAIK, the class is in the proper place. Isn’t the autoloader supposed to do its job? |
Oh, nevermind, it is actually pretty simple: it downloads the |
You're right for "high" tests. But merging won't solve "low" tests unless you state that ~2.7 is the minimum allowed version (in components that relies on your newly added class). One or more composer.json need an update |
*/ | ||
public function supports($resource, $type = null) | ||
{ | ||
return 'directory' === $type || (!$type && preg_match('/\/$/', $resource) === 1); // ends with a slash |
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.
I'd prefer to check is_dir instead of is ended with a slash
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.
After extensive testing, I had to remove is_dir
checks in both loaders because ->supports()
is not aware of the current location. Therefore, trailing slash is mandatory. I also updated the tests to reflect this.
👍 |
The errors remaining in Travis are not related to this PR. @nicolas-grekas I added graceful degradation instead of bumping the requirements. See the updated description. @stof If nobody else has issues with this, I believe this is ready now, thanks for your input. |
$loaders[] = new DirectoryLoader($container, $locator); | ||
} | ||
|
||
$resolver = new LoaderResolver($loaders); |
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.
I am wondering why the default set of loaders is written in HttpKernel
, shouldn’t there be something like Symfony\Component\DependencyInjection\Loader\LoaderResolver
that would contain the set of default loaders? This is out of scope of this PR though.
@@ -30,6 +30,12 @@ public function process(ContainerBuilder $container) | |||
|
|||
$definition = $container->getDefinition('routing.resolver'); | |||
|
|||
// routing.loader.directory only appears in Routing 2.7 |
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.
I would rather bump the requirement, so that people using FrameworkBundle 2.7 can be sure about which loaders are supported
Issue #11045 For now, the Routing DirectoryLoader requires the type `directory` to be specified so it does not conflict with `AnnotationDirectoryLoader`. However, this could be refactored.
Errors in Travis not related to my PR. |
Too late for 2.7? Will be a nice addition. |
…ectory loading (lavoiesl, nicolas-grekas) This PR was merged into the 2.8 branch. Discussion ---------- [DependencyInjection] [Routing] [Config] Recursive directory loading | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #13246, #11045, #11059 | License | MIT | Doc PR | - Commits ------- 60b1c5b Added CHANGELOG entries, cleanups 73f0ee2 [DI][Routing] recursive directory loading
As asked by @stof, this PR is a remake of #11059 on the 2.7 branch.
See those about creating a cookbook for better file organization:
Issue: symfony/symfony-docs#3680
PR: symfony/symfony-docs#3885
This PR allows to specify a directory to load and it will recursively load all files from it, using the
LoaderResolver
.Example
It also works for routing configuration:
Advantages
AnnotationDirectoryLoader
, so it does not duplicate the logic.Graceful degradation
InAs asked by @stof, the version requirements are now 2.7 for both.FrameworkBundle
andHttpKernel
, theDirectoryLoader
is only added if available. This means you can haveFrameworkBundle
2.7
withRouting
andDependencyInjection
2.6
and everything will work, except the directory loading.Conflicts
For now, the Routing DirectoryLoader requires the type
directory
to be specified so it does not conflict withAnnotationDirectoryLoader
. However, this could be refactored.The type declaration requires a patch in AsseticBundle for it to be used onReleased in 2.5.0. Changing the main router would be like this:framework.router.resource
. The patch is already merged in master, but not in a release yet.