Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FrameworkBundle][Serializer] Fix a deprecation triggered by the ClassMetadataFactory #18630

Merged
merged 3 commits into from
Apr 27, 2016

Conversation

GuilhemN
Copy link
Contributor

@GuilhemN GuilhemN commented Apr 24, 2016

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets
License MIT

Without apparent reasons, FOSRestBundle's tests fail since #18561.

Passing a Doctrine Cache instance as 2nd parameter of the "Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory" constructor is deprecated. This parameter will be removed in Symfony 4.0. Use the "Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory" class instead: 6x
    1x in ErrorWithTemplatingFormatTest::testSerializeExceptionHtml from FOS\RestBundle\Tests\Functional
    1x in SerializerErrorTest::testSerializeExceptionJson from FOS\RestBundle\Tests\Functional
    1x in SerializerErrorTest::testSerializeExceptionJsonWithoutDebug from FOS\RestBundle\Tests\Functional
    1x in SerializerErrorTest::testSerializeExceptionXml from FOS\RestBundle\Tests\Functional
    1x in SerializerErrorTest::testSerializeInvalidFormJson from FOS\RestBundle\Tests\Functional
    1x in SerializerErrorTest::testSerializeInvalidFormXml from FOS\RestBundle\Tests\Functional

We don't use cache in our tests but some of them are not in debug mode (will change soon) so the cache is automatically used.

This PR fixes this deprecation by detecting if the cache used by the serializer is psr6 compliant or not (if it is, then it replaces the default metadata factory by an instance of the new class CacheClassMetadataFactory, otherwise the second parameter of the ClassMetadataFactory is used).

@GuilhemN
Copy link
Contributor Author

The tests failure seems unrelated.

@@ -513,7 +513,7 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode)
->canBeEnabled()
->children()
->booleanNode('enable_annotations')->defaultFalse()->end()
->scalarNode('cache')->defaultValue('serializer.mapping.cache.symfony')->end()
->scalarNode('cache')->defaultValue('cache.pool.serializer')->end()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a BC break to me, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is merged in 3.1 where it was introduced, then I think it isn't.

@javiereguiluz
Copy link
Member

@Ener-Getick please, don't remove any of the rows of the PR table. In your table we miss the Branch row, which is were you propose where to merge this. If you are not sure, it's OK to say so. Thanks!

@GuilhemN
Copy link
Contributor Author

@javiereguiluz I thought it was enough to target the right branch, added ☺

{
public function process(ContainerBuilder $container)
{
if (!$container->hasAlias('serializer.mapping.cache') && !$container->hasDefinition('serializer.mapping.cache')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use $container->has('serializer.mapping.cache').

@xabbuh
Copy link
Member

xabbuh commented Apr 25, 2016

Can't we always use the CacheClassMetadataFactory when the cache is configured and optionally wrap a Doctrine cache instance in a DoctrineAdapter?

@nicolas-grekas
Copy link
Member

Understood, this is for 3.1 :)
Then I have a few suggestions:

  • change the deprecation message to add the version: ...constructor is deprecated since version 3.1....
  • replace the compiler pass by a deprecation of the cache configuration key and a few wiring in the DI extension.

@nicolas-grekas
Copy link
Member

If we don't want to deprecate the cache configuration key, then I'd suggest doing what @xabbuh suggests, and do it at runtime using a static method as factory added to CacheClassMetadataFactory, tagged @internal

@xabbuh
Copy link
Member

xabbuh commented Apr 25, 2016

I agree with @nicolas-grekas. Now that we have the cache.pool.serializer pool we do not need the cache config option for the serializer anymore. People can now configure the cache through the semantic config of the cache subsystem.

@GuilhemN
Copy link
Contributor Author

GuilhemN commented Apr 25, 2016

@nicolas-grekas @xabbuh then the default value introduced in #18561 should be removed right ?

@GuilhemN GuilhemN changed the title [Serializer] Fix a deprecation triggered by the ClassMetadataFactory [FrameworkBundle][Serializer] Fix a deprecation triggered by the ClassMetadataFactory Apr 25, 2016
@nicolas-grekas
Copy link
Member

Yep, can you do that in this PR, as a first commit?

@GuilhemN
Copy link
Contributor Author

@nicolas-grekas yes, I'm gonna split my commit

@@ -982,7 +982,9 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder

$chainLoader->replaceArgument(0, $serializerLoaders);

if (!$container->getParameter('kernel.debug')) {
if (isset($config['cache']) && $config['cache']) {
@trigger_error('Using the option "framework.serializer.cache" is deprecated since version 3.1. This option will be removed in 4.0. You can configure a cache pool called "serializer" under "framework.cache" instead.', E_USER_DEPRECATED);
Copy link
Member

@nicolas-grekas nicolas-grekas Apr 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@GuilhemN GuilhemN force-pushed the SERIALIZER branch 2 times, most recently from 205f808 to 0d7ecc7 Compare April 25, 2016 17:25
@GuilhemN GuilhemN force-pushed the SERIALIZER branch 5 times, most recently from 60d94c6 to f44cb14 Compare April 25, 2016 17:51
@GuilhemN
Copy link
Contributor Author

GuilhemN commented Apr 25, 2016

Rebased and updated.

I also added notes in the upgrading files to inform about this new deprecation.

$this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
}

public function testDeprecatedSerializerCacheOption()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be tagged @group legacy so that we don't forget removing it when preparing 4.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,8 @@
<?php

$container->loadFromExtension('framework', array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding the "legacy" word in these fixtures so we can easily find them when preparing 4.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean in the filename

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍, renamed to serializer_legacy_cache

@nicolas-grekas
Copy link
Member

👍 with only one wonder: should the UPGRADE files tell about the serializer pool, and/or tell about cache.pool.local, which is the centralized way of configuring e.g. APCu for all internal adapters at once?

@GuilhemN
Copy link
Contributor Author

I didn't think about cache.pool.local, this is indeed probably better to use it.
And in case the user wants something more specific, we can add a link to the documentation (which doesn't exist yet).


```yaml
framework:
serializer: ~
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this level should be removed, cache is a direct child of framework

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it should not be removed. If you remove the serializer key entirely, it disables the serializer in FrameworkBundle

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas
Copy link
Member

Thank you @Ener-Getick.

@nicolas-grekas nicolas-grekas merged commit 15579d5 into symfony:master Apr 27, 2016
nicolas-grekas added a commit that referenced this pull request Apr 27, 2016
…by the ClassMetadataFactory (Ener-Getick)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[FrameworkBundle][Serializer] Fix a deprecation triggered by the ClassMetadataFactory

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT

Without apparent reasons, [FOSRestBundle's tests fail](https://travis-ci.org/FriendsOfSymfony/FOSRestBundle/jobs/124384888) since #18561.
```
Passing a Doctrine Cache instance as 2nd parameter of the "Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory" constructor is deprecated. This parameter will be removed in Symfony 4.0. Use the "Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory" class instead: 6x
    1x in ErrorWithTemplatingFormatTest::testSerializeExceptionHtml from FOS\RestBundle\Tests\Functional
    1x in SerializerErrorTest::testSerializeExceptionJson from FOS\RestBundle\Tests\Functional
    1x in SerializerErrorTest::testSerializeExceptionJsonWithoutDebug from FOS\RestBundle\Tests\Functional
    1x in SerializerErrorTest::testSerializeExceptionXml from FOS\RestBundle\Tests\Functional
    1x in SerializerErrorTest::testSerializeInvalidFormJson from FOS\RestBundle\Tests\Functional
    1x in SerializerErrorTest::testSerializeInvalidFormXml from FOS\RestBundle\Tests\Functional
```
We don't use cache in our tests but some of them are not in ``debug`` mode (will change soon) so the cache is automatically used.

This PR fixes this deprecation by detecting if the cache used by the serializer is psr6 compliant or not (if it is, then it replaces the default metadata factory by an instance of the new class ``CacheClassMetadataFactory``, otherwise the second parameter of the ``ClassMetadataFactory`` is used).

Commits
-------

15579d5 [FrameworkBundle] Deprecate framework.serializer.cache
eccbffb [Serializer] Improve a deprecation message
96e418a Revert "[FrameworkBundle] Fallback to default cache system in production for serializer"
@GuilhemN GuilhemN deleted the SERIALIZER branch April 27, 2016 12:52
fabpot added a commit that referenced this pull request Apr 28, 2016
… regressions (Ener-Getick)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[FrameworkBundle] Fix a typo and add a test to prevent new regressions

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

This fixes a typo introduced in #18630 and adds a new functional test to avoid most regressions in service definitions in the future when features are only available in non-debug mode.

cc @nicolas-grekas

Commits
-------

61872ce Fix a typo and add a check to prevent regressions
fabpot added a commit to symfony/symfony-standard that referenced this pull request May 9, 2016
…r-Getick)

This PR was merged into the 3.1-dev branch.

Discussion
----------

Do not use validator.cache and serializer.cache anymore

``framework.serializer.cache`` has been deprecated in symfony/symfony#18630 in favor of the new caching system.

see symfony/symfony#18630

Commits
-------

e7a2085 Use the new cache system configuration
@fabpot fabpot mentioned this pull request May 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants