Merge remote branch 'bschussek/form-extensions'
* bschussek/form-extensions: [Form] Refactored code from CoreExtension to new ValidatorExtension [Form] Added FormTypeExtensionInterface [Form] Reorganized code into "form extensions"
This commit is contained in:
commit
9a4da005a2
@ -14,7 +14,7 @@ namespace Symfony\Bridge\Doctrine\Form\ChoiceList;
|
||||
use Symfony\Component\Form\Util\PropertyPath;
|
||||
use Symfony\Component\Form\Exception\FormException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ArrayChoiceList;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
|
@ -13,8 +13,8 @@ namespace Symfony\Bridge\Doctrine\Form\DataTransformer;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\DataTransformer\TransformationFailedException;
|
||||
use Symfony\Component\Form\DataTransformer\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
|
@ -12,9 +12,9 @@
|
||||
namespace Symfony\Bridge\Doctrine\Form\DataTransformer;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\DataTransformer\DataTransformerInterface;
|
||||
use Symfony\Component\Form\DataTransformer\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
|
||||
class EntityToIdTransformer implements DataTransformerInterface
|
||||
{
|
||||
|
41
src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php
Normal file
41
src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Doctrine\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractExtension;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
class DoctrineOrmExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* The Doctrine 2 entity manager
|
||||
* @var Doctrine\ORM\EntityManager
|
||||
*/
|
||||
protected $em = null;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function loadTypes()
|
||||
{
|
||||
return array(
|
||||
new Type\EntityType($this->em),
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadTypeGuesser()
|
||||
{
|
||||
return new DoctrineOrmTypeGuesser($this->em);
|
||||
}
|
||||
}
|
@ -3,26 +3,21 @@
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Doctrine\Form\Type\Guesser;
|
||||
namespace Symfony\Bridge\Doctrine\Form;
|
||||
|
||||
use Symfony\Component\Form\FormTypeGuesserInterface;
|
||||
use Symfony\Component\Form\Guess\Guess;
|
||||
use Symfony\Component\Form\Guess\TypeGuess;
|
||||
use Symfony\Component\Form\Guess\ValueGuess;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\Form\Type\Guesser\Guess;
|
||||
use Symfony\Component\Form\Type\Guesser\TypeGuesserInterface;
|
||||
use Symfony\Component\Form\Type\Guesser\TypeGuess;
|
||||
use Symfony\Component\Form\Type\Guesser\ValueGuess;
|
||||
|
||||
/**
|
||||
* Guesses form fields from the metadata of Doctrine 2
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
|
||||
*/
|
||||
class EntityTypeGuesser implements TypeGuesserInterface
|
||||
class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
|
||||
{
|
||||
/**
|
||||
* The Doctrine 2 entity manager
|
||||
@ -30,11 +25,6 @@ class EntityTypeGuesser implements TypeGuesserInterface
|
||||
*/
|
||||
protected $em = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ClassMetadataFactoryInterface $metadataFactory
|
||||
*/
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
@ -190,4 +180,4 @@ class EntityTypeGuesser implements TypeGuesserInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Doctrine\Form;
|
||||
|
||||
use Symfony\Component\Form\Type\Loader\TypeLoaderInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
class DoctrineTypeLoader implements TypeLoaderInterface
|
||||
{
|
||||
private $types;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->types['entity'] = new EntityType($em);
|
||||
}
|
||||
|
||||
public function getType($name)
|
||||
{
|
||||
return $this->types[$name];
|
||||
}
|
||||
|
||||
public function hasType($name)
|
||||
{
|
||||
return isset($this->types[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Doctrine\Form;
|
||||
namespace Symfony\Bridge\Doctrine\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
@ -17,7 +17,7 @@ use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||
use Symfony\Bridge\Doctrine\Form\EventListener\MergeCollectionListener;
|
||||
use Symfony\Bridge\Doctrine\Form\DataTransformer\EntitiesToArrayTransformer;
|
||||
use Symfony\Bridge\Doctrine\Form\DataTransformer\EntityToIdTransformer;
|
||||
use Symfony\Component\Form\Type\AbstractType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
class EntityType extends AbstractType
|
@ -38,7 +38,7 @@
|
||||
<parameter key="doctrine.orm.proxy_cache_warmer.class">Symfony\Bundle\DoctrineBundle\CacheWarmer\ProxyCacheWarmer</parameter>
|
||||
|
||||
<!-- form field factory guesser -->
|
||||
<parameter key="form.guesser.doctrine.class">Symfony\Bridge\Doctrine\Form\Type\Guesser\EntityTypeGuesser</parameter>
|
||||
<parameter key="form.type_guesser.doctrine.class">Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
@ -55,12 +55,12 @@
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
|
||||
<service id="form.guesser.doctrine" class="%form.guesser.doctrine.class%" public="false">
|
||||
<tag name="form.guesser" />
|
||||
<service id="form.type_guesser.doctrine" class="%form.type_guesser.doctrine.class%">
|
||||
<tag name="form.type_guesser" />
|
||||
<argument type="service" id="doctrine.orm.entity_manager" />
|
||||
</service>
|
||||
|
||||
<service id="form.type.entity" class="Symfony\Bridge\Doctrine\Form\EntityType">
|
||||
<service id="form.type.entity" class="Symfony\Bridge\Doctrine\Form\Type\EntityType">
|
||||
<tag name="form.type" alias="entity" />
|
||||
<argument type="service" id="doctrine.orm.entity_manager" />
|
||||
</service>
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Adds all services with the tag "form.guesser" as constructor argument of the
|
||||
* "form.factory" service
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
|
||||
*/
|
||||
class AddFormGuessersPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('form.factory')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$guessers = array();
|
||||
|
||||
foreach ($container->findTaggedServiceIds('form.guesser') as $serviceId => $tag) {
|
||||
$guessers[] = new Reference($serviceId);
|
||||
}
|
||||
|
||||
$container->getDefinition('form.factory')->replaceArgument(1, $guessers);
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
|
||||
/**
|
||||
* Adds all services with the tag "form.type" as argument
|
||||
* to the "form.type.loader" service
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
*/
|
||||
class AddFormTypesPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('form.type.loader')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Builds an array with service IDs as keys and tag aliases as values
|
||||
$types = array();
|
||||
$tags = $container->findTaggedServiceIds('form.type');
|
||||
|
||||
foreach ($tags as $serviceId => $arguments) {
|
||||
$alias = isset($arguments[0]['alias'])
|
||||
? $arguments[0]['alias']
|
||||
: $serviceId;
|
||||
|
||||
// Flip, because we want tag aliases (= type identifiers) as keys
|
||||
$types[$alias] = $serviceId;
|
||||
}
|
||||
|
||||
$container->getDefinition('form.type.loader')->replaceArgument(1, $types);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
|
||||
/**
|
||||
* Adds all services with the tags "form.type" and "form.type_guesser" as
|
||||
* arguments of the "form.extension" service
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
*/
|
||||
class FormPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('form.extension')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Builds an array with service IDs as keys and tag aliases as values
|
||||
$types = array();
|
||||
|
||||
foreach ($container->findTaggedServiceIds('form.type') as $serviceId => $tag) {
|
||||
$alias = isset($tag[0]['alias'])
|
||||
? $tag[0]['alias']
|
||||
: $serviceId;
|
||||
|
||||
// Flip, because we want tag aliases (= type identifiers) as keys
|
||||
$types[$alias] = $serviceId;
|
||||
}
|
||||
|
||||
$container->getDefinition('form.extension')->replaceArgument(1, $types);
|
||||
|
||||
$typeExtensions = array();
|
||||
|
||||
foreach ($container->findTaggedServiceIds('form.type_extension') as $serviceId => $tag) {
|
||||
$alias = isset($tag[0]['alias'])
|
||||
? $tag[0]['alias']
|
||||
: $serviceId;
|
||||
|
||||
if (!isset($typeExtensions[$alias])) {
|
||||
$typeExtensions[$alias] = array();
|
||||
}
|
||||
|
||||
$typeExtensions[$alias][] = $serviceId;
|
||||
}
|
||||
|
||||
$container->getDefinition('form.extension')->replaceArgument(2, $typeExtensions);
|
||||
|
||||
// Find all services annotated with "form.type_guesser"
|
||||
$guessers = array_keys($container->findTaggedServiceIds('form.type_guesser'));
|
||||
|
||||
$container->getDefinition('form.extension')->replaceArgument(3, $guessers);
|
||||
}
|
||||
}
|
@ -11,32 +11,7 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\Type\Loader\TypeLoaderInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
class ContainerAwareTypeLoader implements TypeLoaderInterface
|
||||
{
|
||||
private $container;
|
||||
|
||||
private $serviceIds;
|
||||
|
||||
public function __construct(ContainerInterface $container, array $serviceIds)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->serviceIds = $serviceIds;
|
||||
}
|
||||
|
||||
public function getType($identifier)
|
||||
{
|
||||
if (!isset($this->serviceIds[$identifier])) {
|
||||
throw new \InvalidArgumentException(sprintf('The field type "%s" is not registered with the service container.', $identifier));
|
||||
}
|
||||
|
||||
return $this->container->get($this->serviceIds[$identifier]);
|
||||
}
|
||||
|
||||
public function hasType($identifier)
|
||||
{
|
||||
return isset($this->serviceIds[$identifier]);
|
||||
}
|
||||
}
|
@ -12,8 +12,7 @@
|
||||
namespace Symfony\Bundle\FrameworkBundle;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddFormTypesPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddFormGuessersPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
|
||||
@ -78,8 +77,7 @@ class FrameworkBundle extends Bundle
|
||||
$container->addCompilerPass(new RegisterKernelListenersPass());
|
||||
$container->addCompilerPass(new TemplatingPass());
|
||||
$container->addCompilerPass(new AddConstraintValidatorsPass());
|
||||
$container->addCompilerPass(new AddFormTypesPass());
|
||||
$container->addCompilerPass(new AddFormGuessersPass());
|
||||
$container->addCompilerPass(new FormPass());
|
||||
$container->addCompilerPass(new AddClassesToCachePass());
|
||||
$container->addCompilerPass(new AddClassesToAutoloadMapPass());
|
||||
$container->addCompilerPass(new TranslatorPass());
|
||||
|
@ -5,10 +5,10 @@
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="form.extension.class">Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension</parameter>
|
||||
<parameter key="form.factory.class">Symfony\Component\Form\FormFactory</parameter>
|
||||
<parameter key="form.type.loader.class">Symfony\Bundle\FrameworkBundle\Form\ContainerAwareTypeLoader</parameter>
|
||||
<parameter key="form.guesser.validator.class">Symfony\Component\Form\Type\Guesser\ValidatorTypeGuesser</parameter>
|
||||
<parameter key="form.csrf_provider.class">Symfony\Component\Form\CsrfProvider\SessionCsrfProvider</parameter>
|
||||
<parameter key="form.type_guesser.validator.class">Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser</parameter>
|
||||
<parameter key="form.csrf_provider.class">Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider</parameter>
|
||||
<parameter key="form.csrf_protection.enabled">true</parameter>
|
||||
<parameter key="form.csrf_protection.field_name">_token</parameter>
|
||||
<parameter key="form.csrf_protection.secret">secret</parameter>
|
||||
@ -23,17 +23,39 @@
|
||||
|
||||
<!-- FormFactory -->
|
||||
<service id="form.factory" class="%form.factory.class%">
|
||||
<argument type="service" id="form.type.loader" />
|
||||
<argument type="collection">
|
||||
<!--
|
||||
We don't need to be able to add more extensions.
|
||||
* more types can be registered with the form.type tag
|
||||
* more type_guessers can be registered with the form.type.type_guesser tag
|
||||
-->
|
||||
<argument type="service" id="form.extension" />
|
||||
</argument>
|
||||
</service>
|
||||
|
||||
<!-- DependencyInjectionExtension -->
|
||||
<service id="form.extension" class="%form.extension.class%" public="false">
|
||||
<argument type="service" id="service_container" />
|
||||
<!--
|
||||
All services with tag "form.guesser" are inserted here by
|
||||
AddFormGuessersPass
|
||||
All services with tag "form.type" are inserted here by
|
||||
InitFormsPass
|
||||
-->
|
||||
<argument type="collection" />
|
||||
<!--
|
||||
All services with tag "form.type_extension" are inserted here by
|
||||
InitFormsPass
|
||||
-->
|
||||
<argument type="collection" />
|
||||
<!--
|
||||
All services with tag "form.type_guesser" are inserted here by
|
||||
InitFormsPass
|
||||
-->
|
||||
<argument type="collection" />
|
||||
</service>
|
||||
|
||||
|
||||
<!-- ValidatorTypeGuesser -->
|
||||
<service id="form.guesser.validator" class="%form.guesser.validator.class%" public="false">
|
||||
<tag name="form.guesser" />
|
||||
<service id="form.type_guesser.validator" class="%form.type_guesser.validator.class%">
|
||||
<tag name="form.type_guesser" />
|
||||
<argument type="service" id="validator.mapping.class_metadata_factory" />
|
||||
</service>
|
||||
|
||||
@ -50,102 +72,97 @@
|
||||
<argument>%file.temporary_storage.nesting_levels%</argument>
|
||||
<argument>%file.temporary_storage.directory%</argument>
|
||||
</service>
|
||||
|
||||
<!-- ContainerAwareTypeLoader -->
|
||||
<service id="form.type.loader" class="%form.type.loader.class%">
|
||||
<argument type="service" id="service_container" />
|
||||
<!--
|
||||
All services with tag "form.type" are inserted here by
|
||||
AddFormTypesPass
|
||||
-->
|
||||
<argument type="collection" />
|
||||
</service>
|
||||
|
||||
<!-- FieldTypes -->
|
||||
<service id="form.type.field" class="Symfony\Component\Form\Type\FieldType">
|
||||
|
||||
<!-- CoreExtension -->
|
||||
<service id="form.type.field" class="Symfony\Component\Form\Extension\Core\Type\FieldType">
|
||||
<tag name="form.type" alias="field" />
|
||||
<argument type="service" id="validator" />
|
||||
</service>
|
||||
<service id="form.type.form" class="Symfony\Component\Form\Type\FormType">
|
||||
<service id="form.type.form" class="Symfony\Component\Form\Extension\Core\Type\FormType">
|
||||
<tag name="form.type" alias="form" />
|
||||
</service>
|
||||
<service id="form.type.birthday" class="Symfony\Component\Form\Type\BirthdayType">
|
||||
<service id="form.type.birthday" class="Symfony\Component\Form\Extension\Core\Type\BirthdayType">
|
||||
<tag name="form.type" alias="birthday" />
|
||||
</service>
|
||||
<service id="form.type.checkbox" class="Symfony\Component\Form\Type\CheckboxType">
|
||||
<service id="form.type.checkbox" class="Symfony\Component\Form\Extension\Core\Type\CheckboxType">
|
||||
<tag name="form.type" alias="checkbox" />
|
||||
</service>
|
||||
<service id="form.type.choice" class="Symfony\Component\Form\Type\ChoiceType">
|
||||
<service id="form.type.choice" class="Symfony\Component\Form\Extension\Core\Type\ChoiceType">
|
||||
<tag name="form.type" alias="choice" />
|
||||
</service>
|
||||
<service id="form.type.collection" class="Symfony\Component\Form\Type\CollectionType">
|
||||
<service id="form.type.collection" class="Symfony\Component\Form\Extension\Core\Type\CollectionType">
|
||||
<tag name="form.type" alias="collection" />
|
||||
</service>
|
||||
<service id="form.type.country" class="Symfony\Component\Form\Type\CountryType">
|
||||
<service id="form.type.country" class="Symfony\Component\Form\Extension\Core\Type\CountryType">
|
||||
<tag name="form.type" alias="country" />
|
||||
</service>
|
||||
<service id="form.type.csrf" class="Symfony\Component\Form\Type\CsrfType">
|
||||
<tag name="form.type" alias="csrf" />
|
||||
<argument type="service" id="form.csrf_provider" />
|
||||
</service>
|
||||
<service id="form.type.date" class="Symfony\Component\Form\Type\DateType">
|
||||
<service id="form.type.date" class="Symfony\Component\Form\Extension\Core\Type\DateType">
|
||||
<tag name="form.type" alias="date" />
|
||||
</service>
|
||||
<service id="form.type.datetime" class="Symfony\Component\Form\Type\DateTimeType">
|
||||
<service id="form.type.datetime" class="Symfony\Component\Form\Extension\Core\Type\DateTimeType">
|
||||
<tag name="form.type" alias="datetime" />
|
||||
</service>
|
||||
<service id="form.type.email" class="Symfony\Component\Form\Type\EmailType">
|
||||
<service id="form.type.email" class="Symfony\Component\Form\Extension\Core\Type\EmailType">
|
||||
<tag name="form.type" alias="email" />
|
||||
</service>
|
||||
<service id="form.type.file" class="Symfony\Component\Form\Type\FileType">
|
||||
<service id="form.type.file" class="Symfony\Component\Form\Extension\Core\Type\FileType">
|
||||
<tag name="form.type" alias="file" />
|
||||
<argument type="service" id="file.temporary_storage" />
|
||||
</service>
|
||||
<service id="form.type.hidden" class="Symfony\Component\Form\Type\HiddenType">
|
||||
<service id="form.type.hidden" class="Symfony\Component\Form\Extension\Core\Type\HiddenType">
|
||||
<tag name="form.type" alias="hidden" />
|
||||
</service>
|
||||
<service id="form.type.integer" class="Symfony\Component\Form\Type\IntegerType">
|
||||
<service id="form.type.integer" class="Symfony\Component\Form\Extension\Core\Type\IntegerType">
|
||||
<tag name="form.type" alias="integer" />
|
||||
</service>
|
||||
<service id="form.type.language" class="Symfony\Component\Form\Type\LanguageType">
|
||||
<service id="form.type.language" class="Symfony\Component\Form\Extension\Core\Type\LanguageType">
|
||||
<tag name="form.type" alias="language" />
|
||||
</service>
|
||||
<service id="form.type.locale" class="Symfony\Component\Form\Type\LocaleType">
|
||||
<service id="form.type.locale" class="Symfony\Component\Form\Extension\Core\Type\LocaleType">
|
||||
<tag name="form.type" alias="locale" />
|
||||
</service>
|
||||
<service id="form.type.money" class="Symfony\Component\Form\Type\MoneyType">
|
||||
<service id="form.type.money" class="Symfony\Component\Form\Extension\Core\Type\MoneyType">
|
||||
<tag name="form.type" alias="money" />
|
||||
</service>
|
||||
<service id="form.type.number" class="Symfony\Component\Form\Type\NumberType">
|
||||
<service id="form.type.number" class="Symfony\Component\Form\Extension\Core\Type\NumberType">
|
||||
<tag name="form.type" alias="number" />
|
||||
</service>
|
||||
<service id="form.type.password" class="Symfony\Component\Form\Type\PasswordType">
|
||||
<service id="form.type.password" class="Symfony\Component\Form\Extension\Core\Type\PasswordType">
|
||||
<tag name="form.type" alias="password" />
|
||||
</service>
|
||||
<service id="form.type.percent" class="Symfony\Component\Form\Type\PercentType">
|
||||
<service id="form.type.percent" class="Symfony\Component\Form\Extension\Core\Type\PercentType">
|
||||
<tag name="form.type" alias="percent" />
|
||||
</service>
|
||||
<service id="form.type.radio" class="Symfony\Component\Form\Type\RadioType">
|
||||
<service id="form.type.radio" class="Symfony\Component\Form\Extension\Core\Type\RadioType">
|
||||
<tag name="form.type" alias="radio" />
|
||||
</service>
|
||||
<service id="form.type.repeated" class="Symfony\Component\Form\Type\RepeatedType">
|
||||
<service id="form.type.repeated" class="Symfony\Component\Form\Extension\Core\Type\RepeatedType">
|
||||
<tag name="form.type" alias="repeated" />
|
||||
</service>
|
||||
<service id="form.type.textarea" class="Symfony\Component\Form\Type\TextareaType">
|
||||
<service id="form.type.textarea" class="Symfony\Component\Form\Extension\Core\Type\TextareaType">
|
||||
<tag name="form.type" alias="textarea" />
|
||||
</service>
|
||||
<service id="form.type.text" class="Symfony\Component\Form\Type\TextType">
|
||||
<service id="form.type.text" class="Symfony\Component\Form\Extension\Core\Type\TextType">
|
||||
<tag name="form.type" alias="text" />
|
||||
</service>
|
||||
<service id="form.type.time" class="Symfony\Component\Form\Type\TimeType">
|
||||
<service id="form.type.time" class="Symfony\Component\Form\Extension\Core\Type\TimeType">
|
||||
<tag name="form.type" alias="time" />
|
||||
</service>
|
||||
<service id="form.type.timezone" class="Symfony\Component\Form\Type\TimezoneType">
|
||||
<service id="form.type.timezone" class="Symfony\Component\Form\Extension\Core\Type\TimezoneType">
|
||||
<tag name="form.type" alias="timezone" />
|
||||
</service>
|
||||
<service id="form.type.url" class="Symfony\Component\Form\Type\UrlType">
|
||||
<service id="form.type.url" class="Symfony\Component\Form\Extension\Core\Type\UrlType">
|
||||
<tag name="form.type" alias="url" />
|
||||
</service>
|
||||
|
||||
<!-- CsrfExtension -->
|
||||
<service id="form.type.csrf" class="Symfony\Component\Form\Extension\Csrf\Type\CsrfType">
|
||||
<tag name="form.type" alias="csrf" />
|
||||
<argument type="service" id="form.csrf_provider" />
|
||||
</service>
|
||||
<service id="form.type_extension.csrf" class="Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension">
|
||||
<tag name="form.type_extension" alias="form" />
|
||||
</service>
|
||||
|
||||
</services>
|
||||
</container>
|
||||
|
158
src/Symfony/Component/Form/AbstractExtension.php
Normal file
158
src/Symfony/Component/Form/AbstractExtension.php
Normal file
@ -0,0 +1,158 @@
|
||||
<?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\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Exception\FormException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
|
||||
*/
|
||||
abstract class AbstractExtension implements FormExtensionInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $types;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $typeExtensions;
|
||||
|
||||
/**
|
||||
* @var FormTypeGuesserInterface
|
||||
*/
|
||||
private $typeGuesser;
|
||||
|
||||
/**
|
||||
* @var Boolean
|
||||
*/
|
||||
private $typeGuesserLoaded = false;
|
||||
|
||||
protected function loadTypes()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function loadTypeExtensions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function loadTypeGuesser()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private function initTypes()
|
||||
{
|
||||
$types = $this->loadTypes();
|
||||
$typesByName = array();
|
||||
|
||||
foreach ($types as $type) {
|
||||
if (!$type instanceof FormTypeInterface) {
|
||||
throw new UnexpectedTypeException($type, 'Symfony\Component\Form\FormTypeInterface');
|
||||
}
|
||||
|
||||
$typesByName[$type->getName()] = $type;
|
||||
}
|
||||
|
||||
$this->types = $typesByName;
|
||||
}
|
||||
|
||||
private function initTypeExtensions()
|
||||
{
|
||||
$extensions = $this->loadTypeExtensions();
|
||||
$extensionsByType = array();
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (!$extension instanceof FormTypeExtensionInterface) {
|
||||
throw new UnexpectedTypeException($extension, 'Symfony\Component\Form\FormTypeExtensionInterface');
|
||||
}
|
||||
|
||||
$type = $extension->getExtendedType();
|
||||
|
||||
if (!isset($extensionsByType[$type])) {
|
||||
$extensionsByType[$type] = array();
|
||||
}
|
||||
|
||||
$extensionsByType[$type][] = $extension;
|
||||
}
|
||||
|
||||
$this->typeExtensions = $extensionsByType;
|
||||
}
|
||||
|
||||
private function initTypeGuesser()
|
||||
{
|
||||
$this->typeGuesserLoaded = true;
|
||||
|
||||
$guesser = $this->loadTypeGuesser();
|
||||
|
||||
if (!$guesser instanceof FormTypeGuesserInterface) {
|
||||
throw new UnexpectedTypeException($type, 'Symfony\Component\Form\FormTypeGuesserInterface');
|
||||
}
|
||||
|
||||
$this->guesser = $guesser;
|
||||
}
|
||||
|
||||
public function getType($name)
|
||||
{
|
||||
if (null === $this->types) {
|
||||
$this->initTypes();
|
||||
}
|
||||
|
||||
if (!isset($this->types[$name])) {
|
||||
throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
|
||||
}
|
||||
|
||||
return $this->types[$name];
|
||||
}
|
||||
|
||||
public function hasType($name)
|
||||
{
|
||||
if (null === $this->types) {
|
||||
$this->initTypes();
|
||||
}
|
||||
|
||||
return isset($this->types[$name]);
|
||||
}
|
||||
|
||||
function getTypeExtensions($name)
|
||||
{
|
||||
if (null === $this->typeExtensions) {
|
||||
$this->initTypeExtensions();
|
||||
}
|
||||
|
||||
return isset($this->typeExtensions[$name])
|
||||
? $this->typeExtensions[$name]
|
||||
: array();
|
||||
}
|
||||
|
||||
function hasTypeExtensions($name)
|
||||
{
|
||||
if (null === $this->typeExtensions) {
|
||||
$this->initTypeExtensions();
|
||||
}
|
||||
|
||||
return isset($this->typeExtensions[$name]) && count($this->typeExtensions[$name]) > 0;
|
||||
}
|
||||
|
||||
public function getTypeGuesser()
|
||||
{
|
||||
if (!$this->typeGuesserLoaded) {
|
||||
$this->initTypeGuesser();
|
||||
}
|
||||
|
||||
return $this->typeGuesser;
|
||||
}
|
||||
}
|
@ -9,15 +9,12 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
abstract class AbstractType implements FormTypeInterface
|
||||
{
|
||||
private $extensions = array();
|
||||
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
{
|
||||
}
|
||||
@ -51,4 +48,20 @@ abstract class AbstractType implements FormTypeInterface
|
||||
|
||||
return strtolower($matches[1]);
|
||||
}
|
||||
|
||||
public function setExtensions(array $extensions)
|
||||
{
|
||||
foreach ($extensions as $extension) {
|
||||
if (!$extension instanceof FormTypeExtensionInterface) {
|
||||
throw new UnexpectedTypeException($extension, 'Symfony\Component\Form\FormTypeExtensionInterface');
|
||||
}
|
||||
}
|
||||
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
public function getExtensions()
|
||||
{
|
||||
return $this->extensions;
|
||||
}
|
||||
}
|
32
src/Symfony/Component/Form/AbstractTypeExtension.php
Normal file
32
src/Symfony/Component/Form/AbstractTypeExtension.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
abstract class AbstractTypeExtension implements FormTypeExtensionInterface
|
||||
{
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form)
|
||||
{
|
||||
}
|
||||
|
||||
public function getDefaultOptions(array $options)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
class CallbackTransformer implements DataTransformerInterface
|
||||
{
|
@ -9,9 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Validator;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
class CallbackValidator implements FormValidatorInterface
|
||||
{
|
@ -9,9 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataMapper;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
interface DataMapperInterface
|
||||
{
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
/**
|
||||
* Transforms a value between different representations.
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Exception;
|
||||
|
||||
/**
|
||||
* Indicates a value transformation error.
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\ChoiceList;
|
||||
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
|
||||
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
@ -38,7 +38,7 @@ class ArrayChoiceList implements ChoiceListInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Symfony\Component\Form\ChoiceList\ChoiceListInterface::getChoices
|
||||
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface::getChoices
|
||||
*/
|
||||
protected function load()
|
||||
{
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\ChoiceList;
|
||||
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
|
||||
|
||||
interface ChoiceListInterface
|
||||
{
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\ChoiceList;
|
||||
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
|
||||
|
||||
class MonthChoiceList extends PaddedChoiceList
|
||||
{
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\ChoiceList;
|
||||
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
|
||||
|
||||
class PaddedChoiceList extends ArrayChoiceList
|
||||
{
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\ChoiceList;
|
||||
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
|
||||
|
||||
/**
|
||||
* Represents a choice list where each timezone is broken down by continent.
|
@ -9,21 +9,28 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type\Loader;
|
||||
namespace Symfony\Component\Form\Extension\Core;
|
||||
|
||||
use Symfony\Component\Form\Type;
|
||||
use Symfony\Component\Form\CsrfProvider\CsrfProviderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type;
|
||||
use Symfony\Component\Form\AbstractExtension;
|
||||
use Symfony\Component\Validator\ValidatorInterface;
|
||||
use Symfony\Component\HttpFoundation\File\TemporaryStorage;
|
||||
|
||||
class DefaultTypeLoader extends ArrayTypeLoader
|
||||
class CoreExtension extends AbstractExtension
|
||||
{
|
||||
public function __construct(
|
||||
ValidatorInterface $validator = null,
|
||||
CsrfProviderInterface $csrfProvider = null, TemporaryStorage $storage = null)
|
||||
private $storage;
|
||||
|
||||
private $typeGuesser;
|
||||
|
||||
public function __construct(TemporaryStorage $storage)
|
||||
{
|
||||
$types = array(
|
||||
new Type\FieldType($validator),
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
protected function loadTypes()
|
||||
{
|
||||
return array(
|
||||
new Type\FieldType(),
|
||||
new Type\FormType(),
|
||||
new Type\BirthdayType(),
|
||||
new Type\CheckboxType(),
|
||||
@ -48,17 +55,7 @@ class DefaultTypeLoader extends ArrayTypeLoader
|
||||
new Type\TimeType(),
|
||||
new Type\TimezoneType(),
|
||||
new Type\UrlType(),
|
||||
new Type\FileType($this->storage),
|
||||
);
|
||||
|
||||
if ($csrfProvider) {
|
||||
// TODO Move to a Symfony\Bridge\FormSecurity
|
||||
$types[] = new Type\CsrfType($csrfProvider);
|
||||
}
|
||||
|
||||
if ($storage) {
|
||||
$types[] = new Type\FileType($storage);
|
||||
}
|
||||
|
||||
parent::__construct($types);
|
||||
}
|
||||
}
|
@ -9,9 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataMapper;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataMapper;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\DataMapperInterface;
|
||||
use Symfony\Component\Form\Util\VirtualFormAwareIterator;
|
||||
use Symfony\Component\Form\Exception\FormException;
|
||||
|
@ -9,9 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
class ArrayToBooleanChoicesTransformer implements DataTransformerInterface
|
@ -9,9 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\Util\FormUtil;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
class ArrayToChoicesTransformer implements DataTransformerInterface
|
@ -9,8 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
@ -9,7 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
|
||||
abstract class BaseDateTimeTransformer implements DataTransformerInterface
|
||||
{
|
@ -9,8 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
@ -9,7 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
|
||||
/**
|
||||
* Passes a value through multiple value transformers
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
@ -9,9 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformer\TransformationFailedException;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
@ -9,9 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformer\TransformationFailedException;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
@ -9,9 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
/**
|
||||
* Transforms between an integer and a localized number with grouping
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
@ -9,8 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
@ -9,8 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
@ -9,9 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
class ScalarToBooleanChoicesTransformer implements DataTransformerInterface
|
@ -9,9 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\Util\FormUtil;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
|
||||
class ScalarToChoiceTransformer implements DataTransformerInterface
|
||||
{
|
@ -9,8 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\DataTransformer;
|
||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\EventListener;
|
||||
namespace Symfony\Component\Form\Extension\Core\EventListener;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\Events;
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\EventListener;
|
||||
namespace Symfony\Component\Form\Extension\Core\EventListener;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\Events;
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\EventListener;
|
||||
namespace Symfony\Component\Form\Extension\Core\EventListener;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\Events;
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\EventListener;
|
||||
namespace Symfony\Component\Form\Extension\Core\EventListener;
|
||||
|
||||
use Symfony\Component\Form\Events;
|
||||
use Symfony\Component\Form\Event\DataEvent;
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\EventListener;
|
||||
namespace Symfony\Component\Form\Extension\Core\EventListener;
|
||||
|
||||
use Symfony\Component\Form\Events;
|
||||
use Symfony\Component\Form\Event\FilterDataEvent;
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
|
||||
class BirthdayType extends AbstractType
|
@ -9,11 +9,12 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\DataTransformer\BooleanToStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
|
||||
class CheckboxType extends AbstractType
|
@ -9,19 +9,20 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\Exception\FormException;
|
||||
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\EventListener\FixRadioInputListener;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\DataTransformer\ScalarToChoiceTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\ScalarToBooleanChoicesTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\ArrayToChoicesTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\ArrayToBooleanChoicesTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ScalarToChoiceTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ScalarToBooleanChoicesTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToChoicesTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToBooleanChoicesTransformer;
|
||||
|
||||
class ChoiceType extends AbstractType
|
||||
{
|
||||
@ -32,7 +33,7 @@ class ChoiceType extends AbstractType
|
||||
}
|
||||
|
||||
if ($options['choice_list'] && !$options['choice_list'] instanceof ChoiceListInterface) {
|
||||
throw new FormException('The "choice_list" must be an instance of "Symfony\Component\Form\ChoiceList\ChoiceListInterface".');
|
||||
throw new FormException('The "choice_list" must be an instance of "Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface".');
|
||||
}
|
||||
|
||||
if (!$options['choice_list']) {
|
@ -9,10 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\EventListener\ResizeFormListener;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener;
|
||||
|
||||
class CollectionType extends AbstractType
|
||||
{
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Locale\Locale;
|
||||
|
@ -9,15 +9,16 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\DataTransformer\ReversedTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\DataTransformerChain;
|
||||
use Symfony\Component\Form\DataTransformer\DateTimeToArrayTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\DateTimeToStringTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\DateTimeToTimestampTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\ArrayToPartsTransformer;
|
||||
use Symfony\Component\Form\ReversedTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer;
|
||||
|
||||
class DateTimeType extends AbstractType
|
||||
{
|
@ -9,18 +9,19 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\ChoiceList\PaddedChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\MonthChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\PaddedChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\MonthChoiceList;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\DataTransformer\DateTimeToLocalizedStringTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\DateTimeToArrayTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\DateTimeToStringTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\DateTimeToTimestampTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\ReversedTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
|
||||
use Symfony\Component\Form\ReversedTransformer;
|
||||
|
||||
class DateType extends AbstractType
|
||||
{
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
@ -9,28 +9,21 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Util\PropertyPath;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\EventListener\TrimListener;
|
||||
use Symfony\Component\Form\Validator\DefaultValidator;
|
||||
use Symfony\Component\Form\Validator\DelegatingValidator;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\TrimListener;
|
||||
use Symfony\Component\Form\Extension\Core\Validator\DefaultValidator;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\Validator\ValidatorInterface;
|
||||
|
||||
class FieldType extends AbstractType
|
||||
{
|
||||
private $validator;
|
||||
|
||||
public function __construct(ValidatorInterface $validator)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
{
|
||||
if (null === $options['property_path']) {
|
||||
@ -43,24 +36,17 @@ class FieldType extends AbstractType
|
||||
$options['property_path'] = new PropertyPath($options['property_path']);
|
||||
}
|
||||
|
||||
$options['validation_groups'] = empty($options['validation_groups'])
|
||||
? null
|
||||
: (array)$options['validation_groups'];
|
||||
|
||||
$builder->setRequired($options['required'])
|
||||
->setReadOnly($options['read_only'])
|
||||
->setErrorBubbling($options['error_bubbling'])
|
||||
->setEmptyData($options['empty_data'])
|
||||
->setAttribute('by_reference', $options['by_reference'])
|
||||
->setAttribute('property_path', $options['property_path'])
|
||||
->setAttribute('validation_groups', $options['validation_groups'])
|
||||
->setAttribute('error_mapping', $options['error_mapping'])
|
||||
->setAttribute('max_length', $options['max_length'])
|
||||
->setAttribute('label', $options['label'] ?: $this->humanize($builder->getName()))
|
||||
->setAttribute('validation_constraint', $options['validation_constraint'])
|
||||
->setData($options['data'])
|
||||
->addValidator(new DefaultValidator())
|
||||
->addValidator(new DelegatingValidator($this->validator));
|
||||
->addValidator(new DefaultValidator());
|
||||
|
||||
if ($options['trim']) {
|
||||
$builder->addEventSubscriber(new TrimListener());
|
||||
@ -110,11 +96,9 @@ class FieldType extends AbstractType
|
||||
'max_length' => null,
|
||||
'property_path' => null,
|
||||
'by_reference' => true,
|
||||
'validation_groups' => null,
|
||||
'error_bubbling' => false,
|
||||
'error_mapping' => array(),
|
||||
'label' => null,
|
||||
'validation_constraint' => null,
|
||||
);
|
||||
|
||||
if (!empty($options['data_class'])) {
|
@ -9,16 +9,17 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\EventListener\FixFileUploadListener;
|
||||
use Symfony\Component\Form\DataTransformer\DataTransformerChain;
|
||||
use Symfony\Component\Form\DataTransformer\ReversedTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\FileToStringTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\FileToArrayTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\FixFileUploadListener;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain;
|
||||
use Symfony\Component\Form\ReversedTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\FileToStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\FileToArrayTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\HttpFoundation\File\TemporaryStorage;
|
||||
|
@ -9,13 +9,14 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\CsrfProvider\CsrfProviderInterface;
|
||||
use Symfony\Component\Form\DataMapper\PropertyPathMapper;
|
||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
|
||||
class FormType extends AbstractType
|
||||
@ -24,16 +25,6 @@ class FormType extends AbstractType
|
||||
{
|
||||
$builder->setAttribute('virtual', $options['virtual'])
|
||||
->setDataMapper(new PropertyPathMapper($options['data_class']));
|
||||
|
||||
if ($options['csrf_protection']) {
|
||||
$csrfOptions = array('page_id' => $options['csrf_page_id']);
|
||||
|
||||
if ($options['csrf_provider']) {
|
||||
$csrfOptions['csrf_provider'] = $options['csrf_provider'];
|
||||
}
|
||||
|
||||
$builder->add($options['csrf_field_name'], 'csrf', $csrfOptions);
|
||||
}
|
||||
}
|
||||
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form)
|
||||
@ -53,10 +44,6 @@ class FormType extends AbstractType
|
||||
public function getDefaultOptions(array $options)
|
||||
{
|
||||
$defaultOptions = array(
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_provider' => null,
|
||||
'csrf_page_id' => get_class($this),
|
||||
'virtual' => false,
|
||||
// Errors in forms bubble by default, so that form errors will
|
||||
// end up as global errors in the root form
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
|
||||
class HiddenType extends AbstractType
|
@ -9,10 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\DataTransformer\IntegerToLocalizedStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer;
|
||||
|
||||
class IntegerType extends AbstractType
|
||||
{
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Locale\Locale;
|
||||
|
||||
class LanguageType extends AbstractType
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Locale\Locale;
|
||||
|
||||
class LocaleType extends AbstractType
|
@ -9,11 +9,12 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\DataTransformer\MoneyToLocalizedStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
|
||||
class MoneyType extends AbstractType
|
@ -9,10 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\DataTransformer\NumberToLocalizedStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer;
|
||||
|
||||
class NumberType extends AbstractType
|
||||
{
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormView;
|
@ -9,10 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\DataTransformer\PercentToLocalizedStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer;
|
||||
|
||||
class PercentType extends AbstractType
|
||||
{
|
@ -9,11 +9,12 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\DataTransformer\BooleanToStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
|
||||
class RadioType extends AbstractType
|
@ -9,10 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\DataTransformer\ValueToDuplicatesTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToDuplicatesTransformer;
|
||||
|
||||
class RepeatedType extends AbstractType
|
||||
{
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
@ -9,8 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
|
||||
class TextareaType extends AbstractType
|
@ -9,15 +9,16 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\ChoiceList\PaddedChoiceList;
|
||||
use Symfony\Component\Form\DataTransformer\ReversedTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\DateTimeToStringTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\DateTimeToTimestampTransformer;
|
||||
use Symfony\Component\Form\DataTransformer\DateTimeToArrayTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\PaddedChoiceList;
|
||||
use Symfony\Component\Form\ReversedTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
|
||||
class TimeType extends AbstractType
|
@ -9,10 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\ChoiceList\TimezoneChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\TimezoneChoiceList;
|
||||
|
||||
class TimezoneType extends AbstractType
|
||||
{
|
@ -9,10 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\EventListener\FixUrlProtocolListener;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener;
|
||||
|
||||
class UrlType extends AbstractType
|
||||
{
|
@ -9,9 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Validator;
|
||||
namespace Symfony\Component\Form\Extension\Core\Validator;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormValidatorInterface;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
class DefaultValidator implements FormValidatorInterface
|
40
src/Symfony/Component/Form/Extension/Csrf/CsrfExtension.php
Normal file
40
src/Symfony/Component/Form/Extension/Csrf/CsrfExtension.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Extension\Csrf;
|
||||
|
||||
use Symfony\Component\Form\Extension\Csrf\Type;
|
||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
||||
use Symfony\Component\Form\AbstractExtension;
|
||||
|
||||
class CsrfExtension extends AbstractExtension
|
||||
{
|
||||
private $csrfProvider;
|
||||
|
||||
public function __construct(CsrfProviderInterface $csrfProvider)
|
||||
{
|
||||
$this->csrfProvider = $csrfProvider;
|
||||
}
|
||||
|
||||
protected function loadTypes()
|
||||
{
|
||||
return array(
|
||||
new Type\CsrfType($this->csrfProvider),
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadTypeExtensions()
|
||||
{
|
||||
return array(
|
||||
new Type\FormTypeCsrfExtension(),
|
||||
);
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\CsrfProvider;
|
||||
namespace Symfony\Component\Form\Extension\Csrf\CsrfProvider;
|
||||
|
||||
/**
|
||||
* Marks classes able to provide CSRF protection
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\CsrfProvider;
|
||||
namespace Symfony\Component\Form\Extension\Csrf\CsrfProvider;
|
||||
|
||||
/**
|
||||
* Default implementation of CsrfProviderInterface
|
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\CsrfProvider;
|
||||
namespace Symfony\Component\Form\Extension\Csrf\CsrfProvider;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session;
|
||||
|
@ -9,13 +9,14 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
namespace Symfony\Component\Form\Extension\Csrf\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\CsrfProvider\CsrfProviderInterface;
|
||||
use Symfony\Component\Form\Validator\CallbackValidator;
|
||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
||||
use Symfony\Component\Form\CallbackValidator;
|
||||
|
||||
class CsrfType extends AbstractType
|
||||
{
|
||||
@ -32,16 +33,16 @@ class CsrfType extends AbstractType
|
||||
$pageId = $options['page_id'];
|
||||
|
||||
$builder
|
||||
->setData($csrfProvider->generateCsrfToken($pageId))
|
||||
->addValidator(new CallbackValidator(
|
||||
function (FormInterface $form) use ($csrfProvider, $pageId) {
|
||||
if ((!$form->hasParent() || $form->getParent()->isRoot())
|
||||
&& !$csrfProvider->isCsrfTokenValid($pageId, $form->getData())) {
|
||||
$form->addError(new FormError('The CSRF token is invalid. Please try to resubmit the form'));
|
||||
$form->setData($csrfProvider->generateCsrfToken($pageId));
|
||||
}
|
||||
}
|
||||
));
|
||||
->setData($csrfProvider->generateCsrfToken($pageId))
|
||||
->addValidator(new CallbackValidator(
|
||||
function (FormInterface $form) use ($csrfProvider, $pageId) {
|
||||
if ((!$form->hasParent() || $form->getParent()->isRoot())
|
||||
&& !$csrfProvider->isCsrfTokenValid($pageId, $form->getData())) {
|
||||
$form->addError(new FormError('The CSRF token is invalid. Please try to resubmit the form'));
|
||||
$form->setData($csrfProvider->generateCsrfToken($pageId));
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
public function getDefaultOptions(array $options)
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Extension\Csrf\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
|
||||
class FormTypeCsrfExtension extends AbstractTypeExtension
|
||||
{
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
{
|
||||
if ($options['csrf_protection']) {
|
||||
$csrfOptions = array('page_id' => $options['csrf_page_id']);
|
||||
|
||||
if ($options['csrf_provider']) {
|
||||
$csrfOptions['csrf_provider'] = $options['csrf_provider'];
|
||||
}
|
||||
|
||||
$builder->add($options['csrf_field_name'], 'csrf', $csrfOptions);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDefaultOptions(array $options)
|
||||
{
|
||||
return array(
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_provider' => null,
|
||||
'csrf_page_id' => get_class($this),
|
||||
);
|
||||
}
|
||||
|
||||
public function getExtendedType()
|
||||
{
|
||||
return 'form';
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Extension\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Form\FormExtensionInterface;
|
||||
use Symfony\Component\Form\FormTypeGuesserChain;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
class DependencyInjectionExtension implements FormExtensionInterface
|
||||
{
|
||||
private $container;
|
||||
|
||||
private $typeServiceIds;
|
||||
|
||||
private $guesserServiceIds;
|
||||
|
||||
private $guesser;
|
||||
|
||||
private $guesserLoaded = false;
|
||||
|
||||
public function __construct(ContainerInterface $container,
|
||||
array $typeServiceIds, array $typeExtensionServiceIds,
|
||||
array $guesserServiceIds)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->typeServiceIds = $typeServiceIds;
|
||||
$this->typeExtensionServiceIds = $typeExtensionServiceIds;
|
||||
$this->guesserServiceIds = $guesserServiceIds;
|
||||
}
|
||||
|
||||
public function getType($name)
|
||||
{
|
||||
if (!isset($this->typeServiceIds[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('The field type "%s" is not registered with the service container.', $name));
|
||||
}
|
||||
|
||||
return $this->container->get($this->typeServiceIds[$name]);
|
||||
}
|
||||
|
||||
public function hasType($name)
|
||||
{
|
||||
return isset($this->typeServiceIds[$name]);
|
||||
}
|
||||
|
||||
public function getTypeExtensions($name)
|
||||
{
|
||||
$extensions = array();
|
||||
|
||||
if (isset($this->typeExtensionServiceIds[$name])) {
|
||||
foreach ($this->typeExtensionServiceIds[$name] as $serviceId) {
|
||||
$extensions[] = $this->container->get($serviceId);
|
||||
}
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
|
||||
public function hasTypeExtensions($name)
|
||||
{
|
||||
return isset($this->typeExtensionServiceIds[$name]);
|
||||
}
|
||||
|
||||
public function getTypeGuesser()
|
||||
{
|
||||
if (!$this->guesserLoaded) {
|
||||
$this->guesserLoaded = true;
|
||||
$guessers = array();
|
||||
|
||||
foreach ($this->guesserServiceIds as $serviceId) {
|
||||
$guessers[] = $this->container->get($serviceId);
|
||||
}
|
||||
|
||||
if (count($guessers) > 0) {
|
||||
$this->guesser = new FormTypeGuesserChain($guessers);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->guesser;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Extension\Validator\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\Extension\Validator\Validator\DelegatingValidator;
|
||||
use Symfony\Component\Validator\ValidatorInterface;
|
||||
|
||||
class FieldTypeValidatorExtension extends AbstractTypeExtension
|
||||
{
|
||||
private $validator;
|
||||
|
||||
public function __construct(ValidatorInterface $validator)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
{
|
||||
$options['validation_groups'] = empty($options['validation_groups'])
|
||||
? null
|
||||
: (array)$options['validation_groups'];
|
||||
|
||||
$builder
|
||||
->setAttribute('validation_groups', $options['validation_groups'])
|
||||
->setAttribute('validation_constraint', $options['validation_constraint'])
|
||||
->addValidator(new DelegatingValidator($this->validator));
|
||||
}
|
||||
|
||||
public function getDefaultOptions(array $options)
|
||||
{
|
||||
return array(
|
||||
'validation_groups' => null,
|
||||
'validation_constraint' => null,
|
||||
);
|
||||
}
|
||||
|
||||
public function getExtendedType()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
}
|
@ -9,9 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Validator;
|
||||
namespace Symfony\Component\Form\Extension\Validator\Validator;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormValidatorInterface;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\Util\VirtualFormAwareIterator;
|
||||
use Symfony\Component\Form\Exception\FormException;
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Extension\Validator;
|
||||
|
||||
use Symfony\Component\Form\Extension\Validator\Type;
|
||||
use Symfony\Component\Form\AbstractExtension;
|
||||
use Symfony\Component\Validator\ValidatorInterface;
|
||||
|
||||
class ValidatorExtension extends AbstractExtension
|
||||
{
|
||||
private $validator;
|
||||
|
||||
public function __construct(ValidatorInterface $validator)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
protected function loadTypeExtensions()
|
||||
{
|
||||
return array(
|
||||
new Type\FieldTypeValidatorExtension($this->validator),
|
||||
);
|
||||
}
|
||||
|
||||
public function loadTypeGuesser()
|
||||
{
|
||||
return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
|
||||
}
|
||||
}
|
@ -3,29 +3,24 @@
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type\Guesser;
|
||||
namespace Symfony\Component\Form\Extension\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Form\FormTypeGuesserInterface;
|
||||
use Symfony\Component\Form\Guess\Guess;
|
||||
use Symfony\Component\Form\Guess\TypeGuess;
|
||||
use Symfony\Component\Form\Guess\ValueGuess;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface;
|
||||
|
||||
/**
|
||||
* Guesses form fields from the metadata of the a Validator class
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
|
||||
*/
|
||||
class ValidatorTypeGuesser implements TypeGuesserInterface
|
||||
class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ClassMetadataFactoryInterface $metadataFactory
|
||||
*/
|
||||
private $metadataFactory;
|
||||
|
||||
public function __construct(ClassMetadataFactoryInterface $metadataFactory)
|
||||
{
|
||||
$this->metadataFactory = $metadataFactory;
|
||||
@ -301,4 +296,4 @@ class ValidatorTypeGuesser implements TypeGuesserInterface
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,8 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\FileBag;
|
||||
use Symfony\Component\Form\Event\DataEvent;
|
||||
use Symfony\Component\Form\Event\FilterDataEvent;
|
||||
use Symfony\Component\Form\Exception\FormException;
|
||||
@ -21,12 +19,9 @@ use Symfony\Component\Form\Exception\AlreadyBoundException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\Exception\DanglingFieldException;
|
||||
use Symfony\Component\Form\Exception\FieldDefinitionException;
|
||||
use Symfony\Component\Form\CsrfProvider\CsrfProviderInterface;
|
||||
use Symfony\Component\Form\DataTransformer\DataTransformerInterface;
|
||||
use Symfony\Component\Form\DataTransformer\TransformationFailedException;
|
||||
use Symfony\Component\Form\DataMapper\DataMapperInterface;
|
||||
use Symfony\Component\Form\Validator\FormValidatorInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\FileBag;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
@ -213,19 +208,19 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
{
|
||||
foreach ($clientTransformers as $transformer) {
|
||||
if (!$transformer instanceof DataTransformerInterface) {
|
||||
throw new UnexpectedTypeException($transformer, 'Symfony\Component\Form\DataTransformer\DataTransformerInterface');
|
||||
throw new UnexpectedTypeException($transformer, 'Symfony\Component\Form\DataTransformerInterface');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($normTransformers as $transformer) {
|
||||
if (!$transformer instanceof DataTransformerInterface) {
|
||||
throw new UnexpectedTypeException($transformer, 'Symfony\Component\Form\DataTransformer\DataTransformerInterface');
|
||||
throw new UnexpectedTypeException($transformer, 'Symfony\Component\Form\DataTransformerInterface');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($validators as $validator) {
|
||||
if (!$validator instanceof FormValidatorInterface) {
|
||||
throw new UnexpectedTypeException($validator, 'Symfony\Component\Form\Validator\FormValidatorInterface');
|
||||
throw new UnexpectedTypeException($validator, 'Symfony\Component\Form\FormValidatorInterface');
|
||||
}
|
||||
}
|
||||
|
||||
@ -849,6 +844,10 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
|
||||
foreach ($types as $type) {
|
||||
$type->buildView($view, $this);
|
||||
|
||||
foreach ($type->getExtensions() as $typeExtension) {
|
||||
$typeExtension->buildView($view, $this);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->children as $key => $child) {
|
||||
@ -859,6 +858,10 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
|
||||
foreach ($types as $type) {
|
||||
$type->buildViewBottomUp($view, $this);
|
||||
|
||||
foreach ($type->getExtensions() as $typeExtension) {
|
||||
$typeExtension->buildViewBottomUp($view, $this);
|
||||
}
|
||||
}
|
||||
|
||||
return $view;
|
||||
|
@ -11,12 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\DataMapper\DataMapperInterface;
|
||||
use Symfony\Component\Form\DataTransformer\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Validator\FormValidatorInterface;
|
||||
use Symfony\Component\Form\Exception\FormException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\Type\FormTypeInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
@ -350,7 +346,7 @@ class FormBuilder
|
||||
}
|
||||
|
||||
if (null !== $type && !is_string($type) && !$type instanceof FormTypeInterface) {
|
||||
throw new UnexpectedTypeException($type, 'string or Symfony\Component\Form\Type\FormTypeInterface');
|
||||
throw new UnexpectedTypeException($type, 'string or Symfony\Component\Form\FormTypeInterface');
|
||||
}
|
||||
|
||||
$this->children[$name] = array(
|
||||
|
@ -3,17 +3,23 @@
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* (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\Component\Form\Type\Loader;
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
interface TypeLoaderInterface
|
||||
interface FormExtensionInterface
|
||||
{
|
||||
function getType($name);
|
||||
|
||||
function hasType($name);
|
||||
}
|
||||
|
||||
function getTypeExtensions($name);
|
||||
|
||||
function hasTypeExtensions($name);
|
||||
|
||||
function getTypeGuesser();
|
||||
}
|
@ -11,28 +11,83 @@
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Type\FormTypeInterface;
|
||||
use Symfony\Component\Form\Type\Loader\TypeLoaderInterface;
|
||||
use Symfony\Component\Form\Type\Guesser\TypeGuesserInterface;
|
||||
use Symfony\Component\Form\Type\Guesser\Guess;
|
||||
use Symfony\Component\Form\Guess\TypeGuesserInterface;
|
||||
use Symfony\Component\Form\Guess\Guess;
|
||||
use Symfony\Component\Form\Exception\FormException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
class FormFactory implements FormFactoryInterface
|
||||
{
|
||||
private $typeLoader;
|
||||
private $extensions = array();
|
||||
|
||||
private $guessers = array();
|
||||
private $types = array();
|
||||
|
||||
public function __construct(TypeLoaderInterface $typeLoader, array $guessers = array())
|
||||
private $guesser;
|
||||
|
||||
public function __construct(array $extensions)
|
||||
{
|
||||
foreach ($guessers as $guesser) {
|
||||
if (!$guesser instanceof TypeGuesserInterface) {
|
||||
throw new UnexpectedTypeException($guesser, 'Symfony\Component\Form\Type\Guesser\TypeGuesserInterface');
|
||||
foreach ($extensions as $extension) {
|
||||
if (!$extension instanceof FormExtensionInterface) {
|
||||
throw new UnexpectedTypeException($extension, 'Symfony\Component\Form\FormExtensionInterface');
|
||||
}
|
||||
}
|
||||
$this->typeLoader = $typeLoader;
|
||||
$this->guessers = $guessers;
|
||||
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
private function loadGuesser()
|
||||
{
|
||||
$guessers = array();
|
||||
|
||||
foreach ($this->extensions as $extension) {
|
||||
$guesser = $extension->getTypeGuesser();
|
||||
|
||||
if ($guesser) {
|
||||
$guessers[] = $guesser;
|
||||
}
|
||||
}
|
||||
|
||||
$this->guesser = new FormTypeGuesserChain($guessers);
|
||||
}
|
||||
|
||||
public function getType($name)
|
||||
{
|
||||
$type = null;
|
||||
|
||||
if ($name instanceof FormTypeInterface) {
|
||||
$type = $name;
|
||||
$name = $type->getName();
|
||||
}
|
||||
|
||||
if (!isset($this->types[$name])) {
|
||||
if (!$type) {
|
||||
foreach ($this->extensions as $extension) {
|
||||
if ($extension->hasType($name)) {
|
||||
$type = $extension->getType($name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$type) {
|
||||
throw new FormException(sprintf('Could not load type "%s"', $name));
|
||||
}
|
||||
}
|
||||
|
||||
$typeExtensions = array();
|
||||
|
||||
foreach ($this->extensions as $extension) {
|
||||
$typeExtensions = array_merge(
|
||||
$typeExtensions,
|
||||
$extension->getTypeExtensions($name)
|
||||
);
|
||||
}
|
||||
|
||||
$type->setExtensions($typeExtensions);
|
||||
|
||||
$this->types[$name] = $type;
|
||||
}
|
||||
|
||||
return $this->types[$name];
|
||||
}
|
||||
|
||||
public function create($type, $data = null, array $options = array())
|
||||
@ -64,19 +119,22 @@ class FormFactory implements FormFactoryInterface
|
||||
{
|
||||
$builder = null;
|
||||
$types = array();
|
||||
$typeExtensions = array();
|
||||
$knownOptions = array();
|
||||
$passedOptions = array_keys($options);
|
||||
|
||||
while (null !== $type) {
|
||||
// TODO check if type exists
|
||||
if (!$type instanceof FormTypeInterface) {
|
||||
$type = $this->typeLoader->getType($type);
|
||||
$type = $this->getType($type);
|
||||
|
||||
$defaultOptions = $type->getDefaultOptions($options);
|
||||
|
||||
foreach ($type->getExtensions() as $typeExtension) {
|
||||
$defaultOptions = array_merge($defaultOptions, $typeExtension->getDefaultOptions($options));
|
||||
}
|
||||
|
||||
array_unshift($types, $type);
|
||||
$defaultOptions = $type->getDefaultOptions($options);
|
||||
$options = array_merge($defaultOptions, $options);
|
||||
$knownOptions = array_merge($knownOptions, array_keys($defaultOptions));
|
||||
array_unshift($types, $type);
|
||||
$type = $type->getParent($options);
|
||||
}
|
||||
|
||||
@ -96,6 +154,10 @@ class FormFactory implements FormFactoryInterface
|
||||
|
||||
foreach ($types as $type) {
|
||||
$type->buildForm($builder, $options);
|
||||
|
||||
foreach ($type->getExtensions() as $typeExtension) {
|
||||
$typeExtension->buildForm($builder, $options);
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $data) {
|
||||
@ -107,22 +169,14 @@ class FormFactory implements FormFactoryInterface
|
||||
|
||||
public function createBuilderForProperty($class, $property, $data = null, array $options = array())
|
||||
{
|
||||
// guess field class and options
|
||||
$typeGuess = $this->guess(function ($guesser) use ($class, $property) {
|
||||
return $guesser->guessType($class, $property);
|
||||
});
|
||||
if (!$this->guesser) {
|
||||
$this->loadGuesser();
|
||||
}
|
||||
|
||||
// guess maximum length
|
||||
$maxLengthGuess = $this->guess(function ($guesser) use ($class, $property) {
|
||||
return $guesser->guessMaxLength($class, $property);
|
||||
});
|
||||
$typeGuess = $this->guesser->guessType($class, $property);
|
||||
$maxLengthGuess = $this->guesser->guessMaxLength($class, $property);
|
||||
$requiredGuess = $this->guesser->guessRequired($class, $property);
|
||||
|
||||
// guess whether field is required
|
||||
$requiredGuess = $this->guess(function ($guesser) use ($class, $property) {
|
||||
return $guesser->guessRequired($class, $property);
|
||||
});
|
||||
|
||||
// construct field
|
||||
$type = $typeGuess ? $typeGuess->getType() : 'text';
|
||||
|
||||
if ($maxLengthGuess) {
|
||||
@ -140,26 +194,4 @@ class FormFactory implements FormFactoryInterface
|
||||
|
||||
return $this->createNamedBuilder($type, $property, $data, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a closure for each guesser and returns the best guess from the
|
||||
* return values
|
||||
*
|
||||
* @param \Closure $closure The closure to execute. Accepts a guesser as
|
||||
* argument and should return a FieldFactoryGuess
|
||||
* instance
|
||||
* @return FieldFactoryGuess The guess with the highest confidence
|
||||
*/
|
||||
protected function guess(\Closure $closure)
|
||||
{
|
||||
$guesses = array();
|
||||
|
||||
foreach ($this->guessers as $guesser) {
|
||||
if ($guess = $closure($guesser)) {
|
||||
$guesses[] = $guess;
|
||||
}
|
||||
}
|
||||
|
||||
return Guess::getBestGuess($guesses);
|
||||
}
|
||||
}
|
||||
|
25
src/Symfony/Component/Form/FormTypeExtensionInterface.php
Normal file
25
src/Symfony/Component/Form/FormTypeExtensionInterface.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
interface FormTypeExtensionInterface
|
||||
{
|
||||
function buildForm(FormBuilder $builder, array $options);
|
||||
|
||||
function buildView(FormView $view, FormInterface $form);
|
||||
|
||||
function buildViewBottomUp(FormView $view, FormInterface $form);
|
||||
|
||||
function getDefaultOptions(array $options);
|
||||
|
||||
function getExtendedType();
|
||||
}
|
76
src/Symfony/Component/Form/FormTypeGuesserChain.php
Normal file
76
src/Symfony/Component/Form/FormTypeGuesserChain.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Guess\Guess;
|
||||
|
||||
class FormTypeGuesserChain implements FormTypeGuesserInterface
|
||||
{
|
||||
private $guessers = array();
|
||||
|
||||
public function __construct(array $guessers)
|
||||
{
|
||||
foreach ($guessers as $guesser) {
|
||||
if (!$guesser instanceof FormTypeGuesserInterface) {
|
||||
throw new UnexpectedTypeException($guesser, 'Symfony\Component\Form\FormTypeGuesserInterface');
|
||||
}
|
||||
|
||||
if ($guesser instanceof self) {
|
||||
$this->guessers = array_merge($this->guessers, $guesser->guessers);
|
||||
} else {
|
||||
$this->guessers[] = $guesser;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function guessType($class, $property)
|
||||
{
|
||||
return $this->guess(function ($guesser) use ($class, $property) {
|
||||
return $guesser->guessType($class, $property);
|
||||
});
|
||||
}
|
||||
|
||||
public function guessRequired($class, $property)
|
||||
{
|
||||
return $this->guess(function ($guesser) use ($class, $property) {
|
||||
return $guesser->guessRequired($class, $property);
|
||||
});
|
||||
}
|
||||
|
||||
public function guessMaxLength($class, $property)
|
||||
{
|
||||
return $this->guess(function ($guesser) use ($class, $property) {
|
||||
return $guesser->guessMaxLength($class, $property);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a closure for each guesser and returns the best guess from the
|
||||
* return values
|
||||
*
|
||||
* @param \Closure $closure The closure to execute. Accepts a guesser
|
||||
* as argument and should return a Guess instance
|
||||
* @return FieldFactoryGuess The guess with the highest confidence
|
||||
*/
|
||||
private function guess(\Closure $closure)
|
||||
{
|
||||
$guesses = array();
|
||||
|
||||
foreach ($this->guessers as $guesser) {
|
||||
if ($guess = $closure($guesser)) {
|
||||
$guesses[] = $guess;
|
||||
}
|
||||
}
|
||||
|
||||
return Guess::getBestGuess($guesses);
|
||||
}
|
||||
}
|
@ -3,20 +3,15 @@
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type\Guesser;
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
/**
|
||||
* Guesses field classes and options for the properties of a class
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
|
||||
*/
|
||||
interface TypeGuesserInterface
|
||||
interface FormTypeGuesserInterface
|
||||
{
|
||||
/**
|
||||
* Returns a field guess for a property name of a class
|
||||
@ -44,4 +39,4 @@ interface TypeGuesserInterface
|
||||
* @return Guess A guess for the field's maximum length
|
||||
*/
|
||||
function guessMaxLength($class, $property);
|
||||
}
|
||||
}
|
@ -9,12 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
interface FormTypeInterface
|
||||
{
|
||||
@ -31,4 +26,8 @@ interface FormTypeInterface
|
||||
function getParent(array $options);
|
||||
|
||||
function getName();
|
||||
|
||||
function setExtensions(array $extensions);
|
||||
|
||||
function getExtensions();
|
||||
}
|
@ -9,9 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Validator;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
interface FormValidatorInterface
|
||||
{
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user