-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] don't process classes with the directory loader #25231
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
xabbuh
commented
Nov 30, 2017
Q | A |
---|---|
Branch? | 3.4 |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #25225 |
License | MIT |
Doc PR |
} | ||
|
||
// classes are handled by the AnnotationClassLoader | ||
if (preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource)) { |
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.
wondering why it worked on 3.3 without this? Was the order of the loaders different?
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.
Actually, I think we really need to make the change in 3.3. The observed behaviour seems to be caused by #25113 which just was not part of a patch release of 3.3 yet.
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.
Ah ok I see 😉
Can't we do a class_exists
call to see if $resource
is a class instead?
What about changing the priority of the loaders instead? |
@nicolas-grekas I think the root issue is that paths are different when |
@nicolas-grekas I have pushed a second commit which could be the solution. Basically, it reverts the changes done in #25113 and does the resource resolving inside the |
$resource = $this->getLocator()->locate($resource, $this->currentDir, false); | ||
$resource = is_array($resource) ? $resource[0] : $resource; | ||
$loader = $this->resolve($resource, $type); | ||
} | ||
|
||
if ($loader instanceof self && null !== $this->currentDir) { |
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.
Duplicate?
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.
removed from the try
block
Red :) |
} | ||
|
||
if ($type || !is_string($resource)) { | ||
if (!is_string($resource)) { |
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.
can be
if (!is_string($resource) || $type && 'annotation' !== $type) {
and then no need to change the try block below?
I think we shouldn't go down this road: this changes the locator to be fetched from "$loader" vs "$this" in some cases, and this is too risky for the base FileLoader IMHO. |
} | ||
|
||
// classes are handled by the AnnotationClassLoader | ||
if (strpos($resource, '\\') || class_exists($resource)) { |
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.
false !== strpos
to accurately mirror what's done in AnnotationClassLoader?
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.
of course
} | ||
|
||
// classes are handled by the AnnotationClassLoader | ||
if (false !== strpos($resource, '\\') || class_exists($resource)) { |
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.
that's not good. Importing %kernel.project_dir%/src/Controller
will have backslashes in it on Windows AFAICT.
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.
so we should add the regexp check also
@@ -76,6 +76,15 @@ function (\SplFileInfo $current) { | |||
*/ | |||
public function supports($resource, $type = null) | |||
{ | |||
if ($type && 'annotation' !== $type) { |
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.
replaces the checks below, so they could be removed, but misses the is_string($resource)
one
there is something strange:
they're registered with priority -10, in this order related to "sort" which is not "stable" anymore since 7.0? maybe that's a better place for a fix, making this sorting stable? |
@nicolas-grekas could it be related to SensioFrameworkExtraBundle loaders having a different priority ? |
The order in FrameworkExtraBundle is different:
|
So, should we maybe just change the order of the services in SensioFrameworkExtraBundle instead? |
we should for sure, for consistency at least! |