Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit54ed443

Browse files
committed
[FrameworkBundle] Allow to disable annotations
1 parentaa73ae9 commit54ed443

File tree

5 files changed

+38
-37
lines changed

5 files changed

+38
-37
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,20 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
489489
privatefunctionaddAnnotationsSection(ArrayNodeDefinition$rootNode)
490490
{
491491
$rootNode
492+
->beforeNormalization()
493+
->always(function ($v) {
494+
if (!isset($v['annotations'])) {
495+
$v['annotations']['enabled'] =true;
496+
@trigger_error('You must explicitly define wheter to enable "framework.annotations" or not. It will be disabled by default in 4.0',E_USER_DEPRECATED);
497+
}
498+
499+
return$v;
500+
})
501+
->end()
492502
->children()
493503
->arrayNode('annotations')
494504
->info('annotation configuration')
495-
->addDefaultsIfNotSet()
505+
->canBeEnabled()
496506
->children()
497507
->scalarNode('cache')->defaultValue('file')->end()
498508
->scalarNode('file_cache_dir')->defaultValue('%kernel.cache_dir%/annotations')->end()

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class FrameworkExtension extends Extension
4242
private$translationConfigEnabled =false;
4343
private$sessionConfigEnabled =false;
4444
private$propertyAccessConfigEnabled =false;
45+
private$annotationsConfigEnabled =false;
4546

4647
/**
4748
* @var string|null
@@ -90,11 +91,16 @@ public function load(array $configs, ContainerBuilder $container)
9091
$this->registerSessionConfiguration($config['session'],$container,$loader);
9192
}
9293

93-
if($this->isConfigEnabled($container,$config['property_access'])) {
94+
if($this->isConfigEnabled($container,$config['property_access'])) {
9495
$this->propertyAccessConfigEnabled =true;
9596
$this->registerPropertyAccessConfiguration($config['property_access'],$container,$loader);
9697
}
9798

99+
if ($this->isConfigEnabled($container,$config['annotations'])) {
100+
$this->annotationsConfigEnabled =true;
101+
$this->registerAnnotationsConfiguration($config['annotations'],$container,$loader);
102+
}
103+
98104
if ($this->isConfigEnabled($container,$config['request'])) {
99105
$this->registerRequestConfiguration($config['request'],$container,$loader);
100106
}
@@ -121,23 +127,23 @@ public function load(array $configs, ContainerBuilder $container)
121127
$this->registerTemplatingConfiguration($config['templating'],$config['ide'],$container,$loader);
122128
}
123129

124-
if($this->isConfigEnabled($container,$config['validation'])) {
130+
if($this->isConfigEnabled($container,$config['validation'])) {
125131
$this->registerValidationConfiguration($config['validation'],$container,$loader);
126132
}
127133

128-
if($this->isConfigEnabled($container,$config['esi'])) {
134+
if($this->isConfigEnabled($container,$config['esi'])) {
129135
$loader->load('esi.xml');
130136
}
131137

132-
if($this->isConfigEnabled($container,$config['ssi'])) {
138+
if($this->isConfigEnabled($container,$config['ssi'])) {
133139
$loader->load('ssi.xml');
134140
}
135141

136-
if($this->isConfigEnabled($container,$config['fragments'])) {
142+
if($this->isConfigEnabled($container,$config['fragments'])) {
137143
$this->registerFragmentsConfiguration($config['fragments'],$container,$loader);
138144
}
139145

140-
if($this->isConfigEnabled($container,$config['translator'])) {
146+
if($this->isConfigEnabled($container,$config['translator'])) {
141147
$this->translationConfigEnabled =true;
142148
$this->registerTranslatorConfiguration($config['translator'],$container);
143149
}
@@ -148,10 +154,8 @@ public function load(array $configs, ContainerBuilder $container)
148154
$this->registerRouterConfiguration($config['router'],$container,$loader);
149155
}
150156

151-
$this->registerAnnotationsConfiguration($config['annotations'],$container,$loader);
152-
153157
if ($this->isConfigEnabled($container,$config['serializer'])) {
154-
$this->registerSerializerConfiguration($config,$container,$loader);
158+
$this->registerSerializerConfiguration($config['serializer'],$container,$loader);
155159
}
156160

157161
if ($this->isConfigEnabled($container,$config['property_info'])) {
@@ -228,7 +232,7 @@ public function getConfiguration(array $config, ContainerBuilder $container)
228232
*/
229233
privatefunctionregisterFormConfiguration($config,ContainerBuilder$container,XmlFileLoader$loader)
230234
{
231-
if(!$this->propertyAccessConfigEnabled) {
235+
if(!$this->propertyAccessConfigEnabled) {
232236
thrownewLogicException('"framework.property_access" must be enabled when "framework.form" is enabled.');
233237
}
234238

@@ -756,7 +760,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
756760
return;
757761
}
758762

759-
if(!$this->propertyAccessConfigEnabled) {
763+
if(!$this->propertyAccessConfigEnabled) {
760764
thrownewLogicException('"framework.property_access" must be enabled when "framework.validator" is enabled.');
761765
}
762766

@@ -779,6 +783,9 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
779783
$definition->replaceArgument(0,$config['strict_email']);
780784

781785
if (array_key_exists('enable_annotations',$config) &&$config['enable_annotations']) {
786+
if (!$this->annotationsConfigEnabled) {
787+
thrownew \LogicException('"framework.annotations" must be enabled when "framework.serializer.enable_annotations" is set to true.');
788+
}
782789
$validatorBuilder->addMethodCall('enableAnnotationMapping',array(newReference('annotation_reader')));
783790
}
784791

@@ -905,12 +912,10 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
905912
*/
906913
privatefunctionregisterSerializerConfiguration(array$config,ContainerBuilder$container,XmlFileLoader$loader)
907914
{
908-
if(!$this->propertyAccessConfigEnabled) {
915+
if(!$this->propertyAccessConfigEnabled) {
909916
thrownewLogicException('"framework.property_access" must be enabled when "framework.serializer" is enabled.');
910917
}
911918

912-
$config =$config['serializer'];
913-
914919
if (class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) {
915920
// Run after serializer.normalizer.object
916921
$definition =$container->register('serializer.normalizer.data_uri', DataUriNormalizer::class);
@@ -937,6 +942,9 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
937942

938943
$serializerLoaders =array();
939944
if (isset($config['enable_annotations']) &&$config['enable_annotations']) {
945+
if (!$this->annotationsConfigEnabled) {
946+
thrownew \LogicException('"framework.annotations" must be enabled when "framework.serializer.enable_annotations" is set to true.');
947+
}
940948
$annotationLoader =newDefinition(
941949
'Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader',
942950
array(newReference('annotation_reader'))

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,10 @@
1616

1717
class ConfigurationTestextends \PHPUnit_Framework_TestCase
1818
{
19-
// @todo remove this in 4.0
20-
private$explicitConfigurationNeeded =array(
21-
'property_access' =>true,
22-
);
23-
2419
publicfunctiontestDefaultConfig()
2520
{
2621
$processor =newProcessor();
27-
$config =$processor->processConfiguration(newConfiguration(true),array(
28-
$this->explicitConfigurationNeeded,
29-
array('secret' =>'s3cr3t'),
30-
));
22+
$config =$processor->processConfiguration(newConfiguration(true),array(array('secret' =>'s3cr3t')));
3123

3224
$this->assertEquals(
3325
array_merge(array('secret' =>'s3cr3t','trusted_hosts' =>array()),self::getBundleDefaultConfig()),
@@ -43,7 +35,7 @@ public function testDoNoDuplicateDefaultFormResources()
4335
));
4436

4537
$processor =newProcessor();
46-
$config =$processor->processConfiguration(newConfiguration(true),array($this->explicitConfigurationNeeded,$input));
38+
$config =$processor->processConfiguration(newConfiguration(true),array($input));
4739

4840
$this->assertEquals(array('FrameworkBundle:Form'),$config['templating']['form']['resources']);
4941
}
@@ -55,7 +47,7 @@ public function testValidTrustedProxies($trustedProxies, $processedProxies)
5547
{
5648
$processor =newProcessor();
5749
$configuration =newConfiguration(true);
58-
$config =$processor->processConfiguration($configuration,array($this->explicitConfigurationNeeded,array(
50+
$config =$processor->processConfiguration($configuration,array(array(
5951
'secret' =>'s3cr3t',
6052
'trusted_proxies' =>$trustedProxies,
6153
)));
@@ -86,7 +78,6 @@ public function testInvalidTypeTrustedProxies()
8678
$processor =newProcessor();
8779
$configuration =newConfiguration(true);
8880
$processor->processConfiguration($configuration,array(
89-
$this->explicitConfigurationNeeded,
9081
array(
9182
'secret' =>'s3cr3t',
9283
'trusted_proxies' =>'Not an IP address',
@@ -103,7 +94,6 @@ public function testInvalidValueTrustedProxies()
10394
$configuration =newConfiguration(true);
10495

10596
$processor->processConfiguration($configuration,array(
106-
$this->explicitConfigurationNeeded,
10797
array(
10898
'secret' =>'s3cr3t',
10999
'trusted_proxies' =>array('Not an IP address'),
@@ -115,7 +105,7 @@ public function testAssetsCanBeEnabled()
115105
{
116106
$processor =newProcessor();
117107
$configuration =newConfiguration(true);
118-
$config =$processor->processConfiguration($configuration,array($this->explicitConfigurationNeeded,array('assets' =>null)));
108+
$config =$processor->processConfiguration($configuration,array(array('assets' =>null)));
119109

120110
$defaultConfig =array(
121111
'enabled' =>true,
@@ -139,7 +129,6 @@ public function testInvalidVersionStrategy()
139129
$processor =newProcessor();
140130
$configuration =newConfiguration(true);
141131
$processor->processConfiguration($configuration,array(
142-
$this->explicitConfigurationNeeded,
143132
array(
144133
'assets' =>array(
145134
'base_urls' =>'//example.com',
@@ -160,7 +149,6 @@ public function testInvalidPackageVersionStrategy()
160149
$configuration =newConfiguration(true);
161150

162151
$processor->processConfiguration($configuration,array(
163-
$this->explicitConfigurationNeeded,
164152
array(
165153
'assets' =>array(
166154
'base_urls' =>'//example.com',
@@ -225,6 +213,7 @@ protected static function getBundleDefaultConfig()
225213
'strict_email' =>false,
226214
),
227215
'annotations' =>array(
216+
'enabled' =>true,
228217
'cache' =>'file',
229218
'file_cache_dir' =>'%kernel.cache_dir%/annotations',
230219
'debug' =>'%kernel.debug%',

‎src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
9090
$loader->load(function ($container) {
9191
$container->loadFromExtension('framework',array(
9292
'secret' =>'$ecret',
93-
94-
// @todo remove this in 4.0
95-
'property_access' =>false,
9693
));
9794
});
9895

‎src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
6262
$loader->load(function ($container) {
6363
$container->loadFromExtension('framework',array(
6464
'secret' =>'$ecret',
65-
66-
// @todo remove this in 4.0
67-
'property_access' =>false,
6865
));
6966
});
7067
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp