Skip to content

Commit 1c7af36

Browse files
tjveldhuizennicolas-grekas
authored andcommitted
[Routing] Remove @final annotation from Route attribute
To be able to create a custom attribute containing application or section level defaults, the final annotation is removed from the Route attribute. Fixes #53467
1 parent 98eab13 commit 1c7af36

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

Attribute/Route.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
*
2121
* @author Fabien Potencier <[email protected]>
2222
* @author Alexander M. Turek <[email protected]>
23-
*
24-
* @final since Symfony 6.4
2523
*/
2624
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
2725
class Route
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures;
4+
5+
use Symfony\Component\Routing\Attribute\Route;
6+
7+
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
8+
class ExtendedRoute extends Route
9+
{
10+
public function __construct(array|string $path = null, ?string $name = null, array $defaults = []) {
11+
parent::__construct("/{section<(foo|bar|baz)>}" . $path, $name, [], [], array_merge(['section' => 'foo'], $defaults));
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures;
4+
5+
use Symfony\Component\Routing\Attribute\Route;
6+
7+
#[ExtendedRoute('/class-level')]
8+
class ExtendedRouteOnClassController
9+
{
10+
#[Route(path: '/method-level', name: 'action')]
11+
public function action()
12+
{
13+
}
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures;
4+
5+
class ExtendedRouteOnMethodController
6+
{
7+
#[ExtendedRoute(path: '/method-level', name: 'action')]
8+
public function action()
9+
{
10+
}
11+
}

Tests/Loader/AttributeClassLoaderTestCase.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\Routing\Alias;
1717
use Symfony\Component\Routing\Loader\AttributeClassLoader;
1818
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\AbstractClassController;
19+
use Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures\ExtendedRouteOnClassController;
20+
use Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures\ExtendedRouteOnMethodController;
1921

2022
abstract class AttributeClassLoaderTestCase extends TestCase
2123
{
@@ -312,5 +314,21 @@ public function testMethodsAndSchemes()
312314
$this->assertSame(['https'], $routes->get('string')->getSchemes());
313315
}
314316

317+
public function testLoadingExtendedRouteOnClass()
318+
{
319+
$routes = $this->loader->load(ExtendedRouteOnClassController::class);
320+
$this->assertCount(1, $routes);
321+
$this->assertSame('/{section}/class-level/method-level', $routes->get('action')->getPath());
322+
$this->assertSame(['section' => 'foo'], $routes->get('action')->getDefaults());
323+
}
324+
325+
public function testLoadingExtendedRouteOnMethod()
326+
{
327+
$routes = $this->loader->load(ExtendedRouteOnMethodController::class);
328+
$this->assertCount(1, $routes);
329+
$this->assertSame('/{section}/method-level', $routes->get('action')->getPath());
330+
$this->assertSame(['section' => 'foo'], $routes->get('action')->getDefaults());
331+
}
332+
315333
abstract protected function getNamespace(): string;
316334
}

0 commit comments

Comments
 (0)