Skip to content

Commit 5aa0f20

Browse files
committed
merge in serializer
1 parent 1f52369 commit 5aa0f20

File tree

237 files changed

+1860
-3202
lines changed

Some content is hidden

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

237 files changed

+1860
-3202
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"symfony/ldap": "self.version",
8585
"symfony/lock": "self.version",
8686
"symfony/mailer": "self.version",
87-
"symfony/ser-des": "self.version",
8887
"symfony/messenger": "self.version",
8988
"symfony/mime": "self.version",
9089
"symfony/monolog-bridge": "self.version",
@@ -188,7 +187,7 @@
188187
},
189188
"files": [
190189
"src/Symfony/Component/String/Resources/functions.php",
191-
"src/Symfony/Component/SerDes/Resources/functions.php"
190+
"src/Symfony/Component/Serializer/Resources/functions.php"
192191
],
193192
"classmap": [
194193
"src/Symfony/Component/Cache/Traits/ValueWrapper.php"

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
CHANGELOG
22
=========
33

4-
7.0
5-
---
6-
7-
* Register SerDes services
8-
94
6.3
105
---
116

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/SerDesCacheWarmer.php renamed to src/Symfony/Bundle/FrameworkBundle/CacheWarmer/SerializeDeserializeCacheWarmer.php

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,38 @@
1414
use Psr\Log\LoggerInterface;
1515
use Psr\Log\NullLogger;
1616
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
17-
use Symfony\Component\SerDes\Context\ContextBuilder\ContextBuilderInterface;
18-
use Symfony\Component\SerDes\Context\ContextBuilder\SerializeContextBuilderInterface;
19-
use Symfony\Component\SerDes\Exception\ExceptionInterface;
20-
use Symfony\Component\SerDes\SerializableResolver\SerializableResolverInterface;
21-
use Symfony\Component\SerDes\Template\TemplateHelper;
22-
use Symfony\Component\SerDes\Template\TemplateVariation;
17+
use Symfony\Component\Serializer\Context\ContextBuilder;
18+
use Symfony\Component\Serializer\Exception\ExceptionInterface;
19+
use Symfony\Component\Serializer\SerializableResolver\SerializableResolverInterface;
20+
use Symfony\Component\Serializer\Serialize\Template\TemplateHelper;
21+
use Symfony\Component\Serializer\Serialize\Template\TemplateVariation;
22+
use Symfony\Component\Serializer\Type\TypeFactory;
2323
use Symfony\Component\VarExporter\ProxyHelper;
2424

25-
use function Symfony\Component\SerDes\serialize_generate;
25+
use function Symfony\Component\Serializer\serialize_generate;
2626

2727
/**
2828
* @author Mathias Arlaud <[email protected]>
2929
*
3030
* @experimental in 7.0
3131
*/
32-
final class SerDesCacheWarmer extends CacheWarmer
32+
final class SerializeDeserializeCacheWarmer extends CacheWarmer
3333
{
34-
/**
35-
* @var iterable<ContextBuilderInterface>
36-
*/
37-
private iterable $contextBuilders = [];
38-
3934
private readonly TemplateHelper $templateHelper;
4035

4136
/**
42-
* @param iterable<SerializeContextBuilderInterface> $contextBuilders
43-
* @param list<string> $formats
37+
* @param list<string> $formats
4438
*/
4539
public function __construct(
40+
private readonly ContextBuilder $contextBuilder,
4641
private readonly SerializableResolverInterface $serializableResolver,
4742
private readonly string $templateCacheDir,
4843
private readonly string $lazyObjectCacheDir,
4944
private readonly array $formats,
5045
private readonly int $maxVariants,
5146
private readonly LoggerInterface $logger = new NullLogger(),
5247
) {
53-
$this->templateHelper = new TemplateHelper($this->templateCacheDir);
48+
$this->templateHelper = new TemplateHelper();
5449
}
5550

5651
public function warmUp(string $cacheDir): array
@@ -65,9 +60,10 @@ public function warmUp(string $cacheDir): array
6560

6661
foreach ($this->serializableResolver->resolve() as $className) {
6762
$variants = $this->templateHelper->classTemplateVariants($className);
63+
6864
if (\count($variants) > $this->maxVariants) {
6965
$this->logger->debug('Too many variants for "{className}", keeping only the first {maxVariants}.', ['className' => $className, 'maxVariants' => $this->maxVariants]);
70-
$variants = array_slice($variants, offset: 0, length: $this->maxVariants);
66+
$variants = \array_slice($variants, offset: 0, length: $this->maxVariants);
7167
}
7268

7369
foreach ($this->formats as $format) {
@@ -86,30 +82,17 @@ public function isOptional(): bool
8682
}
8783

8884
/**
89-
* @param iterable<ContextBuilderInterface> $contextBuilders
90-
*
91-
* @internal
92-
*/
93-
public function setContextBuilders(iterable $contextBuilders): void
94-
{
95-
$this->contextBuilders = $contextBuilders;
96-
}
97-
98-
/**
99-
* @param class-string $className
85+
* @param class-string $className
10086
* @param list<list<TemplateVariation>> $variants
10187
*/
10288
private function warmClassTemplate(string $className, array $variants, string $format): void
10389
{
10490
try {
10591
$context = [
10692
'cache_dir' => $this->templateCacheDir,
107-
'template_exists' => false,
10893
];
10994

110-
foreach ($this->contextBuilders as $contextBuilder) {
111-
$context = $contextBuilder->build($context, true);
112-
}
95+
$context = $this->contextBuilder->build($context, isSerialization: true);
11396

11497
foreach ($variants as $variant) {
11598
$variantContext = $context;
@@ -123,7 +106,7 @@ private function warmClassTemplate(string $className, array $variants, string $f
123106

124107
$this->writeCacheFile(
125108
$this->templateCacheDir.\DIRECTORY_SEPARATOR.$variantFilename,
126-
serialize_generate($className, $format, $variantContext),
109+
serialize_generate(TypeFactory::createFromString($className), $format, $variantContext),
127110
);
128111
}
129112
} catch (ExceptionInterface $e) {

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

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
use Symfony\Component\Lock\Lock;
3434
use Symfony\Component\Lock\Store\SemaphoreStore;
3535
use Symfony\Component\Mailer\Mailer;
36-
use Symfony\Component\SerDes\Serializer as SerDesSerializer;
3736
use Symfony\Component\Messenger\MessageBusInterface;
3837
use Symfony\Component\Notifier\Notifier;
3938
use Symfony\Component\PropertyAccess\PropertyAccessor;
@@ -189,7 +188,6 @@ public function getConfigTreeBuilder(): TreeBuilder
189188
$this->addHtmlSanitizerSection($rootNode, $enableIfStandalone);
190189
$this->addWebhookSection($rootNode, $enableIfStandalone);
191190
$this->addRemoteEventSection($rootNode, $enableIfStandalone);
192-
$this->addSerDesSection($rootNode, $enableIfStandalone);
193191

194192
return $treeBuilder;
195193
}
@@ -1100,6 +1098,7 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e
11001098
->arrayNode('serializer')
11011099
->info('serializer configuration')
11021100
->{$enableIfStandalone('symfony/serializer', Serializer::class)}()
1101+
->fixXmlConfig('serializable_path')
11031102
->children()
11041103
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
11051104
->scalarNode('name_converter')->end()
@@ -1120,6 +1119,29 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e
11201119
->defaultValue([])
11211120
->prototype('variable')->end()
11221121
->end()
1122+
->arrayNode('serializable_paths')
1123+
->info('Defines where to find serializable classes.')
1124+
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
1125+
->prototype('scalar')->end()
1126+
->defaultValue([])
1127+
->end()
1128+
->arrayNode('template_warm_up')
1129+
->addDefaultsIfNotSet()
1130+
->fixXmlConfig('format')
1131+
->children()
1132+
->arrayNode('formats')
1133+
->info('Defines the formats that will be handled.')
1134+
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
1135+
->prototype('scalar')->end()
1136+
->defaultValue(['json'])
1137+
->end()
1138+
->integerNode('max_variants')
1139+
->info('Defines the maximum variants allowed for each class.')
1140+
->defaultValue(32)
1141+
->min(0)
1142+
->end()
1143+
->end()
1144+
->end()
11231145
->end()
11241146
->end()
11251147
->end()
@@ -2494,42 +2516,4 @@ private function addHtmlSanitizerSection(ArrayNodeDefinition $rootNode, callable
24942516
->end()
24952517
;
24962518
}
2497-
2498-
private function addSerDesSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone): void
2499-
{
2500-
$rootNode
2501-
->children()
2502-
->arrayNode('ser_des')
2503-
->info('SerDes configuration')
2504-
->{$enableIfStandalone('symfony/ser-des', SerDesSerializer::class)}()
2505-
->fixXmlConfig('serializable_path')
2506-
->children()
2507-
->arrayNode('serializable_paths')
2508-
->info('Defines where to find serializable classes.')
2509-
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
2510-
->prototype('scalar')->end()
2511-
->defaultValue([])
2512-
->end()
2513-
->arrayNode('template_warm_up')
2514-
->addDefaultsIfNotSet()
2515-
->fixXmlConfig('format')
2516-
->children()
2517-
->arrayNode('formats')
2518-
->info('Defines the formats that will be handled.')
2519-
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
2520-
->prototype('scalar')->end()
2521-
->defaultValue(['json'])
2522-
->end()
2523-
->integerNode('max_variants')
2524-
->info('Defines the maximum variants allowed for each class.')
2525-
->defaultValue(32)
2526-
->min(0)
2527-
->end()
2528-
->end()
2529-
->end()
2530-
->end()
2531-
->end()
2532-
->end()
2533-
;
2534-
}
25352519
}

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

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
use Doctrine\Common\Annotations\Reader;
1616
use Http\Client\HttpAsyncClient;
1717
use Http\Client\HttpClient;
18-
use Symfony\Component\SerDes\Context\ContextBuilderInterface;
19-
use Symfony\Component\SerDes\Context\ContextBuilder\DeserializeContextBuilderInterface;
20-
use Symfony\Component\SerDes\Context\ContextBuilder\SerializeContextBuilderInterface;
21-
use Symfony\Component\SerDes\SerializerInterface as SerDesSerializerInterface;
2218
use phpDocumentor\Reflection\DocBlockFactoryInterface;
2319
use phpDocumentor\Reflection\Types\ContextFactory;
2420
use PhpParser\Parser;
@@ -572,10 +568,6 @@ public function load(array $configs, ContainerBuilder $container)
572568
$this->registerHtmlSanitizerConfiguration($config['html_sanitizer'], $container, $loader);
573569
}
574570

575-
if ($this->readConfigEnabled('ser_des', $container, $config['ser_des'])) {
576-
$this->registerSerDesConfiguration($config['ser_des'], $container, $loader);
577-
}
578-
579571
$this->addAnnotatedClassesToCompile([
580572
'**\\Controller\\',
581573
'**\\Entity\\',
@@ -670,10 +662,6 @@ public function load(array $configs, ContainerBuilder $container)
670662
->addTag('mime.mime_type_guesser');
671663
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
672664
->addMethodCall('setLogger', [new Reference('logger')]);
673-
$container->registerForAutoconfiguration(SerializeContextBuilderInterface::class)
674-
->addTag('ser_des.context_builder.serialize');
675-
$container->registerForAutoconfiguration(DeserializeContextBuilderInterface::class)
676-
->addTag('ser_des.context_builder.deserialize');
677665

678666
$container->registerAttributeForAutoconfiguration(AsEventListener::class, static function (ChildDefinition $definition, AsEventListener $attribute, \ReflectionClass|\ReflectionMethod $reflector) {
679667
$tagAttributes = get_object_vars($attribute);
@@ -1955,6 +1943,18 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
19551943
if (isset($config['default_context']) && $config['default_context']) {
19561944
$container->setParameter('serializer.default_context', $config['default_context']);
19571945
}
1946+
1947+
$container->setParameter('serializer.serializable_paths', $config['serializable_paths']);
1948+
$container->setParameter('serializer.template_warm_up.formats', $config['template_warm_up']['formats']);
1949+
$container->setParameter('serializer.template_warm_up.max_variants', $config['template_warm_up']['max_variants']);
1950+
1951+
foreach ($config['serializable_paths'] as $path) {
1952+
if (!is_dir($path)) {
1953+
continue;
1954+
}
1955+
1956+
$container->fileExists($path, '/\.php$/');
1957+
}
19581958
}
19591959

19601960
private function registerPropertyInfoConfiguration(ContainerBuilder $container, PhpFileLoader $loader): void
@@ -3055,27 +3055,6 @@ private function registerHtmlSanitizerConfiguration(array $config, ContainerBuil
30553055
}
30563056
}
30573057

3058-
private function registerSerDesConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
3059-
{
3060-
if (!interface_exists(SerDesSerializerInterface::class)) {
3061-
throw new LogicException('SerDes serializer support cannot be enabled as the SerDes component is not installed. Try running "composer require symfony/ser-des');
3062-
}
3063-
3064-
$container->setParameter('ser_des.serializable_paths', $config['serializable_paths']);
3065-
$container->setParameter('ser_des.template_warm_up.formats', $config['template_warm_up']['formats']);
3066-
$container->setParameter('ser_des.template_warm_up.max_variants', $config['template_warm_up']['max_variants']);
3067-
3068-
$loader->load('ser_des.php');
3069-
3070-
foreach ($config['serializable_paths'] as $path) {
3071-
if (!is_dir($path)) {
3072-
continue;
3073-
}
3074-
3075-
$container->fileExists($path, '/\.php$/');
3076-
}
3077-
}
3078-
30793058
private function resolveTrustedHeaders(array $headers): int
30803059
{
30813060
$trustedHeaders = 0;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@
8181
->private()
8282
->tag('cache.pool')
8383

84-
->set('cache.ser_des')
85-
->parent('cache.system')
86-
->private()
87-
->tag('cache.pool')
88-
8984
->set('cache.adapter.system', AdapterInterface::class)
9085
->abstract()
9186
->factory([AbstractAdapter::class, 'createSystemCache'])

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
[
3333
'cache.validator',
3434
'cache.serializer',
35-
'cache.ser_des',
3635
],
3736
])
3837
->tag('kernel.cache_warmer', ['priority' => 64])

0 commit comments

Comments
 (0)