From ef80873d067e92faa437848625d1e505e386e458 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 7 Jan 2017 08:09:07 -0800 Subject: [PATCH] [FrameworkBundle] changed some default configs from canBeEnabled to canBeDisabled --- .../Bundle/FrameworkBundle/CHANGELOG.md | 3 ++ .../DependencyInjection/Configuration.php | 20 +++++++---- .../DependencyInjection/ConfigurationTest.php | 15 +++++---- .../FrameworkExtensionTest.php | 33 ++++++++++++++----- src/Symfony/Bundle/FullStack.php | 21 ++++++++++++ 5 files changed, 69 insertions(+), 23 deletions(-) create mode 100644 src/Symfony/Bundle/FullStack.php diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 41e1c2453a..cac9d92eda 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -4,6 +4,9 @@ CHANGELOG 3.3.0 ----- + * Changed default configuration for + assets/forms/validation/translation/serialization/csrf from `canBeEnabled()` to + `canBeDisabled()` when Flex is used * The server:* commands and their associated router files were moved to WebServerBundle * Translation related services are not loaded anymore when the `framework.translator` option is disabled. diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 1ee65a0523..960007e25a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -12,9 +12,15 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection; use Doctrine\Common\Annotations\Annotation; +use Symfony\Bundle\FullStack; +use Symfony\Component\Asset\Package; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\Form\Form; +use Symfony\Component\Serializer\Serializer; +use Symfony\Component\Translation\Translator; +use Symfony\Component\Validator\Validation; /** * FrameworkExtension configuration structure. @@ -139,7 +145,7 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('form') ->info('form configuration') - ->canBeEnabled() + ->{!class_exists(FullStack::class) && class_exists(Form::class) ? 'canBeDisabled' : 'canBeEnabled'}() ->children() ->arrayNode('csrf_protection') ->treatFalseLike(array('enabled' => false)) @@ -506,7 +512,7 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('assets') ->info('assets configuration') - ->canBeEnabled() + ->{!class_exists(FullStack::class) && class_exists(Package::class) ? 'canBeDisabled' : 'canBeEnabled'}() ->fixXmlConfig('base_url') ->children() ->scalarNode('version_strategy')->defaultNull()->end() @@ -573,7 +579,7 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('translator') ->info('translator configuration') - ->canBeEnabled() + ->{!class_exists(FullStack::class) && class_exists(Translator::class) ? 'canBeDisabled' : 'canBeEnabled'}() ->fixXmlConfig('fallback') ->fixXmlConfig('path') ->children() @@ -598,10 +604,10 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('validation') ->info('validation configuration') - ->canBeEnabled() + ->{!class_exists(FullStack::class) && class_exists(Validation::class) ? 'canBeDisabled' : 'canBeEnabled'}() ->children() ->scalarNode('cache')->end() - ->booleanNode('enable_annotations')->{class_exists(Annotation::class) ? 'defaultTrue' : 'defaultFalse'}()->end() + ->booleanNode('enable_annotations')->{!class_exists(FullStack::class) && class_exists(Annotation::class) ? 'defaultTrue' : 'defaultFalse'}()->end() ->arrayNode('static_method') ->defaultValue(array('loadValidatorMetadata')) ->prototype('scalar')->end() @@ -642,9 +648,9 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('serializer') ->info('serializer configuration') - ->canBeEnabled() + ->{!class_exists(FullStack::class) && class_exists(Serializer::class) ? 'canBeDisabled' : 'canBeEnabled'}() ->children() - ->booleanNode('enable_annotations')->{class_exists(Annotation::class) ? 'defaultTrue' : 'defaultFalse'}()->end() + ->booleanNode('enable_annotations')->{!class_exists(FullStack::class) && class_exists(Annotation::class) ? 'defaultTrue' : 'defaultFalse'}()->end() ->scalarNode('cache')->end() ->scalarNode('name_converter')->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 2bbc1faf3c..f658e67c6a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration; +use Symfony\Bundle\FullStack; use Symfony\Component\Config\Definition\Processor; class ConfigurationTest extends \PHPUnit_Framework_TestCase @@ -176,7 +177,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'enabled' => false, ), 'form' => array( - 'enabled' => false, + 'enabled' => !class_exists(FullStack::class), 'csrf_protection' => array( 'enabled' => null, // defaults to csrf_protection.enabled 'field_name' => '_token', @@ -200,14 +201,14 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase ), ), 'translator' => array( - 'enabled' => false, + 'enabled' => !class_exists(FullStack::class), 'fallbacks' => array('en'), 'logging' => true, 'paths' => array(), ), 'validation' => array( - 'enabled' => false, - 'enable_annotations' => false, + 'enabled' => !class_exists(FullStack::class), + 'enable_annotations' => !class_exists(FullStack::class), 'static_method' => array('loadValidatorMetadata'), 'translation_domain' => 'validators', 'strict_email' => false, @@ -219,8 +220,8 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'enabled' => true, ), 'serializer' => array( - 'enabled' => false, - 'enable_annotations' => false, + 'enabled' => !class_exists(FullStack::class), + 'enable_annotations' => !class_exists(FullStack::class), ), 'property_access' => array( 'magic_call' => false, @@ -258,7 +259,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'loaders' => array(), ), 'assets' => array( - 'enabled' => false, + 'enabled' => !class_exists(FullStack::class), 'version_strategy' => null, 'version' => null, 'version_format' => '%%s?%%s', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 2da8393962..7254ed34a7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -11,6 +11,8 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection; +use Doctrine\Common\Annotations\Annotation; +use Symfony\Bundle\FullStack; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; use Symfony\Component\Cache\Adapter\ApcuAdapter; @@ -24,6 +26,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\ClosureLoader; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader; use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader; @@ -413,7 +416,9 @@ abstract class FrameworkExtensionTest extends TestCase $calls = $container->getDefinition('validator.builder')->getMethodCalls(); - $this->assertCount(6, $calls); + $annotations = !class_exists(FullStack::class) && class_exists(Annotation::class); + + $this->assertCount($annotations ? 7 : 6, $calls); $this->assertSame('setConstraintValidatorFactory', $calls[0][0]); $this->assertEquals(array(new Reference('validator.validator_factory')), $calls[0][1]); $this->assertSame('setTranslator', $calls[1][0]); @@ -422,10 +427,14 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertSame(array('%validator.translation_domain%'), $calls[2][1]); $this->assertSame('addXmlMappings', $calls[3][0]); $this->assertSame(array($xmlMappings), $calls[3][1]); - $this->assertSame('addMethodMapping', $calls[4][0]); - $this->assertSame(array('loadValidatorMetadata'), $calls[4][1]); - $this->assertSame('setMetadataCache', $calls[5][0]); - $this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[5][1]); + $i = 3; + if ($annotations) { + $this->assertSame('enableAnnotationMapping', $calls[++$i][0]); + } + $this->assertSame('addMethodMapping', $calls[++$i][0]); + $this->assertSame(array('loadValidatorMetadata'), $calls[$i][1]); + $this->assertSame('setMetadataCache', $calls[++$i][0]); + $this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[$i][1]); } public function testValidationService() @@ -536,10 +545,16 @@ abstract class FrameworkExtensionTest extends TestCase $calls = $container->getDefinition('validator.builder')->getMethodCalls(); - $this->assertCount(5, $calls); + $annotations = !class_exists(FullStack::class) && class_exists(Annotation::class); + + $this->assertCount($annotations ? 6 : 5, $calls); $this->assertSame('addXmlMappings', $calls[3][0]); - $this->assertSame('setMetadataCache', $calls[4][0]); - $this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[4][1]); + $i = 3; + if ($annotations) { + $this->assertSame('enableAnnotationMapping', $calls[++$i][0]); + } + $this->assertSame('setMetadataCache', $calls[++$i][0]); + $this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[$i][1]); // no cache, no annotations, no static methods } @@ -572,7 +587,7 @@ abstract class FrameworkExtensionTest extends TestCase public function testSerializerDisabled() { $container = $this->createContainerFromFile('default_config'); - $this->assertFalse($container->has('serializer')); + $this->assertSame(!class_exists(FullStack::class) && class_exists(Serializer::class), $container->has('serializer')); } public function testSerializerEnabled() diff --git a/src/Symfony/Bundle/FullStack.php b/src/Symfony/Bundle/FullStack.php new file mode 100644 index 0000000000..b884a47173 --- /dev/null +++ b/src/Symfony/Bundle/FullStack.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle; + +/** + * A marker to be able to check if symfony/symfony is installed instead of the individual components/bundles. + * + * @internal + */ +final class FullStack +{ +}