diff --git a/UPGRADE-3.1.md b/UPGRADE-3.1.md
index eddac865e8..db3b491c00 100644
--- a/UPGRADE-3.1.md
+++ b/UPGRADE-3.1.md
@@ -19,19 +19,19 @@ Form
* Support for data objects that implements both `Traversable` and `ArrayAccess`
in `ResizeFormListener::preSubmit` method has been deprecated and will be
removed in Symfony 4.0.
-
+
* Using callable strings as choice options in ChoiceType has been deprecated
in favor of `PropertyPath` in Symfony 4.0 use a "\Closure" instead.
-
+
Before:
-
+
```php
'choice_value' => new PropertyPath('range'),
'choice_label' => 'strtoupper',
```
-
+
After:
-
+
```php
'choice_value' => 'range',
'choice_label' => function ($choice) {
@@ -88,6 +88,27 @@ FrameworkBundle
cache service. If you are using `serializer.mapping.cache.apc`, use
`serializer.mapping.cache.doctrine.apc` instead.
+ * The `framework.serializer.cache` option has been deprecated. Configure a cache pool
+ called `serializer` under `framework.cache.pools` instead.
+
+ Before:
+
+ ```yaml
+ framework:
+ serializer:
+ cache: serializer.mapping.cache.apc
+ ```
+
+ After:
+
+ ```yaml
+ framework:
+ serializer: ~
+ cache:
+ pools:
+ serializer:
+ adapter: cache.adapter.apcu
+
HttpKernel
----------
diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md
index 2f965b0cc2..54b6fd19b5 100644
--- a/UPGRADE-4.0.md
+++ b/UPGRADE-4.0.md
@@ -16,26 +16,26 @@ Form
* Support for data objects that implements both `Traversable` and
`ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed.
-
- * Using callable strings as choice options in ChoiceType is not supported
+
+ * Using callable strings as choice options in ChoiceType is not supported
anymore in favor of passing PropertyPath instances.
-
+
Before:
-
+
```php
'choice_value' => new PropertyPath('range'),
'choice_label' => 'strtoupper',
```
-
+
After:
-
+
```php
'choice_value' => 'range',
'choice_label' => function ($choice) {
return strtoupper($choice);
},
```
-
+
FrameworkBundle
---------------
@@ -78,6 +78,28 @@ FrameworkBundle
* The service `serializer.mapping.cache.apc` has been removed; use
`serializer.mapping.cache.doctrine.apc` instead.
+ * The `framework.serializer.cache` option has been removed. Configure a cache pool
+ called `serializer` under `framework.cache.pools` instead.
+
+ Before:
+
+ ```yaml
+ framework:
+ serializer:
+ cache: serializer.mapping.cache.apc
+ ```
+
+ After:
+
+ ```yaml
+ framework:
+ serializer: ~
+ cache:
+ pools:
+ serializer:
+ adapter: cache.adapter.apcu
+ ```
+
HttpKernel
----------
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
index 406ed376b4..7d8bf5f0a0 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -513,7 +513,7 @@ class Configuration implements ConfigurationInterface
->canBeEnabled()
->children()
->booleanNode('enable_annotations')->defaultFalse()->end()
- ->scalarNode('cache')->defaultValue('serializer.mapping.cache.symfony')->end()
+ ->scalarNode('cache')->end()
->scalarNode('name_converter')->end()
->end()
->end()
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
index bc12894339..34de43d07f 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -24,6 +24,7 @@ use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
+use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
@@ -982,7 +983,9 @@ class FrameworkExtension extends Extension
$chainLoader->replaceArgument(0, $serializerLoaders);
- if (!$container->getParameter('kernel.debug')) {
+ if (isset($config['cache']) && $config['cache']) {
+ @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);
+
$container->setParameter(
'serializer.mapping.cache.prefix',
'serializer_'.$this->getKernelRootHash($container)
@@ -991,6 +994,18 @@ class FrameworkExtension extends Extension
$container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument(
1, new Reference($config['cache'])
);
+ } elseif (!$container->getParameter('kernel.debug')) {
+ $cacheMetadataFactory = new Definition(
+ CacheClassMetadataFactory::class,
+ array(
+ new Reference('serializer.mapping.class_metadata_factory.inner'),
+ new Reference('cache.pool.serializer'),
+ )
+ );
+ $cacheMetadataFactory->setPublic(false);
+ $cacheMetadataFactory->setDecoratedService('serializer.mapping.class_metadata_factory');
+
+ $container->setDefinition('serializer.mapping.cache_class_metadata_factory', $cacheMetadataFactory);
}
if (isset($config['name_converter']) && $config['name_converter']) {
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml
index 68db50f927..d5b5093fb6 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml
@@ -38,10 +38,6 @@
-
-
-
-
%serializer.mapping.cache.prefix%
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
index 9ecc2df51d..b41d568c64 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
@@ -221,7 +221,6 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
'serializer' => array(
'enabled' => false,
'enable_annotations' => false,
- 'cache' => 'serializer.mapping.cache.symfony',
),
'property_access' => array(
'magic_call' => false,
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php
index 22d0d49b13..6849f8fbd4 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php
@@ -66,7 +66,6 @@ $container->loadFromExtension('framework', array(
'serializer' => array(
'enabled' => true,
'enable_annotations' => true,
- 'cache' => 'serializer.mapping.cache.doctrine.apc',
'name_converter' => 'serializer.name_converter.camel_case_to_snake_case',
),
'ide' => 'file%%link%%format',
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_legacy_cache.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_legacy_cache.php
new file mode 100644
index 0000000000..65ddd32154
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_legacy_cache.php
@@ -0,0 +1,8 @@
+loadFromExtension('framework', array(
+ 'serializer' => array(
+ 'enabled' => true,
+ 'cache' => 'foo',
+ ),
+));
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
index ae2dce5d5d..e8e34d6e9c 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
@@ -40,6 +40,6 @@
-
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_legacy_cache.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_legacy_cache.xml
new file mode 100644
index 0000000000..237e31e50a
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_legacy_cache.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
index 774e31f487..d345174e8b 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
@@ -52,7 +52,6 @@ framework:
serializer:
enabled: true
enable_annotations: true
- cache: serializer.mapping.cache.doctrine.apc
name_converter: serializer.name_converter.camel_case_to_snake_case
ide: file%%link%%format
request:
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_legacy_cache.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_legacy_cache.yml
new file mode 100644
index 0000000000..5fadc886ab
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_legacy_cache.yml
@@ -0,0 +1,4 @@
+framework:
+ serializer:
+ enabled: true
+ cache: foo
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
index dc89e9948c..6abee616bb 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
@@ -449,7 +449,7 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertCount(1, $argument);
$this->assertEquals('Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader', $argument[0]->getClass());
- $this->assertEquals(new Reference('serializer.mapping.cache.doctrine.apc'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
+ $this->assertNull($container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.normalizer.object')->getArgument(1));
}
@@ -521,6 +521,44 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertEquals(-1000, $tag[0]['priority']);
}
+ public function testSerializerCacheActivated()
+ {
+ $container = $this->createContainerFromFile('serializer_enabled');
+ $this->assertTrue($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
+ }
+
+ public function testSerializerCacheDisabled()
+ {
+ $container = $this->createContainerFromFile('serializer_enabled', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__));
+ $this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
+ }
+
+ /**
+ * @group legacy
+ */
+ public function testDeprecatedSerializerCacheOption()
+ {
+ $deprecations = array();
+ set_error_handler(function ($type, $msg) use (&$deprecations) {
+ if (E_USER_DEPRECATED !== $type) {
+ restore_error_handler();
+
+ return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
+ }
+
+ $deprecations[] = $msg;
+ });
+
+ $container = $this->createContainerFromFile('serializer_legacy_cache', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__));
+
+ restore_error_handler();
+
+ $this->assertCount(1, $deprecations);
+ $this->assertContains('The "framework.serializer.cache" option is deprecated', $deprecations[0]);
+ $this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
+ $this->assertEquals(new Reference('foo'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
+ }
+
public function testAssetHelperWhenAssetsAreEnabled()
{
$container = $this->createContainerFromFile('full');
diff --git a/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php b/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php
index 396aec0a8d..6604430d19 100644
--- a/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php
+++ b/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php
@@ -50,7 +50,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
$this->cache = $cache;
if (null !== $cache) {
- @trigger_error(sprintf('Passing a Doctrine Cache instance as 2nd parameter of the "%s" constructor is deprecated. This parameter will be removed in Symfony 4.0. Use the "%s" class instead.', __CLASS__, CacheClassMetadataFactory::class), E_USER_DEPRECATED);
+ @trigger_error(sprintf('Passing a Doctrine Cache instance as 2nd parameter of the "%s" constructor is deprecated since version 3.1. This parameter will be removed in Symfony 4.0. Use the "%s" class instead.', __CLASS__, CacheClassMetadataFactory::class), E_USER_DEPRECATED);
}
}