Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f44cb14

Browse filesBrowse files
committed
[FrameworkBundle] Deprecate framework.serializer.cache
1 parent eccbffb commit f44cb14
Copy full SHA for f44cb14

File tree

11 files changed

+134
-16
lines changed
Filter options

11 files changed

+134
-16
lines changed

‎UPGRADE-3.1.md

Copy file name to clipboardExpand all lines: UPGRADE-3.1.md
+26-5Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ Form
1919
* Support for data objects that implements both `Traversable` and `ArrayAccess`
2020
in `ResizeFormListener::preSubmit` method has been deprecated and will be
2121
removed in Symfony 4.0.
22-
22+
2323
* Using callable strings as choice options in ChoiceType has been deprecated
2424
in favor of `PropertyPath` in Symfony 4.0 use a "\Closure" instead.
25-
25+
2626
Before:
27-
27+
2828
```php
2929
'choice_value' => new PropertyPath('range'),
3030
'choice_label' => 'strtoupper',
3131
```
32-
32+
3333
After:
34-
34+
3535
```php
3636
'choice_value' => 'range',
3737
'choice_label' => function ($choice) {
@@ -88,6 +88,27 @@ FrameworkBundle
8888
cache service. If you are using `serializer.mapping.cache.apc`, use
8989
`serializer.mapping.cache.doctrine.apc` instead.
9090

91+
* The `framework.serializer.cache` option has been deprecated. Configure a cache pool
92+
called `serializer` under `framework.cache.pools` instead.
93+
94+
Before:
95+
96+
```yaml
97+
framework:
98+
serializer:
99+
cache: serializer.mapping.cache.apc
100+
```
101+
102+
After:
103+
104+
```yaml
105+
framework:
106+
serializer: ~
107+
cache:
108+
pools:
109+
serializer:
110+
adapter: cache.adapter.apcu
111+
91112
HttpKernel
92113
----------
93114

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+29-7Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ Form
1616

1717
* Support for data objects that implements both `Traversable` and
1818
`ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed.
19-
20-
* Using callable strings as choice options in ChoiceType is not supported
19+
20+
* Using callable strings as choice options in ChoiceType is not supported
2121
anymore in favor of passing PropertyPath instances.
22-
22+
2323
Before:
24-
24+
2525
```php
2626
'choice_value' => new PropertyPath('range'),
2727
'choice_label' => 'strtoupper',
2828
```
29-
29+
3030
After:
31-
31+
3232
```php
3333
'choice_value' => 'range',
3434
'choice_label' => function ($choice) {
3535
return strtoupper($choice);
3636
},
3737
```
38-
38+
3939

4040
FrameworkBundle
4141
---------------
@@ -78,6 +78,28 @@ FrameworkBundle
7878
* The service `serializer.mapping.cache.apc` has been removed; use
7979
`serializer.mapping.cache.doctrine.apc` instead.
8080

81+
* The `framework.serializer.cache` option has been removed. Configure a cache pool
82+
called `serializer` under `framework.cache.pools` instead.
83+
84+
Before:
85+
86+
```yaml
87+
framework:
88+
serializer:
89+
cache: serializer.mapping.cache.apc
90+
```
91+
92+
After:
93+
94+
```yaml
95+
framework:
96+
serializer: ~
97+
cache:
98+
pools:
99+
serializer:
100+
adapter: cache.adapter.apcu
101+
```
102+
81103
HttpKernel
82104
----------
83105

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Finder\Finder;
2525
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2626
use Symfony\Component\Config\FileLocator;
27+
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
2728
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
2829
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
2930
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
@@ -983,6 +984,8 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
983984
$chainLoader->replaceArgument(0, $serializerLoaders);
984985

985986
if (isset($config['cache']) && $config['cache']) {
987+
@trigger_error('The "framework.serializer.cache" option is deprecated since Symfony 3.1 and will be removed in 4.0. You can configure a cache pool called "serializer" under "framework.cache.pools" instead.', E_USER_DEPRECATED);
988+
986989
$container->setParameter(
987990
'serializer.mapping.cache.prefix',
988991
'serializer_'.$this->getKernelRootHash($container)
@@ -991,6 +994,18 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
991994
$container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument(
992995
1, new Reference($config['cache'])
993996
);
997+
} elseif (!$container->getParameter('kernel.debug')) {
998+
$cacheMetadataFactory = new Definition(
999+
CacheClassMetadataFactory::class,
1000+
array(
1001+
new Reference('serializer.mapping.class_metadata_factory.inner'),
1002+
new Reference('cache.pool.serializer'),
1003+
)
1004+
);
1005+
$cacheMetadataFactory->setPublic(false);
1006+
$cacheMetadataFactory->setDecoratedService('serializer.mapping.class_metadata_factory');
1007+
1008+
$container->setDefinition('serializer.mapping.cache_class_metadata_factory', $cacheMetadataFactory);
9941009
}
9951010

9961011
if (isset($config['name_converter']) && $config['name_converter']) {

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_pools.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_pools.xml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
2626
</service>
2727

28+
<service id="cache.pool.serializer" parent="cache.adapter.local" public="false">
29+
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
30+
</service>
31+
2832
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true">
2933
<argument /> <!-- namespace -->
3034
<argument /> <!-- default lifetime -->

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
'serializer' => array(
6767
'enabled' => true,
6868
'enable_annotations' => true,
69-
'cache' => 'serializer.mapping.cache.doctrine.apc',
7069
'name_converter' => 'serializer.name_converter.camel_case_to_snake_case',
7170
),
7271
'ide' => 'file%%link%%format',
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'serializer' => array(
5+
'enabled' => true,
6+
'cache' => 'foo',
7+
),
8+
));

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
</framework:translator>
4141
<framework:validation enabled="true" cache="validator.mapping.cache.doctrine.apc" />
4242
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />
43-
<framework:serializer enabled="true" enable-annotations="true" cache="serializer.mapping.cache.doctrine.apc" name-converter="serializer.name_converter.camel_case_to_snake_case" />
43+
<framework:serializer enabled="true" enable-annotations="true" name-converter="serializer.name_converter.camel_case_to_snake_case" />
4444
</framework:config>
4545
</container>
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:serializer enabled="true" cache="foo"/>
10+
</framework:config>
11+
</container>

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ framework:
5252
serializer:
5353
enabled: true
5454
enable_annotations: true
55-
cache: serializer.mapping.cache.doctrine.apc
5655
name_converter: serializer.name_converter.camel_case_to_snake_case
5756
ide: file%%link%%format
5857
request:
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
serializer:
3+
enabled: true
4+
cache: foo

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+36-1Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public function testSerializerEnabled()
449449

450450
$this->assertCount(1, $argument);
451451
$this->assertEquals('Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader', $argument[0]->getClass());
452-
$this->assertEquals(new Reference('serializer.mapping.cache.doctrine.apc'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
452+
$this->assertNull($container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
453453
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.normalizer.object')->getArgument(1));
454454
}
455455

@@ -521,6 +521,41 @@ public function testObjectNormalizerRegistered()
521521
$this->assertEquals(-1000, $tag[0]['priority']);
522522
}
523523

524+
public function testSerializerCacheActivated()
525+
{
526+
$container = $this->createContainerFromFile('serializer_enabled');
527+
$this->assertTrue($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
528+
}
529+
530+
public function testSerializerCacheDisabled()
531+
{
532+
$container = $this->createContainerFromFile('serializer_enabled', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__));
533+
$this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
534+
}
535+
536+
public function testDeprecatedSerializerCacheOption()
537+
{
538+
$deprecations = array();
539+
set_error_handler(function ($type, $msg) use (&$deprecations) {
540+
if (E_USER_DEPRECATED !== $type) {
541+
restore_error_handler();
542+
543+
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
544+
}
545+
546+
$deprecations[] = $msg;
547+
});
548+
549+
$container = $this->createContainerFromFile('serializer_cache', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__));
550+
551+
restore_error_handler();
552+
553+
$this->assertCount(1, $deprecations);
554+
$this->assertContains('The "framework.serializer.cache" option is deprecated', $deprecations[0]);
555+
$this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
556+
$this->assertEquals(new Reference('foo'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
557+
}
558+
524559
public function testAssetHelperWhenAssetsAreEnabled()
525560
{
526561
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.