[FrameworkBundle] Deprecate framework.serializer.cache
This commit is contained in:
parent
eccbffb435
commit
15579d5137
@ -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
|
||||
----------
|
||||
|
||||
|
@ -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
|
||||
----------
|
||||
|
||||
|
@ -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;
|
||||
@ -983,6 +984,8 @@ class FrameworkExtension extends Extension
|
||||
$chainLoader->replaceArgument(0, $serializerLoaders);
|
||||
|
||||
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']) {
|
||||
|
@ -25,6 +25,10 @@
|
||||
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
|
||||
</service>
|
||||
|
||||
<service id="cache.pool.serializer" parent="cache.adapter.local" public="false">
|
||||
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
|
||||
</service>
|
||||
|
||||
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true">
|
||||
<argument /> <!-- namespace -->
|
||||
<argument /> <!-- default lifetime -->
|
||||
|
@ -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',
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$container->loadFromExtension('framework', array(
|
||||
'serializer' => array(
|
||||
'enabled' => true,
|
||||
'cache' => 'foo',
|
||||
),
|
||||
));
|
@ -40,6 +40,6 @@
|
||||
</framework:translator>
|
||||
<framework:validation enabled="true" cache="validator.mapping.cache.doctrine.apc" />
|
||||
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />
|
||||
<framework:serializer enabled="true" enable-annotations="true" cache="serializer.mapping.cache.doctrine.apc" name-converter="serializer.name_converter.camel_case_to_snake_case" />
|
||||
<framework:serializer enabled="true" enable-annotations="true" name-converter="serializer.name_converter.camel_case_to_snake_case" />
|
||||
</framework:config>
|
||||
</container>
|
||||
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:framework="http://symfony.com/schema/dic/symfony"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
|
||||
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
|
||||
|
||||
<framework:config>
|
||||
<framework:serializer enabled="true" cache="foo"/>
|
||||
</framework:config>
|
||||
</container>
|
@ -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:
|
||||
|
@ -0,0 +1,4 @@
|
||||
framework:
|
||||
serializer:
|
||||
enabled: true
|
||||
cache: foo
|
@ -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');
|
||||
|
Reference in New Issue
Block a user