From 4f5b44bd3bd490309eb2ba7b44df4769816ba729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 19:26:54 +0200 Subject: twig implementation --- .../Form/Tests/Fixtures/AlternatingRowType.php | 27 ++++++++ .../Component/Form/Tests/Fixtures/Author.php | 71 +++++++++++++++++++++ .../Component/Form/Tests/Fixtures/AuthorType.php | 30 +++++++++ .../Form/Tests/Fixtures/CustomArrayObject.php | 70 +++++++++++++++++++++ .../Form/Tests/Fixtures/FixedDataTransformer.php | 45 ++++++++++++++ .../Form/Tests/Fixtures/FixedFilterListener.php | 66 ++++++++++++++++++++ .../Component/Form/Tests/Fixtures/FooSubType.php | 32 ++++++++++ .../Fixtures/FooSubTypeWithParentInstance.php | 32 ++++++++++ .../Component/Form/Tests/Fixtures/FooType.php | 32 ++++++++++ .../Form/Tests/Fixtures/FooTypeBarExtension.php | 35 +++++++++++ .../Form/Tests/Fixtures/FooTypeBazExtension.php | 28 +++++++++ .../Form/Tests/Fixtures/TestExtension.php | 72 ++++++++++++++++++++++ .../form/Symfony/Component/Form/Tests/Fixtures/foo | 0 13 files changed, 540 insertions(+) create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/AlternatingRowType.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/Author.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/AuthorType.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FixedDataTransformer.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FixedFilterListener.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooSubType.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooSubTypeWithParentInstance.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooType.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/TestExtension.php create mode 100644 vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/foo (limited to 'vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures') diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/AlternatingRowType.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/AlternatingRowType.php new file mode 100644 index 00000000..ee7d1353 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/AlternatingRowType.php @@ -0,0 +1,27 @@ +getFormFactory(); + + $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($formFactory) { + $form = $event->getForm(); + $type = $form->getName() % 2 === 0 ? 'text' : 'textarea'; + $form->add('title', $type); + }); + } + + public function getName() + { + return 'alternating_row'; + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/Author.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/Author.php new file mode 100644 index 00000000..11204894 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/Author.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures; + +class Author +{ + public $firstName; + private $lastName; + private $australian; + public $child; + private $readPermissions; + + private $privateProperty; + + public function setLastName($lastName) + { + $this->lastName = $lastName; + } + + public function getLastName() + { + return $this->lastName; + } + + private function getPrivateGetter() + { + return 'foobar'; + } + + public function setAustralian($australian) + { + $this->australian = $australian; + } + + public function isAustralian() + { + return $this->australian; + } + + public function setReadPermissions($bool) + { + $this->readPermissions = $bool; + } + + public function hasReadPermissions() + { + return $this->readPermissions; + } + + private function isPrivateIsser() + { + return true; + } + + public function getPrivateSetter() + { + } + + private function setPrivateSetter($data) + { + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/AuthorType.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/AuthorType.php new file mode 100644 index 00000000..147f6e48 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/AuthorType.php @@ -0,0 +1,30 @@ +add('firstName') + ->add('lastName') + ; + } + + public function getName() + { + return 'author'; + } + + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', + )); + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php new file mode 100644 index 00000000..950f677f --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures; + +/** + * This class is a hand written simplified version of PHP native `ArrayObject` + * class, to show that it behaves differently than the PHP native implementation. + */ +class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable +{ + private $array; + + public function __construct(array $array = null) + { + $this->array = $array ?: array(); + } + + public function offsetExists($offset) + { + return array_key_exists($offset, $this->array); + } + + public function offsetGet($offset) + { + return $this->array[$offset]; + } + + public function offsetSet($offset, $value) + { + if (null === $offset) { + $this->array[] = $value; + } else { + $this->array[$offset] = $value; + } + } + + public function offsetUnset($offset) + { + unset($this->array[$offset]); + } + + public function getIterator() + { + return new \ArrayIterator($this->array); + } + + public function count() + { + return count($this->array); + } + + public function serialize() + { + return serialize($this->array); + } + + public function unserialize($serialized) + { + $this->array = (array) unserialize((string) $serialized); + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FixedDataTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FixedDataTransformer.php new file mode 100644 index 00000000..a5a31248 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FixedDataTransformer.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures; + +use Symfony\Component\Form\DataTransformerInterface; +use Symfony\Component\Form\Exception\RuntimeException; + +class FixedDataTransformer implements DataTransformerInterface +{ + private $mapping; + + public function __construct(array $mapping) + { + $this->mapping = $mapping; + } + + public function transform($value) + { + if (!array_key_exists($value, $this->mapping)) { + throw new RuntimeException(sprintf('No mapping for value "%s"', $value)); + } + + return $this->mapping[$value]; + } + + public function reverseTransform($value) + { + $result = array_search($value, $this->mapping, true); + + if ($result === false) { + throw new RuntimeException(sprintf('No reverse mapping for value "%s"', $value)); + } + + return $result; + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FixedFilterListener.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FixedFilterListener.php new file mode 100644 index 00000000..762a10b8 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FixedFilterListener.php @@ -0,0 +1,66 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures; + +use Symfony\Component\Form\FormEvents; +use Symfony\Component\Form\FormEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +class FixedFilterListener implements EventSubscriberInterface +{ + private $mapping; + + public function __construct(array $mapping) + { + $this->mapping = array_merge(array( + 'preSubmit' => array(), + 'onSubmit' => array(), + 'preSetData' => array(), + ), $mapping); + } + + public function preSubmit(FormEvent $event) + { + $data = $event->getData(); + + if (isset($this->mapping['preSubmit'][$data])) { + $event->setData($this->mapping['preSubmit'][$data]); + } + } + + public function onSubmit(FormEvent $event) + { + $data = $event->getData(); + + if (isset($this->mapping['onSubmit'][$data])) { + $event->setData($this->mapping['onSubmit'][$data]); + } + } + + public function preSetData(FormEvent $event) + { + $data = $event->getData(); + + if (isset($this->mapping['preSetData'][$data])) { + $event->setData($this->mapping['preSetData'][$data]); + } + } + + public static function getSubscribedEvents() + { + return array( + FormEvents::PRE_SUBMIT => 'preSubmit', + FormEvents::SUBMIT => 'onSubmit', + FormEvents::PRE_SET_DATA => 'preSetData', + ); + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooSubType.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooSubType.php new file mode 100644 index 00000000..4f7ba6d4 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooSubType.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormFactoryInterface; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; + +class FooSubType extends AbstractType +{ + public function getName() + { + return 'foo_sub_type'; + } + + public function getParent() + { + return 'foo'; + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooSubTypeWithParentInstance.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooSubTypeWithParentInstance.php new file mode 100644 index 00000000..468b5a32 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooSubTypeWithParentInstance.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormFactoryInterface; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; + +class FooSubTypeWithParentInstance extends AbstractType +{ + public function getName() + { + return 'foo_sub_type_parent_instance'; + } + + public function getParent() + { + return new FooType(); + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooType.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooType.php new file mode 100644 index 00000000..d26d3f76 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooType.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormFactoryInterface; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; + +class FooType extends AbstractType +{ + public function getName() + { + return 'foo'; + } + + public function getParent() + { + return null; + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php new file mode 100644 index 00000000..c5f92e11 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures; + +use Symfony\Component\Form\AbstractTypeExtension; +use Symfony\Component\Form\FormBuilderInterface; + +class FooTypeBarExtension extends AbstractTypeExtension +{ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->setAttribute('bar', 'x'); + } + + public function getAllowedOptionValues() + { + return array( + 'a_or_b' => array('c'), + ); + } + + public function getExtendedType() + { + return 'foo'; + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php new file mode 100644 index 00000000..2e364754 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures; + +use Symfony\Component\Form\AbstractTypeExtension; +use Symfony\Component\Form\FormBuilderInterface; + +class FooTypeBazExtension extends AbstractTypeExtension +{ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->setAttribute('baz', 'x'); + } + + public function getExtendedType() + { + return 'foo'; + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/TestExtension.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/TestExtension.php new file mode 100644 index 00000000..f9de560f --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/TestExtension.php @@ -0,0 +1,72 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures; + +use Symfony\Component\Form\FormTypeInterface; +use Symfony\Component\Form\FormTypeExtensionInterface; +use Symfony\Component\Form\FormTypeGuesserInterface; +use Symfony\Component\Form\FormExtensionInterface; + +class TestExtension implements FormExtensionInterface +{ + private $types = array(); + + private $extensions = array(); + + private $guesser; + + public function __construct(FormTypeGuesserInterface $guesser) + { + $this->guesser = $guesser; + } + + public function addType(FormTypeInterface $type) + { + $this->types[$type->getName()] = $type; + } + + public function getType($name) + { + return isset($this->types[$name]) ? $this->types[$name] : null; + } + + public function hasType($name) + { + return isset($this->types[$name]); + } + + public function addTypeExtension(FormTypeExtensionInterface $extension) + { + $type = $extension->getExtendedType(); + + if (!isset($this->extensions[$type])) { + $this->extensions[$type] = array(); + } + + $this->extensions[$type][] = $extension; + } + + public function getTypeExtensions($name) + { + return isset($this->extensions[$name]) ? $this->extensions[$name] : array(); + } + + public function hasTypeExtensions($name) + { + return isset($this->extensions[$name]); + } + + public function getTypeGuesser() + { + return $this->guesser; + } +} diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/foo b/vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/foo new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3