Skip to content

[FrameworkBundle] Smarter default for framework.annotations #20749

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

Merged
merged 1 commit into from
Dec 14, 2016
Merged

[FrameworkBundle] Smarter default for framework.annotations #20749

merged 1 commit into from
Dec 14, 2016

Conversation

ogizanagi
Copy link
Contributor

Q A
Branch? 3.2
Bug fix? yesish (could be considered as a minor BC break)
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR N/A

framework.annotations default should be true only if doctrine/annotations is installed.

Indeed, in #20097, the dependency on doctrine/annotations was removed from the framework bundle.
Thus, an application can break (not talking from one actually relying on annotations) as soon as it uses the framework bundle without the framework.annotations key explicitly set to false (I had the case in a fixture application in the testsuite of a package).

@@ -604,6 +604,7 @@ private function addAnnotationsSection(ArrayNodeDefinition $rootNode)
->info('annotation configuration')
->canBeDisabled()
->children()
->booleanNode('enabled')->defaultValue(class_exists('Doctrine\Common\Annotations\Annotation'))->end()
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 use Annotation::class here.

@dunglas
Copy link
Member

dunglas commented Dec 5, 2016

👍 (travis error not related)

@nicolas-grekas nicolas-grekas added this to the 3.2 milestone Dec 6, 2016
@@ -604,6 +605,7 @@ private function addAnnotationsSection(ArrayNodeDefinition $rootNode)
->info('annotation configuration')
->canBeDisabled()
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 removed I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I can't because I still need the logic inside canBeDisabled but I'm simply overriding the boolean node and its default value.

However, if it seems less "hacky", I can replace the fix by:

diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
index 4b9af8c..4a7dfa2 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -603,9 +603,8 @@ class Configuration implements ConfigurationInterface
             ->children()
                 ->arrayNode('annotations')
                     ->info('annotation configuration')
-                    ->canBeDisabled()
+                    ->{class_exists(Annotation::class) ? 'canBeDisabled' : 'canBeEnabled'}()
                     ->children()
-                        ->booleanNode('enabled')->defaultValue(class_exists(Annotation::class))->end()
                         ->scalarNode('cache')->defaultValue('php_array')->end()
                         ->scalarNode('file_cache_dir')->defaultValue('%kernel.cache_dir%/annotations')->end()
                         ->booleanNode('debug')->defaultValue($this->debug)->end()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hum...The two codes slightly differ. With the patch above:

    annotations:
        cache: php_array

will properly enable annotations whereas the current implementation doesn't (which is wrong).

So I'll apply the patch.

@chalasr
Copy link
Member

chalasr commented Dec 7, 2016

👍 Upgrading was hard for me too on LexikJWTAuthenticationBundle which requires the framework in 2.8+ and don't make use of annotations at all, tests was broken on 3.2.

Symfony\Component\DependencyInjection\Exception\LogicException: Annotations cannot be enabled as the Doctrine Annotation library is not installed

Status: reviewed

@ogizanagi
Copy link
Contributor Author

@fabpot What do you think about this one?

It'll be great to have it for 3.2.2 IMHO.

@stof
Copy link
Member

stof commented Dec 13, 2016

this indeed makes sense

@fabpot
Copy link
Member

fabpot commented Dec 14, 2016

Thank you @ogizanagi.

@fabpot fabpot merged commit e38be09 into symfony:3.2 Dec 14, 2016
fabpot added a commit that referenced this pull request Dec 14, 2016
…s (ogizanagi)

This PR was merged into the 3.2 branch.

Discussion
----------

[FrameworkBundle] Smarter default for framework.annotations

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yesish (could be considered as a minor BC break)
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

`framework.annotations` default should be true only if `doctrine/annotations` is installed.

Indeed, in #20097, the dependency on `doctrine/annotations` was removed from the framework bundle.
Thus, an application can break (not talking from one actually relying on annotations) as soon as it uses the framework bundle without the `framework.annotations` key explicitly set to `false` (I had the case in a fixture application in the testsuite of a package).

Commits
-------

e38be09 [FrameworkBundle] framework.annotations default should be true only if doctrine/annotations is installed
@ogizanagi ogizanagi deleted the fix/fwk_bundle/annotation_defaults branch December 14, 2016 08:15
@fabpot fabpot mentioned this pull request Jan 12, 2017
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.

7 participants