8000 [Routing] Remove remaining deprecations · symfony/symfony@4076990 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4076990

Browse files
[Routing] Remove remaining deprecations
1 parent 8dc7b48 commit 4076990

12 files changed

+58
-221
lines changed

.github/expected-missing-return-types.diff

Lines changed: 0 additions & 10 deletions
< 67E6 div data-testid="deletion diffstat" class="DiffSquares-module__diffSquare--h5kjy DiffSquares-module__deletion--hKV3q">
Original file line numberDiff line numberDiff line change
@@ -408,16 +408,6 @@ diff --git a/src/Symfony/Component/HttpKernel/KernelInterface.php b/src/Symfony/
408408
- public function shutdown();
409409
+ public function shutdown(): void;
410410

411-
/**
412-
diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
413-
--- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
414-
+++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
415-
@@ -324,5 +324,5 @@ abstract class AnnotationClassLoader implements LoaderInterface
416-
* @return void
417-
*/
418-
- abstract protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot);
419-
+ abstract protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void;
420-
421411
/**
422412
diff --git a/src/Symfony/Component/Security/Core/Authentication/RememberMe/TokenProviderInterface.php b/src/Symfony/Component/Security/Core/Authentication/RememberMe/TokenProviderInterface.php
423413
--- a/src/Symfony/Component/Security/Core/Authentication/RememberMe/TokenProviderInterface.php

UPGRADE-7.0.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ FrameworkBundle
248248
* Change default of some config options:
249249

250250
| option | default Symfony <7.0 | default in Symfony 7.0+ |
251-
| -------------------------------------------- | -------------------------- | --------------------------------------------------------------------------- |
251+
|----------------------------------------------|----------------------------|-----------------------------------------------------------------------------|
252252
| `framework.http_method_override` | `true` | `false` |
253253
| `framework.handle_all_throwables` | `false` | `true` |
254254
| `framework.php_errors.log` | `'%kernel.debug%'` | `true` |
@@ -260,6 +260,10 @@ FrameworkBundle
260260
| `framework.validation.email_validation_mode` | `'loose'` | `'html5'` |
261261
* Remove the `framework.validation.enable_annotations` config option, use `framework.validation.enable_attributes` instead
262262
* Remove the `framework.serializer.enable_annotations` config option, use `framework.serializer.enable_attributes` instead
263+
* Remove the `routing.loader.annotation` service, use the `routing.loader.attribute` service instead
264+
* Remove the `routing.loader.annotation.directory` service, use the `routing.loader.attribute.directory` service instead
265+
* Remove the `routing.loader.annotation.file` service, use the `routing.loader.attribute.file` service instead
266+
* Remove `AnnotatedRouteControllerLoader`, use `AttributeRouteControllerLoader` instead
263267

264268
HttpFoundation
265269
--------------
@@ -400,7 +404,9 @@ Routing
400404

401405
* Add parameter `array $routeParameters` to `UrlMatcher::handleRouteRequirements()`
402406
* Remove Doctrine annotations support in favor of native attributes. Use `Symfony\Component\Routing\Annotation\Route` as native attribute now
403-
* Change the constructor signature of `AnnotationClassLoader` to `__construct(?string $env = null)`, passing an annotation reader as first argument is not supported anymore
407+
* Remove `AnnotationClassLoader`, use `AttributeClassLoader` instead
408+
* Remove `AnnotationDirectoryLoader`, use `AttributeDirectoryLoader` instead
409+
* Remove `AnnotationFileLoader`, use `AttributeFileLoader` instead
404410

405411
Security
406412
--------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ CHANGELOG
2424
* Make the `framework.validation.email_validation_mode` config option default to `html5`
2525
* Remove the `framework.validation.enable_annotations` config option, use `framework.validation.enable_attributes` instead
2626
* Remove the `framework.serializer.enable_annotations` config option, use `framework.serializer.enable_attributes` instead
27+
* Remove the `routing.loader.annotation` service, use the `routing.loader.attribute` service instead
28+
* Remove the `routing.loader.annotation.directory` service, use the `routing.loader.attribute.directory` service instead
29+
* Remove the `routing.loader.annotation.file` service, use the `routing.loader.attribute.file` service instead
30+
* Remove `AnnotatedRouteControllerLoader`, use `AttributeRouteControllerLoader` instead
2731

2832
6.4
2933
---

src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,29 +98,20 @@
9898
])
9999
->tag('routing.loader', ['priority' => -10])
100100

101-
->alias('routing.loader.annotation', 'routing.loader.attribute')
102-
->deprecate('symfony/routing', '6.4', 'The "%alias_id%" service is deprecated, use the "routing.loader.attribute" service instead.')
103-
104101
->set('routing.loader.attribute.directory', AttributeDirectoryLoader::class)
105102
->args([
106103
service('file_locator'),
107104
service('routing.loader.attribute'),
108105
])
109106
->tag('routing.loader', ['priority' => -10])
110107

111-
->alias('routing.loader.annotation.directory', 'routing.loader.attribute.directory')
112-
->deprecate('symfony/routing', '6.4', 'The "%alias_id%" service is deprecated, use the "routing.loader.attribute.directory" service instead.')
113-
114108
->set('routing.loader.attribute.file', AttributeFileLoader::class)
115109
->args([
116110
service('file_locator'),
117111
service('routing.loader.attribute'),
118112
])
119113
->tag('routing.loader', ['priority' => -10])
120114

121-
->alias('routing.loader.annotation.file', 'routing.loader.attribute.file')
122-
->deprecate('symfony/routing', '6.4', 'The "%alias_id%" service is deprecated, use the "routing.loader.attribute.file" service instead.')
123-
124115
->set('routing.loader.psr4', Psr4DirectoryLoader::class)
125116
->args([
126117
service('file_locator'),

src/Symfony/Bundle/FrameworkBundle/Routing/AttributeRouteControllerLoader.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ class AttributeRouteControllerLoader extends AttributeClassLoader
2525
{
2626
/**
2727
* Configures the _controller default parameter of a given Route instance.
28-
*
29-
* @return void
3028
*/
31-
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot)
29+
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void
3230
{
3331
if ('__invoke' === $method->getName()) {
3432
$route->setDefault('_controller', $class->getName());
@@ -51,7 +49,3 @@ protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMetho
5149
return str_replace('__', '_', $name);
5250
}
5351
}
54-
55-
if (!class_exists(AnnotatedRouteControllerLoader::class, false)) {
56-
class_alias(AttributeRouteControllerLoader::class, AnnotatedRouteControllerLoader::class);
57-
}

src/Symfony/Component/Routing/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ CHANGELOG
66

77
* Add argument `$routeParameters` to `UrlMatcher::handleRouteRequirements()`
88
* Remove Doctrine annotations support in favor of native attributes
9-
* Change the constructor signature of `AnnotationClassLoader` to `__construct(?string $env = null)`, passing an annotation reader as first argument is not supported anymore
9+
* Remove `AnnotationClassLoader`, use `AttributeClassLoader` instead
10+
* Remove `AnnotationDirectoryLoader`, use `AttributeDirectoryLoader` instead
11+
* Remove `AnnotationFileLoader`, use `AttributeFileLoader` instead
1012

1113
6.4
1214
---

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

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

Lines changed: 38 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Routing\Loader;
1313

14-
use Doctrine\Common\Annotations\Reader;
1514
use Symfony\Component\Config\Loader\LoaderInterface;
1615
use Symfony\Component\Config\Loader\LoaderResolverInterface;
1716
use Symfony\Component\Config\Resource\FileResource;
@@ -53,57 +52,18 @@
5352
*/
5453
abstract class AttributeClassLoader implements LoaderInterface
5554
{
56-
/**
57-
* @var Reader|null
58-
*
59-
* @deprecated in Symfony 6.4, this property will be removed in Symfony 7.
60-
*/
61-
protected $reader;
62-
63-
/**
64-
* @var string|null
65-
*/
66-
protected $env;
67-
68-
/**
69-
* @var string
70-
*/
71-
protected $routeAnnotationClass = RouteAnnotation::class;
55+
protected string $routeAnnotationClass = RouteAnnotation::class;
56+
protected int $defaultRouteIndex = 0;
7257

73-
/**
74-
* @var int
75-
*/
76-
protected $defaultRouteIndex = 0;
77-
78-
private bool $hasDeprecatedAnnotations = false;
79-
80-
/**
81-
* @param string|null $env
82-
*/
83-
public function __construct($env = null)
84-
{
85-
if ($env instanceof Reader || null === $env && \func_num_args() > 1 && null !== func_get_arg(1)) {
86-
trigger_deprecation('symfony/routing', '6.4', 'Passing an instance of "%s" as first and the environment as second argument to "%s" is deprecated. Pass the environment as first argument instead.', Reader::class, __METHOD__);
87-
88-
$this->reader = $env;
89-
$env = \func_num_args() > 1 ? func_get_arg(1) : null;
90-
}
91-
92-
if (\is_string($env) || null === $env) {
93-
$this->env = $env;
94-
} elseif ($env instanceof \Stringable || \is_scalar($env)) {
95-
$this->env = (string) $env;
96-
} else {
97-
throw new \TypeError(__METHOD__.sprintf(': Parameter $env was expected to be a string or null, "%s" given.', get_debug_type($env)));
98-
}
58+
public function __construct(
59+
protected readonly ?string $env = null,
60+
) {
9961
}
10062

10163
/**
10264
* Sets the annotation class to read route properties from.
103-
*
104-
* @return void
10565
*/
106-
public function setRouteAnnotationClass(string $class)
66+
public function setRouteAnnotationClass(string $class): void
10767
{
10868
$this->routeAnnotationClass = $class;
10969
}
@@ -124,59 +84,47 @@ public function load(mixed $class, string $type = null): RouteCollection
12484
throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class->getName()));
12585
}
12686

127-
$this->hasDeprecatedAnnotations = false;
128-
129-
try {
130-
$globals = $this->getGlobals($class);
131-
$collection = new RouteCollection();
132-
$collection->addResource(new FileResource($class->getFileName()));
133-
if ($globals['env'] && $this->env !== $globals['env']) {
134-
return $collection;
135-
}
136-
$fqcnAlias = false;
137-
foreach ($class->getMethods() as $method) {
138-
$this->defaultRouteIndex = 0;
139-
$routeNamesBefore = array_keys($collection->all());
140-
foreach ($this->getAnnotations($method) as $annot) {
141-
$this->addRoute($collection, $annot, $globals, $class, $method);
142-
if ('__invoke' === $method->name) {
143-
$fqcnAlias = true;
144-
}
145-
}
146-
147-
if (1 === $collection->count() - \count($routeNamesBefore)) {
148-
$newRouteName = current(array_diff(array_keys($collection->all()), $routeNamesBefore));
149-
$collection->addAlias(sprintf('%s::%s', $class->name, $method->name), $newRouteName);
150-
}
151-
}
152-
if (0 === $collection->count() && $class->hasMethod('__invoke')) {
153-
$globals = $this->resetGlobals();
154-
foreach ($this->getAnnotations($class) as $annot) {
155-
$this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
87+
$globals = $this->getGlobals($class);
88+
$collection = new RouteCollection();
89+
$collection->addResource(new FileResource($class->getFileName()));
90+
if ($globals['env'] && $this->env !== $globals['env']) {
91+
return $collection;
92+
}
93+
$fqcnAlias = false;
94+
foreach ($class->getMethods() as $method) {
95+
$this->defaultRouteIndex = 0;
96+
$routeNamesBefore = array_keys($collection->all());
97+
foreach ($this->getAnnotations($method) as $annot) {
98+
$this->addRoute($collection, $annot, $globals, $class, $method);
99+
if ('__invoke' === $method->name) {
156100
$fqcnAlias = true;
157101
}
158102
}
159-
if ($fqcnAlias && 1 === $collection->count()) {
160-
$collection->addAlias($class->name, $invokeRouteName = key($collection->all()));
161-
$collection->addAlias(sprintf('%s::__invoke', $class->name), $invokeRouteName);
162-
}
163103

164-
if ($this->hasDeprecatedAnnotations) {
165-
trigger_deprecation('symfony/routing', '6.4', 'Class "%s" uses Doctrine Annotations to configure routes, which is deprecated. Use PHP attributes instead.', $class->getName());
104+
if (1 === $collection->count() - \count($routeNamesBefore)) {
105+
$newRouteName = current(array_diff(array_keys($collection->all()), $routeNamesBefore));
106+
$collection->addAlias(sprintf('%s::%s', $class->name, $method->name), $newRouteName);
107+
}
108+
}
109+
if (0 === $collection->count() && $class->hasMethod('__invoke')) {
110+
$globals = $this->resetGlobals();
111+
foreach ($this->getAnnotations($class) as $annot) {
112+
$this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
113+
$fqcnAlias = true;
166114
}
167-
} finally {
168-
$this->hasDeprecatedAnnotations = false;
115+
}
116+
if ($fqcnAlias && 1 === $collection->count()) {
117+
$collection->addAlias($class->name, $invokeRouteName = key($collection->all()));
118+
$collection->addAlias(sprintf('%s::__invoke', $class->name), $invokeRouteName);
169119
}
170120

171121
return $collection;
172122
}
173123

174124
/**
175125
* @param RouteAnnotation $annot or an object that exposes a similar interface
176-
*
177-
* @return void
178126
*/
179-
protected function addRoute(RouteCollection $collection, object $annot, array $globals, \ReflectionClass $class, \ReflectionMethod $method)
127+
protected function addRoute(RouteCollection $collection, object $annot, array $globals, \ReflectionClass $class, \ReflectionMethod $method): void
180128
{
181129
if ($annot->getEnv() && $annot->getEnv() !== $this->env) {
182130
return;
@@ -263,11 +211,7 @@ protected function addRoute(RouteCollection $collection, object $annot, array $g
263211

264212
public function supports(mixed $resource, string $type = null): bool
265213
{
266-
if ('annotation' === $type) {
267-
trigger_deprecation('symfony/routing', '6.4', 'The "annotation" route type is deprecated, use the "attribute" route type instead.');
268-
}
269-
270-
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));
214+
return \is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || 'attribute' === $type);
271215
}
272216

273217
public function setResolver(LoaderResolverInterface $resolver): void
@@ -280,10 +224,8 @@ public function getResolver(): LoaderResolverInterface
280224

281225
/**
282226
* Gets the default route name for a class method.
283-
*
284-
* @return string
285227
*/
286-
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
228+
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method): string
287229
{
288230
$name = str_replace('\\', '_', $class->name).'_'.$method->name;
289231
$name = \function_exists('mb_strtolower') && preg_match('//u', $name) ? mb_strtolower($name, 'UTF-8') : strtolower($name);
@@ -298,19 +240,13 @@ protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMetho
298240
/**
299241
* @return array<string, mixed>
300242
*/
301-
protected function getGlobals(\ReflectionClass $class)
243+
protected function getGlobals(\ReflectionClass $class): array
302244
{
303245
$globals = $this->resetGlobals();
304246

305-
$annot = null;
306247
if ($attribute = $class->getAttributes($this->routeAnnotationClass, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null) {
307248
$annot = $attribute->newInstance();
308-
}
309-
if (!$annot && $annot = $this->reader?->getClassAnnotation($class, $this->routeAnnotationClass)) {
310-
$this->hasDeprecatedAnnotations = true;
311-
}
312249

313-
if ($annot) {
314250
if (null !== $annot->getName()) {
315251
$globals['name'] = $annot->getName();
316252
}
@@ -380,10 +316,7 @@ private function resetGlobals(): array
380316
];
381317
}
382318

383-
/**
384-
* @return Route
385-
*/
386-
protected function createRoute(string $path, array $defaults, array $requirements, array $options, ?string $host, array $schemes, array $methods, ?string $condition)
319+
protected function createRoute(string $path, array $defaults, array $requirements, array $options, ?string $host, array $schemes, array $methods, ?string $condition): Route
387320
{
388321
return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);
389322
}
@@ -401,25 +334,5 @@ private function getAnnotations(\ReflectionClass|\ReflectionMethod $reflection):
401334
foreach ($reflection->getAttributes($this->routeAnnotationClass, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
402335
yield $attribute->newInstance();
403336
}
404-
405-
if (!$this->reader) {
406-
return;
407-
}
408-
409-
$annotations = $reflection instanceof \ReflectionClass
410-
? $this->reader->getClassAnnotations($reflection)
411-
: $this->reader->getMethodAnnotations($reflection);
412-
413-
foreach ($annotations as $annotation) {
414-
if ($annotation instanceof $this->routeAnnotationClass) {
415-
$this->hasDeprecatedAnnotations = true;
416-
417-
yield $annotation;
418-
}
419-
}
420337
}
421338
}
422-
423-
if (!class_exists(AnnotationClassLoader::class, false)) {
424-
class_alias(AttributeClassLoader::class, AnnotationClassLoader::class);
425-
}

0 commit comments

Comments
 (0)
0