Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

xabbuh
Copy link
Member

@xabbuh 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)) {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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?

@xabbuh xabbuh changed the base branch from 3.4 to 3.3 November 30, 2017 20:29
@xabbuh xabbuh modified the milestones: 3.4, 3.3 Nov 30, 2017
@nicolas-grekas
Copy link
Member

What about changing the priority of the loaders instead?

@xabbuh
Copy link
Member Author

xabbuh commented Nov 30, 2017

@nicolas-grekas I think the root issue is that paths are different when supports() and load() are called. The reason is that the FileLoader resolves paths relative to the current dir after supports() but before load() is called.

@xabbuh
Copy link
Member Author

xabbuh commented Nov 30, 2017

@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 FileLoader if resolving the loader fails. This should ensure that the supports() method receives the same resource as the load() method later.

$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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate?

Copy link
Member Author

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

@nicolas-grekas
Copy link
Member

Red :)

}

if ($type || !is_string($resource)) {
if (!is_string($resource)) {
Copy link
Contributor

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?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Dec 1, 2017

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.
I would revert to the first version of the patch, which excluded FQCN.
to make it a bit more strict and less likely to break, I would also suggest to exclude only if the resource contains a \ and to add a class_exists check in AnnotationClassLoader::supports.

}

// classes are handled by the AnnotationClassLoader
if (strpos($resource, '\\') || class_exists($resource)) {
Copy link
Member

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?

Copy link
Member Author

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)) {
Copy link
Member

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.

Copy link
Member

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) {
Copy link
Member

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

@nicolas-grekas
Copy link
Member

there is something strange:
in FrameworkExtension

  • AnnotatedRouteControllerLoader
  • AnnotationDirectoryLoader
  • AnnotationFileLoader

they're registered with priority -10, in this order
I'd expect the issue to not exist
because AnnotatedRouteControllerLoader (=AnnotationClasLoader) is first

related to "sort" which is not "stable" anymore since 7.0? maybe that's a better place for a fix, making this sorting stable?

@stof
Copy link
Member

stof commented Dec 4, 2017

@nicolas-grekas could it be related to SensioFrameworkExtraBundle loaders having a different priority ?

@xabbuh
Copy link
Member Author

xabbuh commented Dec 4, 2017

The order in FrameworkExtraBundle is different:

  • AnnotationDirectoryLoader
  • AnnotationFileLoader
  • AnnotatedRouteControllerLoader

@xabbuh
Copy link
Member Author

xabbuh commented Dec 4, 2017

So, should we maybe just change the order of the services in SensioFrameworkExtraBundle instead?

@nicolas-grekas
Copy link
Member

we should for sure, for consistency at least!

@xabbuh
Copy link
Member Author

xabbuh commented Dec 4, 2017

@xabbuh xabbuh closed this Dec 4, 2017
@xabbuh xabbuh deleted the issue-25225 branch December 4, 2017 14:14
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.

5 participants