[Form] Fixed PR comments

This commit is contained in:
Bernhard Schussek 2015-03-26 10:59:50 +01:00
parent 26eba769b5
commit d6179c830b
25 changed files with 134 additions and 244 deletions

View File

@ -97,25 +97,12 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
}
/**
* Loads the values corresponding to the given objects.
*
* The values are returned with the same keys and in the same order as the
* corresponding objects in the given array.
*
* Optionally, a callable can be passed for generating the choice values.
* The callable receives the object as first and the array key as the second
* argument.
*
* @param array $objects An array of objects. Non-existing objects in
* this array are ignored
* @param null|callable $value The callable generating the choice values
*
* @return string[] An array of choice values
* {@inheritdoc}
*/
public function loadValuesForChoices(array $objects, $value = null)
public function loadValuesForChoices(array $choices, $value = null)
{
// Performance optimization
if (empty($objects)) {
if (empty($choices)) {
return array();
}
@ -127,7 +114,7 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
$values = array();
// Maintain order and indices of the given objects
foreach ($objects as $i => $object) {
foreach ($choices as $i => $object) {
if ($object instanceof $this->class) {
// Make sure to convert to the right format
$values[$i] = (string) $this->idReader->getIdValue($object);
@ -137,24 +124,11 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
return $values;
}
return $this->loadChoiceList($value)->getValuesForChoices($objects);
return $this->loadChoiceList($value)->getValuesForChoices($choices);
}
/**
* Loads the objects corresponding to the given values.
*
* The objects are returned with the same keys and in the same order as the
* corresponding values in the given array.
*
* Optionally, a callable can be passed for generating the choice values.
* The callable receives the object as first and the array key as the second
* argument.
*
* @param string[] $values An array of choice values. Non-existing
* values in this array are ignored
* @param null|callable $value The callable generating the choice values
*
* @return array An array of objects
* {@inheritdoc}
*/
public function loadChoicesForValues(array $values, $value = null)
{

View File

@ -129,6 +129,8 @@ class EntityChoiceList extends ObjectChoiceList
}
parent::__construct($entities, $labelPath, $preferredEntities, $groupPath, null, $propertyAccessor);
trigger_error('The '.__CLASS__.' class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader instead.', E_USER_DEPRECATED);
}
/**

View File

@ -37,9 +37,14 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
/**
* Construct an ORM Query Builder Loader.
*
* @param QueryBuilder|\Closure $queryBuilder
* @param EntityManager $manager
* @param string $class
* @param QueryBuilder|\Closure $queryBuilder The query builder or a closure
* for creating the query builder.
* Passing a closure is
* deprecated and will not be
* supported anymore as of
* Symfony 3.0.
* @param EntityManager $manager Deprecated.
* @param string $class Deprecated.
*
* @throws UnexpectedTypeException
*/
@ -51,13 +56,16 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder or \Closure');
}
// This block is not executed anymore since Symfony 2.7. The query
// builder closure is already invoked in DoctrineType
if ($queryBuilder instanceof \Closure) {
trigger_error('Passing a QueryBuilder closure to '.__CLASS__.'::__construct() is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
if (!$manager instanceof EntityManager) {
throw new UnexpectedTypeException($manager, 'Doctrine\ORM\EntityManager');
}
trigger_error('Passing an EntityManager to '.__CLASS__.'::__construct() is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
trigger_error('Passing a class to '.__CLASS__.'::__construct() is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
$queryBuilder = $queryBuilder($manager->getRepository($class));
if (!$queryBuilder instanceof QueryBuilder) {

View File

@ -116,27 +116,10 @@ abstract class DoctrineType extends AbstractType
$choiceLoaders = &$this->choiceLoaders;
$type = $this;
$idReader = function (Options $options) use (&$idReaders) {
$hash = CachingFactoryDecorator::generateHash(array(
$options['em'],
$options['class'],
));
// The ID reader is a utility that is needed to read the object IDs
// when generating the field values. The callback generating the
// field values has no access to the object manager or the class
// of the field, so we store that information in the reader.
// The reader is cached so that two choice lists for the same class
// (and hence with the same reader) can successfully be cached.
if (!isset($idReaders[$hash])) {
$classMetadata = $options['em']->getClassMetadata($options['class']);
$idReaders[$hash] = new IdReader($options['em'], $classMetadata);
}
return $idReaders[$hash];
};
$choiceLoader = function (Options $options) use ($choiceListFactory, &$choiceLoaders, $type) {
// This closure and the "query_builder" options should be pushed to
// EntityType in Symfony 3.0 as they are specific to the ORM
// Unless the choices are given explicitly, load them on demand
if (null === $options['choices']) {
// We consider two query builders with an equal SQL string and
@ -243,6 +226,13 @@ abstract class DoctrineType extends AbstractType
return $em;
};
// deprecation note
$propertyNormalizer = function (Options $options, $propertyName) {
trigger_error('The "property" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_label" instead.', E_USER_DEPRECATED);
return $propertyName;
};
// Invoke the query builder closure so that we can cache choice lists
// for equal query builders
$queryBuilderNormalizer = function (Options $options, $queryBuilder) {
@ -257,6 +247,35 @@ abstract class DoctrineType extends AbstractType
return $queryBuilder;
};
// deprecation note
$loaderNormalizer = function (Options $options, $loader) {
trigger_error('The "loader" option is deprecated since version 2.7 and will be removed in 3.0. Override getLoader() instead.', E_USER_DEPRECATED);
return $loader;
};
// Set the "id_reader" option via the normalizer. This option is not
// supposed to be set by the user.
$idReaderNormalizer = function (Options $options) use (&$idReaders) {
$hash = CachingFactoryDecorator::generateHash(array(
$options['em'],
$options['class'],
));
// The ID reader is a utility that is needed to read the object IDs
// when generating the field values. The callback generating the
// field values has no access to the object manager or the class
// of the field, so we store that information in the reader.
// The reader is cached so that two choice lists for the same class
// (and hence with the same reader) can successfully be cached.
if (!isset($idReaders[$hash])) {
$classMetadata = $options['em']->getClassMetadata($options['class']);
$idReaders[$hash] = new IdReader($options['em'], $classMetadata);
}
return $idReaders[$hash];
};
$resolver->setDefaults(array(
'em' => null,
'property' => null, // deprecated, use "choice_label"
@ -268,17 +287,19 @@ abstract class DoctrineType extends AbstractType
'choice_label' => $choiceLabel,
'choice_name' => $choiceName,
'choice_value' => $choiceValue,
'id_reader' => $idReader,
'id_reader' => null, // internal
));
$resolver->setRequired(array('class'));
$resolver->setNormalizer('em', $emNormalizer);
$resolver->setNormalizer('property', $propertyNormalizer);
$resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
$resolver->setNormalizer('loader', $loaderNormalizer);
$resolver->setNormalizer('id_reader', $idReaderNormalizer);
$resolver->setAllowedTypes('em', array('null', 'string', 'Doctrine\Common\Persistence\ObjectManager'));
$resolver->setAllowedTypes('loader', array('null', 'Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface'));
$resolver->setAllowedTypes('query_builder', array('null', 'callable', 'Doctrine\ORM\QueryBuilder'));
}
/**

View File

@ -20,9 +20,9 @@ class EntityType extends DoctrineType
/**
* Return the default loader object.
*
* @param ObjectManager $manager
* @param QueryBuilder|\Closure $queryBuilder
* @param string $class
* @param ObjectManager $manager
* @param QueryBuilder $queryBuilder
* @param string $class
*
* @return ORMQueryBuilderLoader
*/

View File

@ -51,10 +51,10 @@ class ArrayChoiceList implements ChoiceListInterface
*
* The given choice array must have the same array keys as the value array.
*
* @param array $choices The selectable choices
* @param callable $value The callable for creating the value for a
* choice. If `null` is passed, incrementing
* integers are used as values
* @param array $choices The selectable choices
* @param callable|null $value The callable for creating the value for a
* choice. If `null` is passed, incrementing
* integers are used as values
*/
public function __construct(array $choices, $value = null)
{

View File

@ -41,7 +41,7 @@ use Symfony\Component\Form\Exception\InvalidArgumentException;
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Added for backwards compatibility in Symfony 2.7, to be removed
* in Symfony 3.0.
* in Symfony 3.0. Use {@link ArrayChoiceList} instead.
*/
class ArrayKeyChoiceList extends ArrayChoiceList
{
@ -113,6 +113,8 @@ class ArrayKeyChoiceList extends ArrayChoiceList
}
parent::__construct($choices, $value);
trigger_error('The '.__CLASS__.' class was added for backwards compatibility in version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\ArrayChoiceList instead.', E_USER_DEPRECATED);
}
/**

View File

@ -91,10 +91,6 @@ class CachingFactoryDecorator implements ChoiceListFactoryInterface
*/
public function createListFromChoices($choices, $value = null)
{
if (!is_array($choices) && !$choices instanceof \Traversable) {
throw new UnexpectedTypeException($choices, 'array or \Traversable');
}
if ($choices instanceof \Traversable) {
$choices = iterator_to_array($choices);
}
@ -124,10 +120,6 @@ class CachingFactoryDecorator implements ChoiceListFactoryInterface
*/
public function createListFromFlippedChoices($choices, $value = null)
{
if (!is_array($choices) && !$choices instanceof \Traversable) {
throw new UnexpectedTypeException($choices, 'array or \Traversable');
}
if ($choices instanceof \Traversable) {
$choices = iterator_to_array($choices);
}

View File

@ -85,10 +85,6 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
*/
public function createListFromChoices($choices, $value = null)
{
if (!is_array($choices) && !$choices instanceof \Traversable) {
throw new UnexpectedTypeException($choices, 'array or \Traversable');
}
if ($choices instanceof \Traversable) {
$choices = iterator_to_array($choices);
}
@ -109,10 +105,6 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
*/
public function createListFromFlippedChoices($choices, $value = null)
{
if (!is_array($choices) && !$choices instanceof \Traversable) {
throw new UnexpectedTypeException($choices, 'array or \Traversable');
}
if ($choices instanceof \Traversable) {
$choices = iterator_to_array($choices);
}
@ -140,10 +132,6 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
*/
public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null)
{
if (null !== $value && !is_callable($value)) {
throw new UnexpectedTypeException($value, 'null or callable');
}
return new LazyChoiceList($loader, $value);
}
@ -152,26 +140,6 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
*/
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
{
if (null !== $preferredChoices && !is_array($preferredChoices) && !is_callable($preferredChoices)) {
throw new UnexpectedTypeException($preferredChoices, 'null, array or callable');
}
if (null !== $label && !is_callable($label)) {
throw new UnexpectedTypeException($label, 'null or callable');
}
if (null !== $index && !is_callable($index)) {
throw new UnexpectedTypeException($index, 'null or callable');
}
if (null !== $groupBy && !is_array($groupBy) && !$groupBy instanceof \Traversable && !is_callable($groupBy)) {
throw new UnexpectedTypeException($groupBy, 'null, array, \Traversable or callable');
}
if (null !== $attr && !is_array($attr) && !is_callable($attr)) {
throw new UnexpectedTypeException($attr, 'null, array or callable');
}
// Backwards compatibility
if ($list instanceof LegacyChoiceListInterface && null === $preferredChoices
&& null === $label && null === $index && null === $groupBy && null === $attr) {
@ -247,7 +215,7 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
);
}
// Remove any empty group views that may have been created by
// Remove any empty group view that may have been created by
// addChoiceViewGroupedBy()
foreach ($preferredViews as $key => $view) {
if ($view instanceof ChoiceGroupView && 0 === count($view->choices)) {

View File

@ -153,16 +153,12 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
/**
* {@inheritdoc}
*
* @param ChoiceListInterface $list The choice list
* @param null|array|callable|PropertyPath $preferredChoices The preferred choices
* @param null|callable|PropertyPath $label The callable or path
* generating the choice labels
* @param null|callable|PropertyPath $index The callable or path
* generating the view indices
* @param null|array|\Traversable|callable|PropertyPath $groupBy The callable or path
* generating the group names
* @param null|array|callable|PropertyPath $attr The callable or path
* generating the HTML attributes
* @param ChoiceListInterface $list The choice list
* @param null|array|callable|string|PropertyPath $preferredChoices The preferred choices
* @param null|callable|string|PropertyPath $label The callable or path generating the choice labels
* @param null|callable|string|PropertyPath $index The callable or path generating the view indices
* @param null|array|\Traversable|callable|string|PropertyPath $groupBy The callable or path generating the group names
* @param null|array|callable|string|PropertyPath $attr The callable or path generating the HTML attributes
*
* @return ChoiceListView The choice list view
*/

View File

@ -51,7 +51,7 @@ class LazyChoiceList implements ChoiceListInterface
private $compareByValue;
/**
* @var ChoiceListInterface
* @var ChoiceListInterface|null
*/
private $loadedList;

View File

@ -35,7 +35,7 @@ use Symfony\Component\Form\Extension\Core\View\ChoiceView;
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use {@link \Symfony\Component\Form\ArrayChoiceList\ArrayChoiceList} instead.
* Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList} instead.
*/
class ChoiceList implements ChoiceListInterface
{
@ -92,6 +92,8 @@ class ChoiceList implements ChoiceListInterface
}
$this->initialize($choices, $labels, $preferredChoices);
trigger_error('The '.__CLASS__.' class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\ArrayChoiceList instead.', E_USER_DEPRECATED);
}
/**

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface as BaseChoiceListInterface;
/**
* Contains choices that can be selected in a form field.
*
@ -27,10 +29,9 @@ namespace Symfony\Component\Form\Extension\Core\ChoiceList;
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use {@link \Symfony\Component\Form\ArrayChoiceList\ChoiceListInterface}
* instead.
* Use {@link BaseChoiceListInterface} instead.
*/
interface ChoiceListInterface extends \Symfony\Component\Form\ChoiceList\ChoiceListInterface
interface ChoiceListInterface extends BaseChoiceListInterface
{
/**
* Returns the choice views of the preferred choices as nested array with

View File

@ -23,7 +23,7 @@ use Symfony\Component\Form\Exception\InvalidArgumentException;
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use {@link \Symfony\Component\Form\ArrayChoiceList\LazyChoiceList}
* Use {@link \Symfony\Component\Form\ChoiceList\LazyChoiceList}
* instead.
*/
abstract class LazyChoiceList implements ChoiceListInterface
@ -35,6 +35,11 @@ abstract class LazyChoiceList implements ChoiceListInterface
*/
private $choiceList;
public function __construct()
{
trigger_error('The '.__CLASS__.' class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\LazyChoiceList instead.', E_USER_DEPRECATED);
}
/**
* {@inheritdoc}
*/

View File

@ -34,7 +34,7 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use {@link \Symfony\Component\Form\ArrayChoiceList\ArrayChoiceList}
* Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList}
* instead.
*/
class ObjectChoiceList extends ChoiceList
@ -97,6 +97,8 @@ class ObjectChoiceList extends ChoiceList
$this->valuePath = null !== $valuePath ? new PropertyPath($valuePath) : null;
parent::__construct($choices, array(), $preferredChoices);
trigger_error('The '.__CLASS__.' class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\ArrayChoiceList instead.', E_USER_DEPRECATED);
}
/**

View File

@ -30,7 +30,7 @@ namespace Symfony\Component\Form\Extension\Core\ChoiceList;
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use {@link \Symfony\Component\Form\ArrayChoiceList\ArrayKeyChoiceList}
* Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList}
* instead.
*/
class SimpleChoiceList extends ChoiceList

View File

@ -58,8 +58,6 @@ class RadioListMapper implements DataMapperInterface
foreach ($radios as $radio) {
if ($radio->getData()) {
if ('placeholder' === $radio->getName()) {
$choice = null;
return;
}

View File

@ -19,7 +19,7 @@ use Symfony\Component\Form\Exception\TransformationFailedException;
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use {@link \Symfony\Component\Form\ArrayChoiceList\LazyChoiceList}
* Use {@link \Symfony\Component\Form\ChoiceList\LazyChoiceList}
* instead.
*/
class ChoiceToBooleanArrayTransformer implements DataTransformerInterface
@ -38,6 +38,8 @@ class ChoiceToBooleanArrayTransformer implements DataTransformerInterface
{
$this->choiceList = $choiceList;
$this->placeholderPresent = $placeholderPresent;
trigger_error('The class '.__CLASS__.' is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\LazyChoiceList instead.', E_USER_DEPRECATED);
}
/**

View File

@ -19,7 +19,7 @@ use Symfony\Component\Form\Exception\TransformationFailedException;
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use {@link \Symfony\Component\Form\ArrayChoiceList\LazyChoiceList}
* Use {@link \Symfony\Component\Form\ChoiceList\LazyChoiceList}
* instead.
*/
class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
@ -29,6 +29,8 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
public function __construct(ChoiceListInterface $choiceList)
{
$this->choiceList = $choiceList;
trigger_error('The class '.__CLASS__.' is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\LazyChoiceList instead.', E_USER_DEPRECATED);
}
/**

View File

@ -22,6 +22,10 @@ use Symfony\Component\Form\FormEvents;
* indexed array.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use {@link \Symfony\Component\Form\Extension\Core\DataMapper\CheckboxListMapper}
* instead.
*/
class FixCheckboxInputListener implements EventSubscriberInterface
{
@ -35,6 +39,8 @@ class FixCheckboxInputListener implements EventSubscriberInterface
public function __construct(ChoiceListInterface $choiceList)
{
$this->choiceList = $choiceList;
trigger_error('The class '.__CLASS__.' is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\Extension\Core\DataMapper\CheckboxListMapper instead.', E_USER_DEPRECATED);
}
public function preSubmit(FormEvent $event)

View File

@ -21,6 +21,10 @@ use Symfony\Component\Form\FormEvents;
* to an array.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use {@link \Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper}
* instead.
*/
class FixRadioInputListener implements EventSubscriberInterface
{
@ -38,6 +42,8 @@ class FixRadioInputListener implements EventSubscriberInterface
{
$this->choiceList = $choiceList;
$this->placeholderPresent = $placeholderPresent;
trigger_error('The class '.__CLASS__.' is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper instead.', E_USER_DEPRECATED);
}
public function preSubmit(FormEvent $event)

View File

@ -233,15 +233,8 @@ class ChoiceType extends AbstractType
{
$choiceListFactory = $this->choiceListFactory;
$choiceList = function (Options $options) use ($choiceListFactory) {
$choiceList = function (Options $options, $choiceList) use ($choiceListFactory) {
if (null !== $options['choice_loader']) {
// Due to a bug in OptionsResolver, the choices haven't been
// validated yet at this point. Remove the if statement once that
// bug is resolved
if (!$options['choice_loader'] instanceof ChoiceLoaderInterface) {
return;
}
return $choiceListFactory->createListFromLoader(
$options['choice_loader'],
$options['choice_value']
@ -251,13 +244,6 @@ class ChoiceType extends AbstractType
// Harden against NULL values (like in EntityType and ModelType)
$choices = null !== $options['choices'] ? $options['choices'] : array();
// Due to a bug in OptionsResolver, the choices haven't been
// validated yet at this point. Remove the if statement once that
// bug is resolved
if (!is_array($choices) && !$choices instanceof \Traversable) {
return;
}
// BC when choices are in the keys, not in the values
if (!$options['choices_as_values']) {
return $choiceListFactory->createListFromFlippedChoices($choices, $options['choice_value']);
@ -283,6 +269,13 @@ class ChoiceType extends AbstractType
return $options['empty_value'];
};
// deprecation note
$choiceListNormalizer = function (Options $options, $choiceList) {
trigger_error('The "choice_list" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_loader" instead.', E_USER_DEPRECATED);
return $choiceList;
};
$placeholderNormalizer = function (Options $options, $placeholder) {
if ($options['multiple']) {
// never use an empty value for this case
@ -327,6 +320,7 @@ class ChoiceType extends AbstractType
'data_class' => null,
));
$resolver->setNormalizer('choice_list', $choiceListNormalizer);
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);

View File

@ -11,12 +11,17 @@
namespace Symfony\Component\Form\Extension\Core\View;
use Symfony\Component\Form\ChoiceList\View\ChoiceView as BaseChoiceView;
/**
* Represents a choice in templates.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use {@link BaseChoiceView} instead.
*/
class ChoiceView extends \Symfony\Component\Form\ChoiceList\View\ChoiceView
class ChoiceView extends BaseChoiceView
{
/**
* Creates a new ChoiceView.
@ -28,5 +33,7 @@ class ChoiceView extends \Symfony\Component\Form\ChoiceList\View\ChoiceView
public function __construct($data, $value, $label)
{
parent::__construct($label, $value, $data);
trigger_error('The '.__CLASS__.' class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\View\ChoiceView instead.', E_USER_DEPRECATED);
}
}

View File

@ -34,14 +34,6 @@ class CachingFactoryDecoratorTest extends \PHPUnit_Framework_TestCase
$this->factory = new CachingFactoryDecorator($this->decoratedFactory);
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateFromChoicesFailsIfChoicesNotArrayOrTraversable()
{
$this->factory->createListFromChoices('foobar');
}
public function testCreateFromChoicesEmpty()
{
$list = new \stdClass();
@ -163,14 +155,6 @@ class CachingFactoryDecoratorTest extends \PHPUnit_Framework_TestCase
$this->assertSame($list2, $this->factory->createListFromChoices($choices, $closure2));
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateFromFlippedChoicesFailsIfChoicesNotArrayOrTraversable()
{
$this->factory->createListFromFlippedChoices('foobar');
}
public function testCreateFromFlippedChoicesEmpty()
{
$list = new \stdClass();

View File

@ -88,22 +88,6 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase
$this->factory = new DefaultChoiceListFactory();
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateFromChoicesFailsIfChoicesNotArrayOrTraversable()
{
$this->factory->createListFromChoices('foobar');
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateFromChoicesFailsIfValuesNotCallableOrString()
{
$this->factory->createListFromChoices(array(), new \stdClass());
}
public function testCreateFromChoicesEmpty()
{
$list = $this->factory->createListFromChoices(array());
@ -200,22 +184,6 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase
$this->assertObjectListWithCustomValues($list);
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateFromFlippedChoicesFailsIfChoicesNotArrayOrTraversable()
{
$this->factory->createListFromFlippedChoices('foobar');
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateFromFlippedChoicesFailsIfValuesNotCallableOrString()
{
$this->factory->createListFromFlippedChoices(array(), new \stdClass());
}
public function testCreateFromFlippedChoicesEmpty()
{
$list = $this->factory->createListFromFlippedChoices(array());
@ -345,56 +313,6 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(new LazyChoiceList($loader, $value), $list);
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateFromLoaderFailsIfValuesNotCallableOrString()
{
$loader = $this->getMock('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface');
$this->factory->createListFromLoader($loader, new \stdClass());
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateViewFailsIfPreferredChoicesInvalid()
{
$this->factory->createView($this->list, new \stdClass());
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateViewFailsIfLabelInvalid()
{
$this->factory->createView($this->list, null, new \stdClass());
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateViewFailsIfIndexInvalid()
{
$this->factory->createView($this->list, null, null, new \stdClass());
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateViewFailsIfGroupByInvalid()
{
$this->factory->createView($this->list, null, null, null, new \stdClass());
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testCreateViewFailsIfAttrInvalid()
{
$this->factory->createView($this->list, null, null, null, null, new \stdClass());
}
public function testCreateViewFlat()
{
$view = $this->factory->createView($this->list);