8000 Merge branch '6.4' into 7.0 · symfony/symfony@2ab4e38 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ab4e38

Browse files
Merge branch '6.4' into 7.0
* 6.4: [FrameworkBundle][Routing] Deprecate annotations [FrameworkBundle][Serializer] Deprecate annotations
2 parents 2a5c0e6 + c817241 commit 2ab4e38

File tree

48 files changed

+836
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+836
-286
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/SerializerExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\Serializer\Encoder\JsonEncoder;
1919
use Symfony\Component\Serializer\Encoder\YamlEncoder;
2020
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
21-
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
21+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
2222
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
2323
use Symfony\Component\Serializer\Serializer;
2424
use Twig\Environment;
@@ -49,7 +49,7 @@ public static function serializerDataProvider(): \Generator
4949

5050
private function getTwig(string $template): Environment
5151
{
52-
$meta = new ClassMetadataFactory(new AnnotationLoader());
52+
$meta = new ClassMetadataFactory(new AttributeLoader());
5353
$runtime = new SerializerRuntime(new Serializer([new ObjectNormalizer($meta)], [new JsonEncoder(), new YamlEncoder()]));
5454

5555
$mockRuntimeLoader = $this->createMock(RuntimeLoaderInterface::class);

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"symfony/http-foundation": "<6.4",
6262
"symfony/http-kernel": "<6.4",
6363
"symfony/mime": "<6.4",
64-
"symfony/serializer": "<6.2",
64+
"symfony/serializer": "<6.4",
6565
"symfony/translation": "<6.4",
6666
"symfony/workflow": "<6.4"
6767
},

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ CHANGELOG
5858
* Change `framework.asset_mapper.importmap_polyfill` from a URL to the name of an item in the importmap
5959
* Provide `$buildDir` when running `CacheWarmer` to build read-only resources
6060
* Add the global `--profile` option to the console to enable profiling commands
61+
* Deprecate the `routing.loader.annotation` service, use the `routing.loader.attribute` service instead
62+
* Deprecate the `routing.loader.annotation.directory` service, use the `routing.loader.attribute.directory` service instead
63+
* Deprecate the `routing.loader.annotation.file` service, use the `routing.loader.attribute.file` service instead
64+
* Deprecate `AnnotatedRouteControllerLoader`, use `AttributeRouteControllerLoader` instead
6165

6266
6.3
6367
---

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
use Symfony\Component\Semaphore\Store\StoreFactory as SemaphoreStoreFactory;
152152
use Symfony\Component\Serializer\Encoder\DecoderInterface;
153153
use Symfony\Component\Serializer\Encoder\EncoderInterface;
154-
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
154+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
155155
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
156156
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
157157
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
@@ -1858,7 +1858,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
18581858

18591859
$serializerLoaders = [];
18601860
if (isset($config['enable_attributes']) && $config['enable_attributes']) {
1861-
$annotationLoader = new Definition(AnnotationLoader::class);
1861+
$annotationLoader = new Definition(AttributeLoader::class);
18621862

18631863
$serializerLoaders[] = $annotationLoader;
18641864
}

src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private function configureRoutes(RoutingConfigurator $routes): void
8585
}
8686

8787
if (false !== ($fileName = (new \ReflectionObject($this))->getFileName())) {
88-
$routes->import($fileName, 'annotation');
88+
$routes->import($fileName, 'attribute');
8989
}
9090
}
9191

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer;
1616
use Symfony\Bundle\FrameworkBundle\Controller\RedirectController;
1717
use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
18-
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
18+
use Symfony\Bundle\FrameworkBundle\Routing\AttributeRouteControllerLoader;
1919
use Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader;
2020
use Symfony\Bundle\FrameworkBundle\Routing\RedirectableCompiledUrlMatcher;
2121
use Symfony\Bundle\FrameworkBundle\Routing\Router;
@@ -24,8 +24,8 @@
2424
use Symfony\Component\Routing\Generator\CompiledUrlGenerator;
2525
use Symfony\Component\Routing\Generator\Dumper\CompiledUrlGeneratorDumper;
2626
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
27-
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
28-
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
27+
use Symfony\Component\Routing\Loader\AttributeDirectoryLoader;
28+
use Symfony\Component\Routing\Loader\AttributeFileLoader;
2929
use Symfony\Component\Routing\Loader\ContainerLoader;
3030
use Symfony\Component\Routing\Loader\DirectoryLoader;
3131
use Symfony\Component\Routing\Loader\GlobFileLoader;
@@ -92,26 +92,35 @@
9292
])
9393
->tag('routing.loader')
9494

95-
->set('routing.loader.annotation', AnnotatedRouteControllerLoader::class)
95+
->set('routing.loader.attribute', AttributeRouteControllerLoader::class)
9696
->args([
9797
'%kernel.environment%',
9898
])
9999
->tag('routing.loader', ['priority' => -10])
100100

101-
->set('routing.loader.annotation.directory', AnnotationDirectoryLoader::class)
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+
104+
->set('routing.loader.attribute.directory', AttributeDirectoryLoader::class)
102105
->args([
103106
service('file_locator'),
104-
service('routing.loader.annotation'),
107+
service('routing.loader.attribute'),
105108
])
106109
->tag('routing.loader', ['priority' => -10])
107110

108-
->set('routing.loader.annotation.file', AnnotationFileLoader::class)
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+
114+
->set('routing.loader.attribute.file', AttributeFileLoader::class)
109115
->args([
110116
service('file_locator'),
111-
service('routing.loader.annotation'),
117+
service('routing.loader.attribute'),
112118
])
113119
->tag('routing.loader', ['priority' => -10])
114120

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+
115124
->set('routing.loader.psr4', Psr4DirectoryLoader::class)
116125
->args([
117126
service('file_locator'),

src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php renamed to src/Symfony/Bundle/FrameworkBundle/Routing/AttributeRouteControllerLoader.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Routing;
1313

14-
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
14+
use Symfony\Component\Routing\Loader\AttributeClassLoader;
1515
use Symfony\Component\Routing\Route;
1616

1717
/**
18-
* AnnotatedRouteControllerLoader is an implementation of AnnotationClassLoader
18+
* AttributeRouteControllerLoader is an implementation of AttributeClassLoader
1919
* that sets the '_controller' default based on the class and method names.
2020
*
2121
* @author Fabien Potencier <fabien@symfony.com>
22+
* @author Alexandre Daubois <alex.daubois@gmail.com>
2223
*/
23-
class AnnotatedRouteControllerLoader extends AnnotationClassLoader
24+
class AttributeRouteControllerLoader extends AttributeClassLoader
2425
{
2526
/**
2627
* Configures the _controller default parameter of a given Route instance.
28+
*
29+
* @return void
2730
*/
28-
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void
31+
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot)
2932
{
3033
if ('__invoke' === $method->getName()) {
3134
$route->setDefault('_controller', $class->getName());
@@ -48,3 +51,7 @@ protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMetho
4851
return str_replace('__', '_', $name);
4952
}
5053
}
54+
55+
if (!class_exists(AnnotatedRouteControllerLoader::class, false)) {
56+
class_alias(AttributeRouteControllerLoader::class, AnnotatedRouteControllerLoader::class);
57+
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
use Symfony\Component\Notifier\TexterInterface;
6464
use Symfony\Component\PropertyAccess\PropertyAccessor;
6565
use Symfony\Component\Security\Core\AuthenticationEvents;
66-
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
66+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
6767
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
6868
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
6969
use Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer;
@@ -1425,7 +1425,7 @@ public function testSerializerEnabled()
14251425
$argument = $container->getDefinition('serializer.mapping.chain_loader')->getArgument(0);
14261426

14271427
$this->assertCount(2, $argument);
1428-
$this->assertEquals(AnnotationLoader::class, $argument[0]->getClass());
1428+
$this->assertEquals(AttributeLoader::class, $argument[0]->getClass());
14291429
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.name_converter.metadata_aware')->getArgument(1));
14301430
$this->assertEquals(new Reference('property_info', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE), $container->getDefinition('serializer.normalizer.object')->getArgument(3));
14311431
$this->assertArrayHasKey('circular_reference_handler', $container->getDefinition('serializer.normalizer.object')->getArgument(6));

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ http_client_call:
6767

6868
uid:
6969
resource: "../../Controller/UidController.php"
70-
type: "annotation"
70+
type: "attribute"
7171

7272
send_notification:
7373
path: /send_notification
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
_routingconditionservice_bundle:
22
prefix: /
33
resource: "@RoutingConditionServiceBundle/Controller"
4-
type: annotation
4+
type: attribute

src/Symfony/Component/PropertyInfo/Tests/Extractor/SerializerExtractorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
1818
use Symfony\Component\PropertyInfo\Tests\Fixtures\IgnorePropertyDummy;
1919
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
20-
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
20+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
2121

2222
/**
2323
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -28,7 +28,7 @@ class SerializerExtractorTest extends TestCase
2828

2929
protected function setUp(): void
3030
{
31-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader());
31+
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
3232
$this->extractor = new SerializerExtractor($classMetadataFactory);
3333
}
3434

src/Symfony/Component/Routing/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ CHANGELOG
1515
* Add native return type to `AnnotationClassLoader::setResolver()`
1616
* Deprecate Doctrine annotations support in favor of native attributes
1717
* Change the constructor signature of `AnnotationClassLoader` to `__construct(?string $env = null)`, passing an annotation reader as first argument is deprecated
18+
* Deprecate `AnnotationClassLoader`, use `AttributeClassLoader` instead
19+
* Deprecate `AnnotationDirectoryLoader`, use `AttributeDirectoryLoader` instead
20+
* Deprecate `AnnotationFileLoader`, use `AttributeFileLoader` instead
1821

1922
6.2
2023
---

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

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,73 +11,15 @@
1111

1212
namespace Symfony\Component\Routing\Loader;
1313

14-
use Symfony\Component\Config\Resource\DirectoryResource;
15-
use Symfony\Component\Routing\RouteCollection;
14+
trigger_deprecation('symfony/routing', '6.4', 'The "%s" class is deprecated, use "%s" instead.', AnnotationDirectoryLoader::class, AttributeDirectoryLoader::class);
1615

17-
/**
18-
* AnnotationDirectoryLoader loads routing information from annotations set
19-
* on PHP classes and methods.
20-
*
21-
* @author Fabien Potencier <fabien@symfony.com>
22-
*/
23-
class AnnotationDirectoryLoader extends AnnotationFileLoader
24-
{
16+
class_exists(AttributeDirectoryLoader::class);
17+
18+
if (false) {
2519
/**
26-
* @throws \InvalidArgumentException When the directory does not exist or its routes cannot be parsed
20+
* @deprecated since Symfony 6.4, to be removed in 7.0, use {@link AttributeDirectoryLoader} instead
2721
*/
28-
public function load(mixed $path, string $type = null): ?RouteCollection
29-
{
30-
if (!is_dir($dir = $this->locator->locate($path))) {
31-
return parent::supports($path, $type) ? parent::load($path, $type) : new RouteCollection();
32-
}
33-
34-
$collection = new RouteCollection();
35-
$collection->addResource(new DirectoryResource($dir, '/\.php$/'));
36-
$files = iterator_to_array(new \RecursiveIteratorIterator(
37-
new \RecursiveCallbackFilterIterator(
38-
new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
39-
fn (\SplFileInfo $current) => !str_starts_with($current->getBasename(), '.')
40-
),
41-
\RecursiveIteratorIterator::LEAVES_ONLY
42-
));
43-
usort($files, fn (\SplFileInfo $a, \SplFileInfo $b) => (string) $a > (string) $b ? 1 : -1);
44-
45-
foreach ($files as $file) {
46-
if (!$file->isFile() || !str_ends_with($file->getFilename(), '.php')) {
47-
continue;
48-
}
49-
50-
if ($class = $this->findClass($file)) {
51-
$refl = new \ReflectionClass($class);
52-
if ($refl->isAbstract()) {
53-
continue;
54-
}
55-
56-
$collection->addCollection($this->loader->load($class, $type));
57-
}
58-
}
59-
60-
return $collection;
61-
}
62-
63-
public function supports(mixed $resource, string $type = null): bool
22+
class AnnotationDirectoryLoader
6423
{
65-
if (!\is_string($resource)) {
66-
return false;
67-
}
68-
69-
if (\in_array($type, ['annotation', 'attribute'], true)) {
70-
return true;
71-
}
72-
73-
if ($type) {
74-
return false;
75-
}
76-
77-
try {
78-
return is_dir($this->locator->locate($resource));
79-
} catch (\Exception) {
80-
return false;
81-
}
8224
}
8325
}

0 commit comments

Comments
 (0)
0