Skip to content

Commit 238d749

Browse files
Merge branch '6.4' into 7.4
* 6.4: [RateLimiter] Fix retryAfter when consuming exactly all remaining tokens in FixedWindow and TokenBucket [RateLimiter] Fix retryAfter value on last token consume (SlidingWindow) [RateLimiter] Fix reservations outside the second fixed window [Filesystem] makePathRelative with existing files, remove ending / [Config][Routing] Fix exclude option being ignored for non-glob and PSR-4 resources [Serializer][Validator] Fix propertyPath in ConstraintViolationListNormalizer with MetadataAwareNameConverter [Messenger][Amqp] Don't use retry routing key when sending to failure transport [Messenger] Fix re-sending failed messages to a different failure transport [DependencyInjection] Fix #[AsTaggedItem] discovery through multi-level decoration chains [DependencyInjection] Fix PriorityTaggedServiceTrait not discovering #[AsTaggedItem] on decorated services [Mailer] Clarify the purpose of SentMessage's "message id" concept [TwigBridge] Fix Bootstrap 4 form error layout [Form] Fix merging POST params and files when collection entries have mismatched indices [Validator] Fix type error for non-array items when Unique::fields is set [HttpKernel] Fix default locale ignored when Accept-Language has no enabled-locale match [FrameworkBundle] Make `ConfigDebugCommand` use its container to resolve env vars [Console] Fix various completion edge cases [Messenger][AmazonSqs] Add test for default queue_name when not set in DSN path or options
2 parents 1ca25c9 + 5ab3a3e commit 238d749

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

Loader/Psr4DirectoryLoader.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function __construct(
3939
*/
4040
public function load(mixed $resource, ?string $type = null): ?RouteCollection
4141
{
42+
$excluded = $resource['_excluded'] ?? [];
4243
$path = $this->locator->locate($resource['path'], $this->currentDirectory);
4344
if (!is_dir($path)) {
4445
return new RouteCollection();
@@ -48,7 +49,7 @@ public function load(mixed $resource, ?string $type = null): ?RouteCollection
4849
throw new InvalidArgumentException(\sprintf('Namespace "%s" is not a valid PSR-4 prefix.', $resource['namespace']));
4950
}
5051

51-
return $this->loadFromDirectory($path, trim($resource['namespace'], '\\'));
52+
return $this->loadFromDirectory($path, trim($resource['namespace'], '\\'), $excluded);
5253
}
5354

5455
public function supports(mixed $resource, ?string $type = null): bool
@@ -64,7 +65,7 @@ public function forDirectory(string $currentDirectory): static
6465
return $loader;
6566
}
6667

67-
private function loadFromDirectory(string $directory, string $psr4Prefix): RouteCollection
68+
private function loadFromDirectory(string $directory, string $psr4Prefix, array $excluded = []): RouteCollection
6869
{
6970
$collection = new RouteCollection();
7071
$collection->addResource(new DirectoryResource($directory, '/\.php$/'));
@@ -79,8 +80,13 @@ private function loadFromDirectory(string $directory, string $psr4Prefix): Route
7980

8081
/** @var \SplFileInfo $file */
8182
foreach ($files as $file) {
83+
$normalizedPath = rtrim(str_replace('\\', '/', $file->getPathname()), '/');
84+
if (isset($excluded[$normalizedPath])) {
85+
continue;
86+
}
87+
8288
if ($file->isDir()) {
83-
$collection->addCollection($this->loadFromDirectory($file->getPathname(), $psr4Prefix.'\\'.$file->getFilename()));
89+
$collection->addCollection($this->loadFromDirectory($file->getPathname(), $psr4Prefix.'\\'.$file->getFilename(), $excluded));
8490

8591
continue;
8692
}

Tests/Loader/Psr4DirectoryLoaderTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,38 @@ public function testAbstractController()
6767
$this->assertSame(MyChildController::class.'::someAction', $route->getDefault('_controller'));
6868
}
6969

70+
public function testExcludeSubNamespace()
71+
{
72+
$fixturesPath = \dirname(__DIR__).'/Fixtures';
73+
$excluded = [
74+
rtrim(str_replace('\\', '/', $fixturesPath.'/Psr4Controllers/SubNamespace'), '/') => true,
75+
];
76+
$collection = $this->getLoader()->load(
77+
['path' => 'Psr4Controllers', 'namespace' => 'Symfony\Component\Routing\Tests\Fixtures\Psr4Controllers', '_excluded' => $excluded],
78+
'attribute'
79+
);
80+
81+
$this->assertNotNull($collection->get('my_route'));
82+
$this->assertNull($collection->get('my_other_controller_one'));
83+
$this->assertNull($collection->get('my_controller_with_a_trait'));
84+
$this->assertNull($collection->get('my_child_controller_from_abstract'));
85+
}
86+
87+
public function testExcludeSingleFile()
88+
{
89+
$fixturesPath = \dirname(__DIR__).'/Fixtures';
90+
$excluded = [
91+
rtrim(str_replace('\\', '/', $fixturesPath.'/Psr4Controllers/MyController.php'), '/') => true,
92+
];
93+
$collection = $this->getLoader()->load(
94+
['path' => 'Psr4Controllers', 'namespace' => 'Symfony\Component\Routing\Tests\Fixtures\Psr4Controllers', '_excluded' => $excluded],
95+
'attribute'
96+
);
97+
98+
$this->assertNull($collection->get('my_route'));
99+
$this->assertNotNull($collection->get('my_other_controller_one'));
100+
}
101+
70102
#[DataProvider('provideNamespacesThatNeedTrimming')]
71103
public function testPsr4NamespaceTrim(string $namespace)
72104
{

0 commit comments

Comments
 (0)