[FrameworkBundle] changed some default configs from canBeEnabled to canBeDisabled

This commit is contained in:
Fabien Potencier 2017-01-07 08:09:07 -08:00
parent 98ce21a351
commit ef80873d06
5 changed files with 69 additions and 23 deletions

View File

@ -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.

View File

@ -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()

View File

@ -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',

View File

@ -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()

View File

@ -0,0 +1,21 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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
{
}