Skip to content

Commit ef80873

Browse files
committed
[FrameworkBundle] changed some default configs from canBeEnabled to canBeDisabled
1 parent 98ce21a commit ef80873

File tree

5 files changed

+69
-23
lines changed

5 files changed

+69
-23
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ CHANGELOG
44
3.3.0
55
-----
66

7+
* Changed default configuration for
8+
assets/forms/validation/translation/serialization/csrf from `canBeEnabled()` to
9+
`canBeDisabled()` when Flex is used
710
* The server:* commands and their associated router files were moved to WebServerBundle
811
* Translation related services are not loaded anymore when the `framework.translator` option
912
is disabled.

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
1313

1414
use Doctrine\Common\Annotations\Annotation;
15+
use Symfony\Bundle\FullStack;
16+
use Symfony\Component\Asset\Package;
1517
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1618
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1719
use Symfony\Component\Config\Definition\ConfigurationInterface;
20+
use Symfony\Component\Form\Form;
21+
use Symfony\Component\Serializer\Serializer;
22+
use Symfony\Component\Translation\Translator;
23+
use Symfony\Component\Validator\Validation;
1824

1925
/**
2026
* FrameworkExtension configuration structure.
@@ -139,7 +145,7 @@ private function addFormSection(ArrayNodeDefinition $rootNode)
139145
->children()
140146
->arrayNode('form')
141147
->info('form configuration')
142-
->canBeEnabled()
148+
->{!class_exists(FullStack::class) && class_exists(Form::class) ? 'canBeDisabled' : 'canBeEnabled'}()
143149
->children()
144150
->arrayNode('csrf_protection')
145151
->treatFalseLike(array('enabled' => false))
@@ -506,7 +512,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
506512
->children()
507513
->arrayNode('assets')
508514
->info('assets configuration')
509-
->canBeEnabled()
515+
->{!class_exists(FullStack::class) && class_exists(Package::class) ? 'canBeDisabled' : 'canBeEnabled'}()
510516
->fixXmlConfig('base_url')
511517
->children()
512518
->scalarNode('version_strategy')->defaultNull()->end()
@@ -573,7 +579,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
573579
->children()
574580
->arrayNode('translator')
575581
->info('translator configuration')
576-
->canBeEnabled()
582+
->{!class_exists(FullStack::class) && class_exists(Translator::class) ? 'canBeDisabled' : 'canBeEnabled'}()
577583
->fixXmlConfig('fallback')
578584
->fixXmlConfig('path')
579585
->children()
@@ -598,10 +604,10 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
598604
->children()
599605
->arrayNode('validation')
600606
->info('validation configuration')
601-
->canBeEnabled()
607+
->{!class_exists(FullStack::class) && class_exists(Validation::class) ? 'canBeDisabled' : 'canBeEnabled'}()
602608
->children()
603609
->scalarNode('cache')->end()
604-
->booleanNode('enable_annotations')->{class_exists(Annotation::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
610+
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) && class_exists(Annotation::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
605611
->arrayNode('static_method')
606612
->defaultValue(array('loadValidatorMetadata'))
607613
->prototype('scalar')->end()
@@ -642,9 +648,9 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode)
642648
->children()
643649
->arrayNode('serializer')
644650
->info('serializer configuration')
645-
->canBeEnabled()
651+
->{!class_exists(FullStack::class) && class_exists(Serializer::class) ? 'canBeDisabled' : 'canBeEnabled'}()
646652
->children()
647-
->booleanNode('enable_annotations')->{class_exists(Annotation::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
653+
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) && class_exists(Annotation::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
648654
->scalarNode('cache')->end()
649655
->scalarNode('name_converter')->end()
650656
->end()

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
1313

1414
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
15+
use Symfony\Bundle\FullStack;
1516
use Symfony\Component\Config\Definition\Processor;
1617

1718
class ConfigurationTest extends \PHPUnit_Framework_TestCase
@@ -176,7 +177,7 @@ protected static function getBundleDefaultConfig()
176177
'enabled' => false,
177178
),
178179
'form' => array(
179-
'enabled' => false,
180+
'enabled' => !class_exists(FullStack::class),
180181
'csrf_protection' => array(
181182
'enabled' => null, // defaults to csrf_protection.enabled
182183
'field_name' => '_token',
@@ -200,14 +201,14 @@ protected static function getBundleDefaultConfig()
200201
),
201202
),
202203
'translator' => array(
203-
'enabled' => false,
204+
'enabled' => !class_exists(FullStack::class),
204205
'fallbacks' => array('en'),
205206
'logging' => true,
206207
'paths' => array(),
207208
),
208209
'validation' => array(
209-
'enabled' => false,
210-
'enable_annotations' => false,
210+
'enabled' => !class_exists(FullStack::class),
211+
'enable_annotations' => !class_exists(FullStack::class),
211212
'static_method' => array('loadValidatorMetadata'),
212213
'translation_domain' => 'validators',
213214
'strict_email' => false,
@@ -219,8 +220,8 @@ protected static function getBundleDefaultConfig()
219220
'enabled' => true,
220221
),
221222
'serializer' => array(
222-
'enabled' => false,
223-
'enable_annotations' => false,
223+
'enabled' => !class_exists(FullStack::class),
224+
'enable_annotations' => !class_exists(FullStack::class),
224225
),
225226
'property_access' => array(
226227
'magic_call' => false,
@@ -258,7 +259,7 @@ protected static function getBundleDefaultConfig()
258259
'loaders' => array(),
259260
),
260261
'assets' => array(
261-
'enabled' => false,
262+
'enabled' => !class_exists(FullStack::class),
262263
'version_strategy' => null,
263264
'version' => null,
264265
'version_format' => '%%s?%%s',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
1313

14+
use Doctrine\Common\Annotations\Annotation;
15+
use Symfony\Bundle\FullStack;
1416
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1517
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
1618
use Symfony\Component\Cache\Adapter\ApcuAdapter;
@@ -24,6 +26,7 @@
2426
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
2527
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2628
use Symfony\Component\DependencyInjection\Reference;
29+
use Symfony\Component\Serializer\Serializer;
2730
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
2831
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
2932
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
@@ -413,7 +416,9 @@ public function testValidation()
413416

414417
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
415418

416-
$this->assertCount(6, $calls);
419+
$annotations = !class_exists(FullStack::class) && class_exists(Annotation::class);
420+
421+
$this->assertCount($annotations ? 7 : 6, $calls);
417422
$this->assertSame('setConstraintValidatorFactory', $calls[0][0]);
418423
$this->assertEquals(array(new Reference('validator.validator_factory')), $calls[0][1]);
419424
$this->assertSame('setTranslator', $calls[1][0]);
@@ -422,10 +427,14 @@ public function testValidation()
422427
$this->assertSame(array('%validator.translation_domain%'), $calls[2][1]);
423428
$this->assertSame('addXmlMappings', $calls[3][0]);
424429
$this->assertSame(array($xmlMappings), $calls[3][1]);
425-
$this->assertSame('addMethodMapping', $calls[4][0]);
426-
$this->assertSame(array('loadValidatorMetadata'), $calls[4][1]);
427-
$this->assertSame('setMetadataCache', $calls[5][0]);
428-
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[5][1]);
430+
$i = 3;
431+
if ($annotations) {
432+
$this->assertSame('enableAnnotationMapping', $calls[++$i][0]);
433+
}
434+
$this->assertSame('addMethodMapping', $calls[++$i][0]);
435+
$this->assertSame(array('loadValidatorMetadata'), $calls[$i][1]);
436+
$this->assertSame('setMetadataCache', $calls[++$i][0]);
437+
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[$i][1]);
429438
}
430439

431440
public function testValidationService()
@@ -536,10 +545,16 @@ public function testValidationNoStaticMethod()
536545

537546
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
538547

539-
$this->assertCount(5, $calls);
548+
$annotations = !class_exists(FullStack::class) && class_exists(Annotation::class);
549+
550+
$this->assertCount($annotations ? 6 : 5, $calls);
540551
$this->assertSame('addXmlMappings', $calls[3][0]);
541-
$this->assertSame('setMetadataCache', $calls[4][0]);
542-
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[4][1]);
552+
$i = 3;
553+
if ($annotations) {
554+
$this->assertSame('enableAnnotationMapping', $calls[++$i][0]);
555+
}
556+
$this->assertSame('setMetadataCache', $calls[++$i][0]);
557+
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[$i][1]);
543558
// no cache, no annotations, no static methods
544559
}
545560

@@ -572,7 +587,7 @@ public function testStopwatchEnabledWithDebugModeDisabled()
572587
public function testSerializerDisabled()
573588
{
574589
$container = $this->createContainerFromFile('default_config');
575-
$this->assertFalse($container->has('serializer'));
590+
$this->assertSame(!class_exists(FullStack::class) && class_exists(Serializer::class), $container->has('serializer'));
576591
}
577592

578593
public function testSerializerEnabled()

src/Symfony/Bundle/FullStack.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle;
13+
14+
/**
15+
* A marker to be able to check if symfony/symfony is installed instead of the individual components/bundles.
16+
*
17+
* @internal
18+
*/
19+
final class FullStack
20+
{
21+
}

0 commit comments

Comments
 (0)