From fe8620f91d95f338e05dc799aca4b229dd440bb5 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 30 Nov 2017 21:19:38 +0100 Subject: [PATCH] don't process classes with the directory loader --- .../Routing/Loader/AnnotationClassLoader.php | 2 +- .../Routing/Loader/AnnotationDirectoryLoader.php | 11 ++++++++--- .../Tests/Loader/AnnotationDirectoryLoaderTest.php | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index 5ca3a2b73cb42..2408394fc092e 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -167,7 +167,7 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl */ public function supports($resource, $type = null) { - return is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || 'annotation' === $type); + return is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (false !== strpos($resource, '\\') || class_exists($resource)) && (!$type || 'annotation' === $type); } /** diff --git a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php index 4574a0201c0c3..8f809795db9b3 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php @@ -76,14 +76,19 @@ function (\SplFileInfo $current) { */ public function supports($resource, $type = null) { - if ('annotation' === $type) { - return true; + if (!is_string($resource) || ($type && 'annotation' !== $type)) { + return false; } - if ($type || !is_string($resource)) { + // classes are handled by the AnnotationClassLoader + if (preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (false !== strpos($resource, '\\') || class_exists($resource))) { return false; } + if ('annotation' === $type) { + return true; + } + try { return is_dir($this->locator->locate($resource)); } catch (\Exception $e) { diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php index 1e8ee394015e1..20e80700aaf41 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php @@ -74,6 +74,11 @@ public function testItSupportsAnyAnnotation() $this->assertTrue($this->loader->supports(__DIR__.'/../Fixtures/even-with-not-existing-folder', 'annotation')); } + public function testItDoesNotSupportAnnotatedControllerClasses() + { + $this->assertFalse($this->loader->supports('App\Controller\TestController', 'annotation')); + } + public function testLoadFileIfLocatedResourceIsFile() { $this->reader->expects($this->exactly(1))->method('getClassAnnotation');