diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml
index ea1795455f..5e3d2674a2 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml
@@ -14,7 +14,7 @@
Symfony\Bundle\FrameworkBundle\Templating\Helper\SessionHelper
Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper
Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper
- Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper
+ Symfony\Component\Form\Extension\Templating\FormHelper
Symfony\Component\Form\Extension\Templating\TemplatingRendererEngine
Symfony\Component\Form\FormRenderer
Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables
diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md
index 1e3a60fad3..d8c4589db2 100644
--- a/src/Symfony/Component/Form/CHANGELOG.md
+++ b/src/Symfony/Component/Form/CHANGELOG.md
@@ -177,3 +177,4 @@ CHANGELOG
* made FormView properties public and deprecated their accessor methods
* made the normalized data of a form accessible in the template through the variable "form.vars.data"
* made the original data of a choice accessible in the template through the property "choice.data"
+ * added convenience class Forms and FormFactoryBuilderInterface
diff --git a/src/Symfony/Component/Form/Extension/Csrf/CsrfExtension.php b/src/Symfony/Component/Form/Extension/Csrf/CsrfExtension.php
index 71d06381ad..fabc492f02 100644
--- a/src/Symfony/Component/Form/Extension/Csrf/CsrfExtension.php
+++ b/src/Symfony/Component/Form/Extension/Csrf/CsrfExtension.php
@@ -27,7 +27,7 @@ class CsrfExtension extends AbstractExtension
*
* @param CsrfProviderInterface $csrfProvider The CSRF provider
*/
- public function __construct(CsrfProviderInterface $csrfProvider)
+ public function __construct(CsrfProviderInterface $csrfProvider = null)
{
$this->csrfProvider = $csrfProvider;
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Component/Form/Extension/Templating/FormHelper.php
similarity index 99%
rename from src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php
rename to src/Symfony/Component/Form/Extension/Templating/FormHelper.php
index e271bc56c3..59d57986d3 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php
+++ b/src/Symfony/Component/Form/Extension/Templating/FormHelper.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
+namespace Symfony\Component\Form\Extension\Templating;
use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\Form\FormRendererInterface;
diff --git a/src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php b/src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php
index 4abd9b45f8..3a70b6215e 100644
--- a/src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php
+++ b/src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php
@@ -17,6 +17,11 @@ use Symfony\Component\Form\AbstractExtension;
use Symfony\Component\Validator\ValidatorInterface;
use Symfony\Component\Validator\Constraints\Valid;
+/**
+ * Extension supporting the Symfony2 Validator component in forms.
+ *
+ * @author Bernhard Schussek
+ */
class ValidatorExtension extends AbstractExtension
{
private $validator;
@@ -25,6 +30,12 @@ class ValidatorExtension extends AbstractExtension
{
$this->validator = $validator;
+ // Register the form constraints in the validator programmatically.
+ // This functionality is required when using the Form component without
+ // the DIC, where the XML file is loaded automatically. Thus the following
+ // code must be kept synchronized with validation.xml
+
+ /** @var \Symfony\Component\Validator\Mapping\ClassMetadata $metadata */
$metadata = $this->validator->getMetadataFactory()->getClassMetadata('Symfony\Component\Form\Form');
$metadata->addConstraint(new Form());
$metadata->addPropertyConstraint('children', new Valid());
diff --git a/src/Symfony/Component/Form/FormFactory.php b/src/Symfony/Component/Form/FormFactory.php
index 4ecbfb49a3..02be3017a2 100644
--- a/src/Symfony/Component/Form/FormFactory.php
+++ b/src/Symfony/Component/Form/FormFactory.php
@@ -37,7 +37,7 @@ class FormFactory implements FormFactoryInterface
/**
* {@inheritdoc}
*/
- public function create($type, $data = null, array $options = array(), FormBuilderInterface $parent = null)
+ public function create($type = 'form', $data = null, array $options = array(), FormBuilderInterface $parent = null)
{
return $this->createBuilder($type, $data, $options, $parent)->getForm();
}
@@ -45,7 +45,7 @@ class FormFactory implements FormFactoryInterface
/**
* {@inheritdoc}
*/
- public function createNamed($name, $type, $data = null, array $options = array(), FormBuilderInterface $parent = null)
+ public function createNamed($name, $type = 'form', $data = null, array $options = array(), FormBuilderInterface $parent = null)
{
return $this->createNamedBuilder($name, $type, $data, $options, $parent)->getForm();
}
@@ -61,7 +61,7 @@ class FormFactory implements FormFactoryInterface
/**
* {@inheritdoc}
*/
- public function createBuilder($type, $data = null, array $options = array(), FormBuilderInterface $parent = null)
+ public function createBuilder($type = 'form', $data = null, array $options = array(), FormBuilderInterface $parent = null)
{
$name = $type instanceof FormTypeInterface || $type instanceof ResolvedFormTypeInterface
? $type->getName()
@@ -73,7 +73,7 @@ class FormFactory implements FormFactoryInterface
/**
* {@inheritdoc}
*/
- public function createNamedBuilder($name, $type, $data = null, array $options = array(), FormBuilderInterface $parent = null)
+ public function createNamedBuilder($name, $type = 'form', $data = null, array $options = array(), FormBuilderInterface $parent = null)
{
if (null !== $data && !array_key_exists('data', $options)) {
$options['data'] = $data;
diff --git a/src/Symfony/Component/Form/FormFactoryBuilder.php b/src/Symfony/Component/Form/FormFactoryBuilder.php
new file mode 100644
index 0000000000..d316c9c87b
--- /dev/null
+++ b/src/Symfony/Component/Form/FormFactoryBuilder.php
@@ -0,0 +1,164 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form;
+
+/**
+ * @author Bernhard Schussek
+ */
+
+/**
+ * The default implementation of FormFactoryBuilderInterface.
+ *
+ * @author Bernhard Schussek
+ */
+class FormFactoryBuilder implements FormFactoryBuilderInterface
+{
+ /**
+ * @var ResolvedFormTypeFactoryInterface
+ */
+ private $resolvedTypeFactory;
+
+ /**
+ * @var array
+ */
+ private $extensions = array();
+
+ /**
+ * @var array
+ */
+ private $types = array();
+
+ /**
+ * @var array
+ */
+ private $typeExtensions = array();
+
+ /**
+ * @var array
+ */
+ private $typeGuessers = array();
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setResolvedTypeFactory(ResolvedFormTypeFactoryInterface $resolvedTypeFactory)
+ {
+ $this->resolvedTypeFactory = $resolvedTypeFactory;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addExtension(FormExtensionInterface $extension)
+ {
+ $this->extensions[] = $extension;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addExtensions(array $extensions)
+ {
+ $this->extensions = array_merge($this->extensions, $extensions);
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addType(FormTypeInterface $type)
+ {
+ $this->types[$type->getName()] = $type;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addTypes(array $types)
+ {
+ foreach ($types as $type) {
+ $this->types[$type->getName()] = $type;
+ }
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addTypeExtension(FormTypeExtensionInterface $typeExtension)
+ {
+ $this->typeExtensions[$typeExtension->getExtendedType()][] = $typeExtension;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addTypeExtensions(array $typeExtensions)
+ {
+ foreach ($typeExtensions as $typeExtension) {
+ $this->typeExtensions[$typeExtension->getExtendedType()][] = $typeExtension;
+ }
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addTypeGuesser(FormTypeGuesserInterface $typeGuesser)
+ {
+ $this->typeGuessers[] = $typeGuesser;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addTypeGuessers(array $typeGuessers)
+ {
+ $this->typeGuessers = array_merge($this->typeGuessers, $typeGuessers);
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getFormFactory()
+ {
+ $extensions = $this->extensions;
+
+ if (count($this->types) > 0 || count($this->typeExtensions) > 0 || count($this->typeGuessers) > 0) {
+ $typeGuesser = count($this->typeGuessers) > 1
+ ? new FormTypeGuesserChain($this->typeGuessers)
+ : $this->typeGuessers[0];
+
+ $extensions[] = new PreloadedExtension($this->types, $this->typeExtensions, $typeGuesser);
+ }
+
+ $resolvedTypeFactory = $this->resolvedTypeFactory ?: new ResolvedFormTypeFactory();
+ $registry = new FormRegistry($extensions, $resolvedTypeFactory);
+
+ return new FormFactory($registry, $resolvedTypeFactory);
+ }
+}
diff --git a/src/Symfony/Component/Form/FormFactoryBuilderInterface.php b/src/Symfony/Component/Form/FormFactoryBuilderInterface.php
new file mode 100644
index 0000000000..9370c573a6
--- /dev/null
+++ b/src/Symfony/Component/Form/FormFactoryBuilderInterface.php
@@ -0,0 +1,108 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form;
+
+/**
+ * A builder for FormFactoryInterface objects.
+ *
+ * @author Bernhard Schussek
+ */
+interface FormFactoryBuilderInterface
+{
+ /**
+ * Sets the factory for creating ResolvedFormTypeInterface instances.
+ *
+ * @param ResolvedFormTypeFactoryInterface $resolvedTypeFactory
+ *
+ * @return FormFactoryBuilderInterface The builder.
+ */
+ public function setResolvedTypeFactory(ResolvedFormTypeFactoryInterface $resolvedTypeFactory);
+
+ /**
+ * Adds an extension to be loaded by the factory.
+ *
+ * @param FormExtensionInterface $extension The extension.
+ *
+ * @return FormFactoryBuilderInterface The builder.
+ */
+ public function addExtension(FormExtensionInterface $extension);
+
+ /**
+ * Adds a list of extensions to be loaded by the factory.
+ *
+ * @param array $extensions The extensions.
+ *
+ * @return FormFactoryBuilderInterface The builder.
+ */
+ public function addExtensions(array $extensions);
+
+ /**
+ * Adds a form type to the factory.
+ *
+ * @param FormTypeInterface $type The form type.
+ *
+ * @return FormFactoryBuilderInterface The builder.
+ */
+ public function addType(FormTypeInterface $type);
+
+ /**
+ * Adds a list of form types to the factory.
+ *
+ * @param array $types The form types.
+ *
+ * @return FormFactoryBuilderInterface The builder.
+ */
+ public function addTypes(array $types);
+
+ /**
+ * Adds a form type extension to the factory.
+ *
+ * @param FormTypeExtensionInterface $typeExtension The form type extension.
+ *
+ * @return FormFactoryBuilderInterface The builder.
+ */
+ public function addTypeExtension(FormTypeExtensionInterface $typeExtension);
+
+ /**
+ * Adds a list of form type extensions to the factory.
+ *
+ * @param array $typeExtensions The form type extensions.
+ *
+ * @return FormFactoryBuilderInterface The builder.
+ */
+ public function addTypeExtensions(array $typeExtensions);
+
+ /**
+ * Adds a type guesser to the factory.
+ *
+ * @param FormTypeGuesserInterface $typeGuesser The type guesser.
+ *
+ * @return FormFactoryBuilderInterface The builder.
+ */
+ public function addTypeGuesser(FormTypeGuesserInterface $typeGuesser);
+
+ /**
+ * Adds a list of type guessers to the factory.
+ *
+ * @param array $typeGuessers The type guessers.
+ *
+ * @return FormFactoryBuilderInterface The builder.
+ */
+ public function addTypeGuessers(array $typeGuessers);
+
+ /**
+ * Builds and returns the factory.
+ *
+ * @return FormFactoryInterface The form factory.
+ */
+ public function getFormFactory();
+}
diff --git a/src/Symfony/Component/Form/FormFactoryInterface.php b/src/Symfony/Component/Form/FormFactoryInterface.php
index 73f31aa373..fc90068479 100644
--- a/src/Symfony/Component/Form/FormFactoryInterface.php
+++ b/src/Symfony/Component/Form/FormFactoryInterface.php
@@ -30,7 +30,7 @@ interface FormFactoryInterface
*
* @throws Exception\FormException if any given option is not applicable to the given type
*/
- public function create($type, $data = null, array $options = array(), FormBuilderInterface $parent = null);
+ public function create($type = 'form', $data = null, array $options = array(), FormBuilderInterface $parent = null);
/**
* Returns a form.
@@ -47,7 +47,7 @@ interface FormFactoryInterface
*
* @throws Exception\FormException if any given option is not applicable to the given type
*/
- public function createNamed($name, $type, $data = null, array $options = array(), FormBuilderInterface $parent = null);
+ public function createNamed($name, $type = 'form', $data = null, array $options = array(), FormBuilderInterface $parent = null);
/**
* Returns a form for a property of a class.
@@ -78,7 +78,7 @@ interface FormFactoryInterface
*
* @throws Exception\FormException if any given option is not applicable to the given type
*/
- public function createBuilder($type, $data = null, array $options = array(), FormBuilderInterface $parent = null);
+ public function createBuilder($type = 'form', $data = null, array $options = array(), FormBuilderInterface $parent = null);
/**
* Returns a form builder.
@@ -93,7 +93,7 @@ interface FormFactoryInterface
*
* @throws Exception\FormException if any given option is not applicable to the given type
*/
- public function createNamedBuilder($name, $type, $data = null, array $options = array(), FormBuilderInterface $parent = null);
+ public function createNamedBuilder($name, $type = 'form', $data = null, array $options = array(), FormBuilderInterface $parent = null);
/**
* Returns a form builder for a property of a class.
diff --git a/src/Symfony/Component/Form/Forms.php b/src/Symfony/Component/Form/Forms.php
new file mode 100644
index 0000000000..263297073b
--- /dev/null
+++ b/src/Symfony/Component/Form/Forms.php
@@ -0,0 +1,138 @@
+
+ *
+ * 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\Extension\Core\CoreExtension;
+use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
+
+/**
+ * Entry point of the Form component.
+ *
+ * Use this class to conveniently create new form factories:
+ *
+ *
+ * use Symfony\Component\Form\Forms;
+ *
+ * $formFactory = Forms::createFormFactory();
+ *
+ * $form = $formFactory->createBuilder()
+ * ->add('firstName', 'text')
+ * ->add('lastName', 'text')
+ * ->add('age', 'integer')
+ * ->add('gender', 'choice', array(
+ * 'choices' => array('m' => 'Male', 'f' => 'Female'),
+ * ))
+ * ->getForm();
+ *
+ *
+ * You can also add custom extensions to the form factory:
+ *
+ *
+ * $formFactory = Forms::createFormFactoryBuilder()
+ * ->addExtension(new AcmeExtension())
+ * ->getFormFactory();
+ *
+ *
+ * If you create custom form types or type extensions, it is
+ * generally recommended to create your own extensions that lazily
+ * load these types and type extensions. In projects where performance
+ * does not matter that much, you can also pass them directly to the
+ * form factory:
+ *
+ *
+ * $formFactory = Forms::createFormFactoryBuilder()
+ * ->addType(new PersonType())
+ * ->addType(new PhoneNumberType())
+ * ->addTypeExtension(new FormTypeHelpTextExtension())
+ * ->getFormFactory();
+ *
+ *
+ * Support for CSRF protection is provided by the CsrfExtension.
+ * This extension needs a CSRF provider with a strong secret
+ * (e.g. a 20 character long random string). The default
+ * implementation for this is DefaultCsrfProvider:
+ *
+ *
+ * use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
+ * use Symfony\Component\Form\Extension\Csrf\CsrfProvider\DefaultCsrfProvider;
+ *
+ * $secret = 'V8a5Z97e...';
+ * $formFactory = Forms::createFormFactoryBuilder()
+ * ->addExtension(new CsrfExtension(new DefaultCsrfProvider($secret)))
+ * ->getFormFactory();
+ *
+ *
+ * Support for the HttpFoundation is provided by the
+ * HttpFoundationExtension. You are also advised to load the CSRF
+ * extension with the driver for HttpFoundation's Session class:
+ *
+ *
+ * use Symfony\Component\HttpFoundation\Session\Session;
+ * use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
+ * use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
+ * use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
+ *
+ * $session = new Session();
+ * $secret = 'V8a5Z97e...';
+ * $formFactory = Forms::createFormFactoryBuilder()
+ * ->addExtension(new HttpFoundationExtension())
+ * ->addExtension(new CsrfExtension(new SessionCsrfProvider($session, $secret)))
+ * ->getFormFactory();
+ *
+ *
+ * Support for the Validator component is provided by ValidatorExtension.
+ * This extension needs a validator object to function properly:
+ *
+ *
+ * use Symfony\Component\Validator\ValidatorFactory;
+ * use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
+ *
+ * $validator = ValidatorFactory::buildDefault()->getValidator();
+ * $formFactory = Forms::createFormFactoryBuilder()
+ * ->addExtension(new ValidatorExtension($validator))
+ * ->getFormFactory();
+ *
+ *
+ * @author Bernhard Schussek
+ */
+final class Forms
+{
+ /**
+ * Creates a form factory with the default configuration.
+ *
+ * @return FormFactoryInterface The form factory.
+ */
+ public static function createFormFactory()
+ {
+ return self::createFormFactoryBuilder()->getFormFactory();
+ }
+
+ /**
+ * Creates a form factory builder with the default configuration.
+ *
+ * @return FormFactoryBuilderInterface The form factory builder.
+ */
+ public static function createFormFactoryBuilder()
+ {
+ $builder = new FormFactoryBuilder();
+ $builder->addExtension(new CoreExtension());
+
+ return $builder;
+ }
+
+ /**
+ * This class cannot be instantiated.
+ */
+ private function __construct()
+ {
+ }
+}
diff --git a/src/Symfony/Component/Form/PreloadedExtension.php b/src/Symfony/Component/Form/PreloadedExtension.php
new file mode 100644
index 0000000000..73b502435d
--- /dev/null
+++ b/src/Symfony/Component/Form/PreloadedExtension.php
@@ -0,0 +1,100 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form;
+
+/**
+ * @author Bernhard Schussek
+ */
+use Symfony\Component\Form\Exception\FormException;
+
+/**
+ * A form extension with preloaded types, type exceptions and type guessers.
+ *
+ * @author Bernhard Schussek
+ */
+class PreloadedExtension implements FormExtensionInterface
+{
+ /**
+ * @var array
+ */
+ private $types = array();
+
+ /**
+ * @var array
+ */
+ private $typeExtensions = array();
+
+ /**
+ * @var FormTypeGuesserInterface
+ */
+ private $typeGuesser;
+
+ /**
+ * Creates a new preloaded extension.
+ *
+ * @param array $types The types that the extension should support.
+ * @param array $typeExtensions The type extensions that the extension should support.
+ * @param FormTypeGuesserInterface $typeGuesser The guesser that the extension should support.
+ */
+ public function __construct(array $types, array $typeExtensions, FormTypeGuesserInterface $typeGuesser)
+ {
+ $this->types = $types;
+ $this->typeExtensions = $typeExtensions;
+ $this->typeGuesser = $typeGuesser;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getType($name)
+ {
+ if (!isset($this->types[$name])) {
+ throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
+ }
+
+ return $this->types[$name];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function hasType($name)
+ {
+ return isset($this->types[$name]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getTypeExtensions($name)
+ {
+ return isset($this->typeExtensions[$name])
+ ? $this->typeExtensions[$name]
+ : array();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function hasTypeExtensions($name)
+ {
+ return isset($this->typeExtensions[$name]) && count($this->typeExtensions[$name]) > 0;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getTypeGuesser()
+ {
+ return $this->typeGuesser;
+ }
+}
diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
index e938a5fda8..d4ef19b259 100644
--- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
+++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
@@ -39,7 +39,6 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
protected function getExtensions()
{
return array(
- new CoreExtension(),
new CsrfExtension($this->csrfProvider),
);
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTemplateNameParser.php b/src/Symfony/Component/Form/Tests/Extension/Templating/Fixtures/StubTemplateNameParser.php
similarity index 93%
rename from src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTemplateNameParser.php
rename to src/Symfony/Component/Form/Tests/Extension/Templating/Fixtures/StubTemplateNameParser.php
index 3a66454947..447944a428 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTemplateNameParser.php
+++ b/src/Symfony/Component/Form/Tests/Extension/Templating/Fixtures/StubTemplateNameParser.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures;
+namespace Symfony\Component\Form\Tests\Extension\Templating\Fixtures;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\TemplateReference;
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTranslator.php b/src/Symfony/Component/Form/Tests/Extension/Templating/Fixtures/StubTranslator.php
similarity index 90%
rename from src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTranslator.php
rename to src/Symfony/Component/Form/Tests/Extension/Templating/Fixtures/StubTranslator.php
index 17d1fd4fc6..6e0db360a3 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTranslator.php
+++ b/src/Symfony/Component/Form/Tests/Extension/Templating/Fixtures/StubTranslator.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures;
+namespace Symfony\Component\Form\Tests\Extension\Templating\Fixtures;
use Symfony\Component\Translation\TranslatorInterface;
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php b/src/Symfony/Component/Form/Tests/Extension/Templating/FormHelperDivLayoutTest.php
similarity index 73%
rename from src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php
rename to src/Symfony/Component/Form/Tests/Extension/Templating/FormHelperDivLayoutTest.php
index cc386971f9..9dcc3b4f99 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php
+++ b/src/Symfony/Component/Form/Tests/Extension/Templating/FormHelperDivLayoutTest.php
@@ -9,18 +9,20 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper;
+namespace Symfony\Component\Form\Tests\Extension\Templating;
-use Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper;
-use Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper;
-use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTemplateNameParser;
-use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTranslator;
-use Symfony\Component\Templating\PhpEngine;
-use Symfony\Component\Templating\Loader\FilesystemLoader;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormRenderer;
+use Symfony\Component\Form\Extension\Templating\FormHelper;
use Symfony\Component\Form\Extension\Templating\TemplatingRendererEngine;
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
+use Symfony\Component\Form\Tests\Extension\Templating\Fixtures\StubTemplateNameParser;
+use Symfony\Component\Form\Tests\Extension\Templating\Fixtures\StubTranslator;
+use Symfony\Component\Templating\PhpEngine;
+use Symfony\Component\Templating\Loader\FilesystemLoader;
+
+// should probably be moved to the Translation component
+use Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper;
class FormHelperDivLayoutTest extends AbstractDivLayoutTest
{
@@ -28,9 +30,20 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
protected function setUp()
{
+ if (!class_exists('Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper')) {
+ $this->markTestSkipped('The "FrameworkBundle" is not available');
+ }
+
+ if (!class_exists('Symfony\Component\Templating\PhpEngine')) {
+ $this->markTestSkipped('The "Templating" component is not available');
+ }
+
parent::setUp();
- $root = realpath(__DIR__.'/../../../Resources/views');
+ // should be moved to the Form component once absolute file paths are supported
+ // by the default name parser in the Templating component
+ $reflClass = new \ReflectionClass('Symfony\Bundle\FrameworkBundle\FrameworkBundle');
+ $root = realpath(dirname($reflClass->getFileName()) . '/Resources/views');
$rootTheme = realpath(__DIR__.'/Resources');
$templateNameParser = new StubTemplateNameParser($root, $rootTheme);
$loader = new FilesystemLoader(array());
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTableLayoutTest.php b/src/Symfony/Component/Form/Tests/Extension/Templating/FormHelperTableLayoutTest.php
similarity index 71%
rename from src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTableLayoutTest.php
rename to src/Symfony/Component/Form/Tests/Extension/Templating/FormHelperTableLayoutTest.php
index ad8b74eba9..0bbc95a549 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTableLayoutTest.php
+++ b/src/Symfony/Component/Form/Tests/Extension/Templating/FormHelperTableLayoutTest.php
@@ -9,28 +9,41 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper;
+namespace Symfony\Component\Form\Tests\Extension\Templating;
-use Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper;
-use Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper;
-use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTemplateNameParser;
-use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTranslator;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormRenderer;
+use Symfony\Component\Form\Extension\Templating\FormHelper;
use Symfony\Component\Form\Extension\Templating\TemplatingRendererEngine;
use Symfony\Component\Form\Tests\AbstractTableLayoutTest;
+use Symfony\Component\Form\Tests\Extension\Templating\Fixtures\StubTemplateNameParser;
+use Symfony\Component\Form\Tests\Extension\Templating\Fixtures\StubTranslator;
use Symfony\Component\Templating\PhpEngine;
use Symfony\Component\Templating\Loader\FilesystemLoader;
+// should probably be moved to the Translation component
+use Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper;
+
class FormHelperTableLayoutTest extends AbstractTableLayoutTest
{
protected $helper;
protected function setUp()
{
+ if (!class_exists('Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper')) {
+ $this->markTestSkipped('The "FrameworkBundle" is not available');
+ }
+
+ if (!class_exists('Symfony\Component\Templating\PhpEngine')) {
+ $this->markTestSkipped('The "Templating" component is not available');
+ }
+
parent::setUp();
- $root = realpath(__DIR__.'/../../../Resources/views');
+ // should be moved to the Form component once absolute file paths are supported
+ // by the default name parser in the Templating component
+ $reflClass = new \ReflectionClass('Symfony\Bundle\FrameworkBundle\FrameworkBundle');
+ $root = realpath(dirname($reflClass->getFileName()) . '/Resources/views');
$rootTheme = realpath(__DIR__.'/Resources');
$templateNameParser = new StubTemplateNameParser($root, $rootTheme);
$loader = new FilesystemLoader(array());
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Child/form_label.html.php b/src/Symfony/Component/Form/Tests/Extension/Templating/Resources/Child/form_label.html.php
similarity index 100%
rename from src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Child/form_label.html.php
rename to src/Symfony/Component/Form/Tests/Extension/Templating/Resources/Child/form_label.html.php
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Custom/_name_entry_label.html.php b/src/Symfony/Component/Form/Tests/Extension/Templating/Resources/Custom/_name_entry_label.html.php
similarity index 100%
rename from src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Custom/_name_entry_label.html.php
rename to src/Symfony/Component/Form/Tests/Extension/Templating/Resources/Custom/_name_entry_label.html.php
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Custom/_text_id_widget.html.php b/src/Symfony/Component/Form/Tests/Extension/Templating/Resources/Custom/_text_id_widget.html.php
similarity index 100%
rename from src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Custom/_text_id_widget.html.php
rename to src/Symfony/Component/Form/Tests/Extension/Templating/Resources/Custom/_text_id_widget.html.php
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Parent/form_label.html.php b/src/Symfony/Component/Form/Tests/Extension/Templating/Resources/Parent/form_label.html.php
similarity index 100%
rename from src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Parent/form_label.html.php
rename to src/Symfony/Component/Form/Tests/Extension/Templating/Resources/Parent/form_label.html.php
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Parent/form_widget_simple.html.php b/src/Symfony/Component/Form/Tests/Extension/Templating/Resources/Parent/form_widget_simple.html.php
similarity index 100%
rename from src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Parent/form_widget_simple.html.php
rename to src/Symfony/Component/Form/Tests/Extension/Templating/Resources/Parent/form_widget_simple.html.php
diff --git a/src/Symfony/Component/Form/Tests/FormIntegrationTestCase.php b/src/Symfony/Component/Form/Tests/FormIntegrationTestCase.php
index bdb93e19e7..2d2175d71d 100644
--- a/src/Symfony/Component/Form/Tests/FormIntegrationTestCase.php
+++ b/src/Symfony/Component/Form/Tests/FormIntegrationTestCase.php
@@ -11,9 +11,7 @@
namespace Symfony\Component\Form\Tests;
-use Symfony\Component\Form\FormFactory;
-use Symfony\Component\Form\ResolvedFormTypeFactory;
-use Symfony\Component\Form\FormRegistry;
+use Symfony\Component\Form\Forms;
use Symfony\Component\Form\Extension\Core\CoreExtension;
/**
@@ -22,17 +20,7 @@ use Symfony\Component\Form\Extension\Core\CoreExtension;
class FormIntegrationTestCase extends \PHPUnit_Framework_TestCase
{
/**
- * @var ResolvedFormTypeFactory
- */
- protected $resolvedTypeFactory;
-
- /**
- * @var FormRegistry
- */
- protected $registry;
-
- /**
- * @var FormFactory
+ * @var \Symfony\Component\Form\FormFactoryInterface
*/
protected $factory;
@@ -42,15 +30,13 @@ class FormIntegrationTestCase extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
- $this->resolvedTypeFactory = new ResolvedFormTypeFactory();
- $this->registry = new FormRegistry($this->getExtensions(), $this->resolvedTypeFactory);
- $this->factory = new FormFactory($this->registry, $this->resolvedTypeFactory);
+ $this->factory = Forms::createFormFactoryBuilder()
+ ->addExtensions($this->getExtensions())
+ ->getFormFactory();
}
protected function getExtensions()
{
- return array(
- new CoreExtension(),
- );
+ return array();
}
}