File tree Expand file tree Collapse file tree 5 files changed +81
-1
lines changed
src/Symfony/Component/Routing
Fixtures/Psr4Controllers/SubNamespace Expand file tree Collapse file tree 5 files changed +81
-1
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ function (\SplFileInfo $current) {
8383
8484 continue ;
8585 }
86- if ('php ' !== $ file ->getExtension () || !class_exists ($ className = $ psr4Prefix .'\\' .$ file ->getBasename ('.php ' ))) {
86+ if ('php ' !== $ file ->getExtension () || !class_exists ($ className = $ psr4Prefix .'\\' .$ file ->getBasename ('.php ' )) || ( new \ ReflectionClass ( $ className ))-> isAbstract () ) {
8787 continue ;
8888 }
8989
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Symfony package.
5+ *
6+ * (c) Fabien Potencier <fabien@symfony.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Symfony \Component \Routing \Tests \Fixtures \Psr4Controllers \SubNamespace ;
13+
14+ use Symfony \Component \HttpFoundation \Response ;
15+
16+ /**
17+ * An irrelevant class.
18+ *
19+ * This fixture is not referenced anywhere. Its presence makes sure, classes without attributes are silently ignored
20+ * when loading routes from a directory.
21+ */
22+ final class IrrelevantClass
23+ {
24+ public function irrelevantAction (): Response
25+ {
26+ return new Response (status: Response::HTTP_NO_CONTENT );
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Symfony package.
5+ *
6+ * (c) Fabien Potencier <fabien@symfony.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Symfony \Component \Routing \Tests \Fixtures \Psr4Controllers \SubNamespace ;
13+
14+ use Symfony \Component \HttpFoundation \Response ;
15+ use Symfony \Component \Routing \Annotation \Route ;
16+
17+ abstract class MyAbstractController
18+ {
19+ #[Route('/a/route/from/an/abstract/controller ' , name: 'from_abstract ' )]
20+ public function someAction (): Response
21+ {
22+ return new Response (status: Response::HTTP_NO_CONTENT );
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Symfony package.
5+ *
6+ * (c) Fabien Potencier <fabien@symfony.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Symfony \Component \Routing \Tests \Fixtures \Psr4Controllers \SubNamespace ;
13+
14+ use Symfony \Component \Routing \Annotation \Route ;
15+
16+ #[Route('/my/child/controller ' , name: 'my_child_controller_ ' )]
17+ final class MyChildController extends MyAbstractController
18+ {
19+ }
Original file line number Diff line number Diff line change 2121use Symfony \Component \Routing \RouteCollection ;
2222use Symfony \Component \Routing \Tests \Fixtures \Psr4Controllers \MyController ;
2323use Symfony \Component \Routing \Tests \Fixtures \Psr4Controllers \SubNamespace \EvenDeeperNamespace \MyOtherController ;
24+ use Symfony \Component \Routing \Tests \Fixtures \Psr4Controllers \SubNamespace \MyChildController ;
2425use Symfony \Component \Routing \Tests \Fixtures \Psr4Controllers \SubNamespace \MyControllerWithATrait ;
2526
2627class Psr4DirectoryLoaderTest extends TestCase
@@ -56,6 +57,14 @@ public function testTraitController()
5657 $ this ->assertSame (MyControllerWithATrait::class.'::someAction ' , $ route ->getDefault ('_controller ' ));
5758 }
5859
60+ public function testAbstractController ()
61+ {
62+ $ route = $ this ->loadPsr4Controllers ()->get ('my_child_controller_from_abstract ' );
63+
64+ $ this ->assertSame ('/my/child/controller/a/route/from/an/abstract/controller ' , $ route ->getPath ());
65+ $ this ->assertSame (MyChildController::class.'::someAction ' , $ route ->getDefault ('_controller ' ));
66+ }
67+
5968 /**
6069 * @dataProvider provideNamespacesThatNeedTrimming
6170 */
You can’t perform that action at this time.
0 commit comments