8000 [Routing] Support the "attribute" type (alias of "annotation") in ann… · symfony/symfony@23dc924 · GitHub
[go: up one dir, main page]

Skip to content

Commit 23dc924

Browse files
committed
[Routing] Support the "attribute" type (alias of "annotation") in annotation loaders
1 parent a4241f3 commit 23dc924

File tree

8 files changed

+13
-3
lines changed

8 files changed

+13
-3
lines changed

src/Symfony/Component/Config/Tests/Exception/LoaderLoadExceptionTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public function testMessageCannotLoadResourceWithAnnotationType()
3434
$this->assertEquals('Cannot load resource "resource". Make sure there is a loader supporting the "annotation" type.', $exception->getMessage());
3535
}
3636

37+
public function testMessageCannotLoadResourceWithAttributeType()
38+
{
39+
$exception = new LoaderLoadException('resource', null, 0, null, 'attribute');
40+
$this->assertEquals('Cannot load resource "resource". Make sure there is a loader supporting the "attribute" type.', $exception->getMessage());
41+
}
42+
3743
public function testMessageCannotImportResourceFromSource()
3844
{
3945
$exception = new LoaderLoadException('resource', 'sourceResource');

src/Symfony/Component/Routing/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add `getMissingParameters` and `getRouteName` methods on `MissingMandatoryParametersException`
88
* Allow using UTF-8 parameter names
9+
* Support the `attribute` type (alias of `annotation`) in annotation loaders
910

1011
5.3
1112
---

src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ protected function addRoute(RouteCollection $collection, object $annot, array $g
237237
*/
238238
public function supports(mixed $resource, string $type = null): bool
239239
{
240-
return \is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || 'annotation' === $type);
240+
return \is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || \in_array($type, ['annotation', 'attribute'], true));
241241
}
242242

243243
/**

src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function (\SplFileInfo $current) {
6969
*/
7070
public function supports(mixed $resource, string $type = null): bool
7171
{
72-
if ('annotation' === $type) {
72+
if (\in_array($type, ['annotation', 'attribute'], true)) {
7373
return true;
7474
}
7575

src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function load(mixed $file, string $type = null): ?RouteCollection
6767
*/
6868
public function supports(mixed $resource, string $type = null): bool
6969
{
70-
return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || 'annotation' === $type);
70+
return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || \in_array($type, ['annotation', 'attribute'], true));
7171
}
7272

7373
/**

src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function provideTestSupportsChecksResource()
4646
public function testSupportsChecksTypeIfSpecified()
4747
{
4848
$this->assertTrue($this->loader->supports('class', 'annotation'), '->supports() checks the resource type if specified');
49+
$this->assertTrue($this->loader->supports('class', 'attribute'), '->supports() checks the resource type if specified');
4950
$this->assertFalse($this->loader->supports('class', 'foo'), '->supports() checks the resource type if specified');
5051
}
5152

src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function testSupports()
7878
$this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
7979

8080
$this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified');
81+
$this->assertTrue($this->loader->supports($fixturesDir, 'attribute'), '->supports() checks the resource type if specified');
8182
$this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified');
8283
}
8384

src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function testSupports()
8383
$this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
8484

8585
$this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
86+
$this->assertTrue($this->loader->supports($fixture, 'attribute'), '->supports() checks the resource type if specified');
8687
$this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
8788
}
8889

0 commit comments

Comments
 (0)
0