added a way to disable forms, and force validation to be enabled when forms are enabled (closes #840)
This commit is contained in:
parent
0687aadad2
commit
a15e846568
24
UPDATE.md
24
UPDATE.md
@ -9,19 +9,27 @@ timeline closely anyway.
|
||||
beta1 to beta2
|
||||
--------------
|
||||
|
||||
* Forms must now be explicitly enabled (automatically done in Symfony SE):
|
||||
|
||||
form: ~
|
||||
|
||||
# equivalent to
|
||||
form:
|
||||
enabled: true
|
||||
|
||||
* The Routing Exceptions have been moved:
|
||||
|
||||
Before:
|
||||
Before:
|
||||
|
||||
Symfony\Component\Routing\Matcher\Exception\Exception
|
||||
Symfony\Component\Routing\Matcher\Exception\NotFoundException
|
||||
Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException
|
||||
Symfony\Component\Routing\Matcher\Exception\Exception
|
||||
Symfony\Component\Routing\Matcher\Exception\NotFoundException
|
||||
Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException
|
||||
|
||||
After:
|
||||
After:
|
||||
|
||||
Symfony\Component\Routing\Exception\Exception
|
||||
Symfony\Component\Routing\Exception\NotFoundException
|
||||
Symfony\Component\Routing\Exception\MethodNotAllowedException
|
||||
Symfony\Component\Routing\Exception\Exception
|
||||
Symfony\Component\Routing\Exception\NotFoundException
|
||||
Symfony\Component\Routing\Exception\MethodNotAllowedException
|
||||
|
||||
* The form component's ``csrf_page_id`` option has been renamed to
|
||||
``intention``.
|
||||
|
@ -46,7 +46,7 @@ class Configuration implements ConfigurationInterface
|
||||
->end()
|
||||
;
|
||||
|
||||
$this->addCsrfProtectionSection($rootNode);
|
||||
$this->addFormSection($rootNode);
|
||||
$this->addEsiSection($rootNode);
|
||||
$this->addProfilerSection($rootNode);
|
||||
$this->addRouterSection($rootNode);
|
||||
@ -58,10 +58,18 @@ class Configuration implements ConfigurationInterface
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
private function addCsrfProtectionSection(ArrayNodeDefinition $rootNode)
|
||||
private function addFormSection(ArrayNodeDefinition $rootNode)
|
||||
{
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('form')
|
||||
->canBeUnset()
|
||||
->treatNullLike(array('enabled' => true))
|
||||
->treatTrueLike(array('enabled' => true))
|
||||
->children()
|
||||
->booleanNode('enabled')->defaultTrue()->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('csrf_protection')
|
||||
->canBeUnset()
|
||||
->treatNullLike(array('enabled' => true))
|
||||
@ -84,7 +92,7 @@ class Configuration implements ConfigurationInterface
|
||||
->treatNullLike(array('enabled' => true))
|
||||
->treatTrueLike(array('enabled' => true))
|
||||
->children()
|
||||
->booleanNode('enabled')->end()
|
||||
->booleanNode('enabled')->defaultTrue()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
@ -228,6 +236,8 @@ class Configuration implements ConfigurationInterface
|
||||
->children()
|
||||
->arrayNode('translator')
|
||||
->canBeUnset()
|
||||
->treatNullLike(array('enabled' => true))
|
||||
->treatTrueLike(array('enabled' => true))
|
||||
->children()
|
||||
->booleanNode('enabled')->defaultTrue()->end()
|
||||
->scalarNode('fallback')->defaultValue('en')->end()
|
||||
@ -243,6 +253,8 @@ class Configuration implements ConfigurationInterface
|
||||
->children()
|
||||
->arrayNode('validation')
|
||||
->canBeUnset()
|
||||
->treatNullLike(array('enabled' => true))
|
||||
->treatTrueLike(array('enabled' => true))
|
||||
// For XML, namespace is a child of validation, so it must be moved under annotations
|
||||
->beforeNormalization()
|
||||
->ifTrue(function($v) { return is_array($v) && !empty($v['annotations']) && !empty($v['namespace']); })
|
||||
@ -253,7 +265,7 @@ class Configuration implements ConfigurationInterface
|
||||
})
|
||||
->end()
|
||||
->children()
|
||||
->booleanNode('enabled')->end()
|
||||
->booleanNode('enabled')->defaultTrue()->end()
|
||||
->scalarNode('cache')->end()
|
||||
->arrayNode('annotations')
|
||||
->canBeUnset()
|
||||
|
@ -69,7 +69,18 @@ class FrameworkExtension extends Extension
|
||||
$loader->load('test.xml');
|
||||
}
|
||||
|
||||
$this->registerFormConfiguration($config, $container, $loader);
|
||||
if (isset($config['session'])) {
|
||||
$this->registerSessionConfiguration($config['session'], $container, $loader);
|
||||
}
|
||||
|
||||
if ($hasForm = isset($config['form']) && !empty($config['form']['enabled'])) {
|
||||
$this->registerFormConfiguration($config, $container, $loader);
|
||||
$config['validation']['enabled'] = true;
|
||||
}
|
||||
|
||||
if (!empty($config['validation']['enabled'])) {
|
||||
$this->registerValidationConfiguration($config['validation'], $container, $loader);
|
||||
}
|
||||
|
||||
if (isset($config['esi'])) {
|
||||
$this->registerEsiConfiguration($config['esi'], $loader);
|
||||
@ -83,10 +94,6 @@ class FrameworkExtension extends Extension
|
||||
$this->registerRouterConfiguration($config['router'], $container, $loader);
|
||||
}
|
||||
|
||||
if (isset($config['session'])) {
|
||||
$this->registerSessionConfiguration($config['session'], $container, $loader);
|
||||
}
|
||||
|
||||
if (isset($config['templating'])) {
|
||||
$this->registerTemplatingConfiguration($config['templating'], $config['ide'], $container, $loader);
|
||||
}
|
||||
@ -95,10 +102,6 @@ class FrameworkExtension extends Extension
|
||||
$this->registerTranslatorConfiguration($config['translator'], $container);
|
||||
}
|
||||
|
||||
if (isset($config['validation'])) {
|
||||
$this->registerValidationConfiguration($config['validation'], $container, $loader);
|
||||
}
|
||||
|
||||
$this->addClassesToCompile(array(
|
||||
'Symfony\\Component\\HttpFoundation\\ParameterBag',
|
||||
'Symfony\\Component\\HttpFoundation\\HeaderBag',
|
||||
@ -151,7 +154,7 @@ class FrameworkExtension extends Extension
|
||||
$container->setParameter('form.type_extension.csrf.field_name', $config['csrf_protection']['field_name']);
|
||||
}
|
||||
|
||||
if (isset($config['session'])) {
|
||||
if ($container->hasDefinition('session')) {
|
||||
$container->removeDefinition('file.temporary_storage');
|
||||
$container->setDefinition('file.temporary_storage', $container->getDefinition('file.temporary_storage.session'));
|
||||
$container->removeDefinition('file.temporary_storage.session');
|
||||
@ -453,10 +456,6 @@ class FrameworkExtension extends Extension
|
||||
*/
|
||||
private function registerValidationConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||
{
|
||||
if (empty($config['enabled'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loader->load('validator.xml');
|
||||
|
||||
$container->setParameter('validator.mapping.loader.xml_files_loader.mapping_files', $this->getValidatorXmlMappingFiles($container));
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
<xsd:complexType name="config">
|
||||
<xsd:all>
|
||||
<xsd:element name="form" type="form" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="csrf-protection" type="csrf_protection" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="esi" type="esi" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="profiler" type="profiler" minOccurs="0" maxOccurs="1" />
|
||||
@ -35,6 +36,10 @@
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:complexType name="form">
|
||||
<xsd:attribute name="enabled" type="xsd:boolean" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="csrf_protection">
|
||||
<xsd:attribute name="enabled" type="xsd:boolean" />
|
||||
<xsd:attribute name="field-name" type="xsd:string" />
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
$container->loadFromExtension('framework', array(
|
||||
'secret' => 's3cr3t',
|
||||
'form' => null,
|
||||
'csrf_protection' => array(
|
||||
'enabled' => true,
|
||||
'field_name' => '_csrf',
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
<framework:config secret="s3cr3t">
|
||||
<framework:csrf-protection enabled="true" field-name="_csrf" />
|
||||
<framework:form />
|
||||
<framework:esi enabled="true" />
|
||||
<framework:profiler only-exceptions="true" />
|
||||
<framework:router cache-warmer="true" resource="%kernel.root_dir%/config/routing.xml" type="xml" />
|
||||
|
@ -1,5 +1,6 @@
|
||||
framework:
|
||||
secret: s3cr3t
|
||||
form: ~
|
||||
csrf_protection:
|
||||
enabled: true
|
||||
field_name: _csrf
|
||||
|
Reference in New Issue
Block a user