Skip to content

Commit 129e5d0

Browse files
committed
feature #20097 [FrameworkBundle] removed the Doctrine Annotations lib dependency on FrameworkBundle (fabpot)
This PR was merged into the 3.2-dev branch. Discussion ---------- [FrameworkBundle] removed the Doctrine Annotations lib dependency on FrameworkBundle | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | yes (fixing this is easy by adding doctrine/annotations explicitly) | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15748 partially | License | MIT | Doc PR | n/a Another PR to reduce the number of required dependencies on FrameworkBundle. This PR removes the Doctrine annotations library from the list. Commits ------- c2d8356 [FrameworkBundle] removed the Doctrine Annotations lib dependency on FrameworkBundle
2 parents 214b865 + 154463f commit 129e5d0

File tree

7 files changed

+25
-4
lines changed

7 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
3.2.0
55
-----
66

7+
* Removed `doctrine/annotations` from the list of required dependencies in `composer.json`
78
* Removed `symfony/security-core` and `symfony/security-csrf` from the list of required dependencies in `composer.json`
89
* Removed `symfony/templating` from the list of required dependencies in `composer.json`
910
* Removed `symfony/translation` from the list of required dependencies in `composer.json`

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ private function addAnnotationsSection(ArrayNodeDefinition $rootNode)
593593
->children()
594594
->arrayNode('annotations')
595595
->info('annotation configuration')
596-
->addDefaultsIfNotSet()
596+
->canBeDisabled()
597597
->children()
598598
->scalarNode('cache')->defaultValue('php_array')->end()
599599
->scalarNode('file_cache_dir')->defaultValue('%kernel.cache_dir%/annotations')->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class FrameworkExtension extends Extension
4848
private $formConfigEnabled = false;
4949
private $translationConfigEnabled = false;
5050
private $sessionConfigEnabled = false;
51+
private $annotationsConfigEnabled = false;
5152

5253
/**
5354
* @var string|null
@@ -79,6 +80,8 @@ public function load(array $configs, ContainerBuilder $container)
7980
$configuration = $this->getConfiguration($configs, $container);
8081
$config = $this->processConfiguration($configuration, $configs);
8182

83+
$this->annotationsConfigEnabled = $this->isConfigEnabled($container, $config['annotations']);
84+
8285
// A translator must always be registered (as support is included by
8386
// default in the Form component). If disabled, an identity translator
8487
// will be used and everything will still work as expected.
@@ -892,6 +895,10 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
892895
$definition->replaceArgument(0, $config['strict_email']);
893896

894897
if (array_key_exists('enable_annotations', $config) && $config['enable_annotations']) {
898+
if (!$this->annotationsConfigEnabled) {
899+
throw new \LogicException('"enable_annotations" on the validator cannot be set as Annotations support is disabled.');
900+
}
901+
895902
$validatorBuilder->addMethodCall('enableAnnotationMapping', array(new Reference('annotation_reader')));
896903
}
897904

@@ -957,6 +964,14 @@ private function getValidatorMappingFiles(ContainerBuilder $container)
957964

958965
private function registerAnnotationsConfiguration(array $config, ContainerBuilder $container, $loader)
959966
{
967+
if (!$this->annotationsConfigEnabled) {
968+
return;
969+
}
970+
971+
if (!class_exists('Doctrine\Common\Annotations\Annotation')) {
972+
throw new LogicException('Annotations cannot be enabled as the Doctrine Annotation library is not installed.');
973+
}
974+
960975
$loader->load('annotations.xml');
961976

962977
if ('none' !== $config['cache']) {
@@ -1081,6 +1096,10 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
10811096

10821097
$serializerLoaders = array();
10831098
if (isset($config['enable_annotations']) && $config['enable_annotations']) {
1099+
if (!$this->annotationsConfigEnabled) {
1100+
throw new \LogicException('"enable_annotations" on the serializer cannot be set as Annotations support is disabled.');
1101+
}
1102+
10841103
$annotationLoader = new Definition(
10851104
'Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader',
10861105
array(new Reference('annotation_reader'))

Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
<xsd:attribute name="cache" type="xsd:string" />
189189
<xsd:attribute name="debug" type="xsd:string" />
190190
<xsd:attribute name="file-cache-dir" type="xsd:string" />
191+
<xsd:attribute name="enabled" type="xsd:boolean" />
191192
</xsd:complexType>
192193

193194
<xsd:complexType name="property_access">

Resources/config/services.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<service id="kernel.class_cache.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\ClassCacheCacheWarmer">
2626
<tag name="kernel.cache_warmer" />
2727
<argument type="collection">
28-
<argument>Doctrine\Common\Annotations\AnnotationRegistry</argument>
2928
<argument>Symfony\Component\HttpFoundation\ParameterBag</argument>
3029
<argument>Symfony\Component\HttpFoundation\HeaderBag</argument>
3130
<argument>Symfony\Component\HttpFoundation\FileBag</argument>

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ protected static function getBundleDefaultConfig()
216216
'cache' => 'php_array',
217217
'file_cache_dir' => '%kernel.cache_dir%/annotations',
218218
'debug' => true,
219+
'enabled' => true,
219220
),
220221
'serializer' => array(
221222
'enabled' => false,

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"symfony/finder": "~2.8|~3.0",
3030
"symfony/routing": "~3.0",
3131
"symfony/stopwatch": "~2.8|~3.0",
32-
"doctrine/cache": "~1.0",
33-
"doctrine/annotations": "~1.0"
32+
"doctrine/cache": "~1.0"
3433
},
3534
"require-dev": {
3635
"symfony/asset": "~2.8|~3.0",
@@ -51,6 +50,7 @@
5150
"symfony/validator": "~3.2",
5251
"symfony/yaml": "~3.2",
5352
"symfony/property-info": "~2.8|~3.0",
53+
"doctrine/annotations": "~1.0",
5454
"phpdocumentor/reflection-docblock": "^3.0",
5555
"twig/twig": "~1.23|~2.0"
5656
},

0 commit comments

Comments
 (0)