Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit91b2bca

Browse files
bug#48170 [Routing] Fix PSR-4 directory loader for abstract classes (derrabus)
This PR was merged into the 6.2 branch.Discussion----------[Routing] Fix PSR-4 directory loader for abstract classes| Q | A| ------------- | ---| Branch? | 6.2| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fix#48168, Replaces#48169| License | MIT| Doc PR | N/ACommits-------a232a23 [Routing] Fix PSR-4 directory loader for abstract classes
2 parentsb02a689 +a232a23 commit91b2bca

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

‎src/Symfony/Component/Routing/Loader/Psr4DirectoryLoader.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
namespaceSymfony\Component\Routing\Tests\Fixtures\Psr4Controllers\SubNamespace;
13+
14+
useSymfony\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+
finalclass IrrelevantClass
23+
{
24+
publicfunctionirrelevantAction():Response
25+
{
26+
returnnewResponse(status: Response::HTTP_NO_CONTENT);
27+
}
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
namespaceSymfony\Component\Routing\Tests\Fixtures\Psr4Controllers\SubNamespace;
13+
14+
useSymfony\Component\HttpFoundation\Response;
15+
useSymfony\Component\Routing\Annotation\Route;
16+
17+
abstractclass MyAbstractController
18+
{
19+
#[Route('/a/route/from/an/abstract/controller', name:'from_abstract')]
20+
publicfunctionsomeAction():Response
21+
{
22+
returnnewResponse(status: Response::HTTP_NO_CONTENT);
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
namespaceSymfony\Component\Routing\Tests\Fixtures\Psr4Controllers\SubNamespace;
13+
14+
useSymfony\Component\Routing\Annotation\Route;
15+
16+
#[Route('/my/child/controller', name:'my_child_controller_')]
17+
finalclass MyChildControllerextends MyAbstractController
18+
{
19+
}

‎src/Symfony/Component/Routing/Tests/Loader/Psr4DirectoryLoaderTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
useSymfony\Component\Routing\RouteCollection;
2222
useSymfony\Component\Routing\Tests\Fixtures\Psr4Controllers\MyController;
2323
useSymfony\Component\Routing\Tests\Fixtures\Psr4Controllers\SubNamespace\EvenDeeperNamespace\MyOtherController;
24+
useSymfony\Component\Routing\Tests\Fixtures\Psr4Controllers\SubNamespace\MyChildController;
2425
useSymfony\Component\Routing\Tests\Fixtures\Psr4Controllers\SubNamespace\MyControllerWithATrait;
2526

2627
class Psr4DirectoryLoaderTestextends TestCase
@@ -56,6 +57,14 @@ public function testTraitController()
5657
$this->assertSame(MyControllerWithATrait::class.'::someAction',$route->getDefault('_controller'));
5758
}
5859

60+
publicfunctiontestAbstractController()
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
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp