Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
<?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\Tests\Fixtures;
abstract class AbstractAuthor
{
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Symfony\Component\Form\Tests\Fixtures;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormBuilderInterface;
class AlternatingRowType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$formFactory = $builder->getFormFactory();
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($formFactory) {
$form = $event->getForm();
$type = $form->getName() % 2 === 0
? 'Symfony\Component\Form\Extension\Core\Type\TextType'
: 'Symfony\Component\Form\Extension\Core\Type\TextareaType';
$form->add('title', $type);
});
}
}

View File

@@ -0,0 +1,77 @@
<?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\Tests\Fixtures;
class Author
{
public $firstName;
private $lastName;
private $australian;
public $child;
private $readPermissions;
private $privateProperty;
public function __construct($firstName = null, $lastName = null)
{
$this->firstName = $firstName;
$this->lastName = $lastName;
}
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)
{
}
}

View File

@@ -0,0 +1,16 @@
<?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\Tests\Fixtures;
interface AuthorInterface
{
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Symfony\Component\Form\Tests\Fixtures;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class AuthorType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName')
->add('lastName')
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
));
}
}

View File

@@ -0,0 +1,43 @@
<?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\Tests\Fixtures;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* @author Paráda József <joczy.parada@gmail.com>
*/
class ChoiceSubType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array('expanded' => true));
$resolver->setNormalizer('choices', function () {
return array(
'attr1' => 'Attribute 1',
'attr2' => 'Attribute 2',
);
});
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
}
}

View File

@@ -0,0 +1,45 @@
<?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\Tests\Fixtures;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ChoiceTypeExtension extends AbstractTypeExtension
{
private $extendedType;
public function __construct($extendedType = ChoiceType::class)
{
$this->extendedType = $extendedType;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('choices', array(
'A' => 'a',
'B' => 'b',
));
}
/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return $this->extendedType;
}
}

View File

@@ -0,0 +1,70 @@
<?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\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);
}
}

View File

@@ -0,0 +1,18 @@
<?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\Tests\Fixtures;
use Symfony\Component\Form\AbstractType;
class FBooType extends AbstractType
{
}

View File

@@ -0,0 +1,45 @@
<?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\Tests\Fixtures;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
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 TransformationFailedException(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 TransformationFailedException(sprintf('No reverse mapping for value "%s"', $value));
}
return $result;
}
}

View File

@@ -0,0 +1,66 @@
<?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\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',
);
}
}

View File

@@ -0,0 +1,18 @@
<?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\Tests\Fixtures;
use Symfony\Component\Form\AbstractType;
class Foo extends AbstractType
{
}

View File

@@ -0,0 +1,18 @@
<?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\Tests\Fixtures;
use Symfony\Component\Form\AbstractType;
class Foo1Bar2Type extends AbstractType
{
}

View File

@@ -0,0 +1,18 @@
<?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\Tests\Fixtures;
use Symfony\Component\Form\AbstractType;
class FooBarHTMLType extends AbstractType
{
}

View File

@@ -0,0 +1,22 @@
<?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\Tests\Fixtures;
use Symfony\Component\Form\AbstractType;
class FooSubType extends AbstractType
{
public function getParent()
{
return __NAMESPACE__.'\FooType';
}
}

View File

@@ -0,0 +1,21 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Fixtures;
use Symfony\Component\Form\AbstractType;
class FooType extends AbstractType
{
public function getParent()
{
}
}

View File

@@ -0,0 +1,35 @@
<?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\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 __NAMESPACE__.'\FooType';
}
}

View File

@@ -0,0 +1,28 @@
<?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\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 __NAMESPACE__.'\FooType';
}
}

View File

@@ -0,0 +1,48 @@
<?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\Tests\Fixtures;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class LazyChoiceTypeExtension extends AbstractTypeExtension
{
private $extendedType;
public function __construct($extendedType = ChoiceType::class)
{
$this->extendedType = $extendedType;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('choice_loader', new CallbackChoiceLoader(function () {
return array(
'Lazy A' => 'lazy_a',
'Lazy B' => 'lazy_b',
);
}));
}
/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return $this->extendedType;
}
}

View File

@@ -0,0 +1,72 @@
<?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\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[get_class($type)] = $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;
}
}

View File

@@ -0,0 +1,18 @@
<?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\Tests\Fixtures;
use Symfony\Component\Form\AbstractType;
class Type extends AbstractType
{
}

View File

View File

View File