From d6179c830be7f2245ad56b6a800a33275a802689 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Thu, 26 Mar 2015 10:59:50 +0100 Subject: [PATCH] [Form] Fixed PR comments --- .../Form/ChoiceList/DoctrineChoiceLoader.php | 38 ++------- .../Form/ChoiceList/EntityChoiceList.php | 2 + .../Form/ChoiceList/ORMQueryBuilderLoader.php | 18 ++-- .../Doctrine/Form/Type/DoctrineType.php | 65 ++++++++++----- .../Bridge/Doctrine/Form/Type/EntityType.php | 6 +- .../Form/ChoiceList/ArrayChoiceList.php | 8 +- .../Form/ChoiceList/ArrayKeyChoiceList.php | 4 +- .../Factory/CachingFactoryDecorator.php | 8 -- .../Factory/DefaultChoiceListFactory.php | 34 +------- .../Factory/PropertyAccessDecorator.php | 16 ++-- .../Form/ChoiceList/LazyChoiceList.php | 2 +- .../Extension/Core/ChoiceList/ChoiceList.php | 4 +- .../Core/ChoiceList/ChoiceListInterface.php | 7 +- .../Core/ChoiceList/LazyChoiceList.php | 7 +- .../Core/ChoiceList/ObjectChoiceList.php | 4 +- .../Core/ChoiceList/SimpleChoiceList.php | 2 +- .../Core/DataMapper/RadioListMapper.php | 2 - .../ChoiceToBooleanArrayTransformer.php | 4 +- .../ChoicesToBooleanArrayTransformer.php | 4 +- .../FixCheckboxInputListener.php | 6 ++ .../EventListener/FixRadioInputListener.php | 6 ++ .../Form/Extension/Core/Type/ChoiceType.php | 24 ++---- .../Form/Extension/Core/View/ChoiceView.php | 9 +- .../Factory/CachingFactoryDecoratorTest.php | 16 ---- .../Factory/DefaultChoiceListFactoryTest.php | 82 ------------------- 25 files changed, 134 insertions(+), 244 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php index 4b10b45855..5456c0eedb 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php @@ -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) { diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php index f3d4ff48f6..1d4232306d 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php @@ -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); } /** diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php index 9d34601c9f..92f00cb243 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php @@ -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) { diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index 6020d95e92..b8d03c0eb1 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -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')); } /** diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php index 236b9290c7..87b3ee42cb 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php @@ -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 */ diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php index 515cd15a83..f55154b085 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php @@ -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) { diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php index 918c278f06..7973072f32 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php @@ -41,7 +41,7 @@ use Symfony\Component\Form\Exception\InvalidArgumentException; * @author Bernhard Schussek * * @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); } /** diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php b/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php index fb43ac8759..3a2702a335 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php @@ -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); } diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php index d974bf7d4f..31527a9f34 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -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)) { diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php b/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php index 131690a6ff..f6fd823784 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php @@ -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 */ diff --git a/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php b/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php index 3dea398c6d..092e2c4644 100644 --- a/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php @@ -51,7 +51,7 @@ class LazyChoiceList implements ChoiceListInterface private $compareByValue; /** - * @var ChoiceListInterface + * @var ChoiceListInterface|null */ private $loadedList; diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php index 2f7b287b63..817e03ec72 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php @@ -35,7 +35,7 @@ use Symfony\Component\Form\Extension\Core\View\ChoiceView; * @author Bernhard Schussek * * @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); } /** diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceListInterface.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceListInterface.php index 22354e09d8..aef70aef87 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceListInterface.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceListInterface.php @@ -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 * * @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 diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/LazyChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/LazyChoiceList.php index 24232bc1d6..f3a7cc028a 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/LazyChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/LazyChoiceList.php @@ -23,7 +23,7 @@ use Symfony\Component\Form\Exception\InvalidArgumentException; * @author Bernhard Schussek * * @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} */ diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php index 606de43af3..c356ce466b 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php @@ -34,7 +34,7 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface; * @author Bernhard Schussek * * @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); } /** diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php index 50a3eb5f4a..6dd8fb091e 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php @@ -30,7 +30,7 @@ namespace Symfony\Component\Form\Extension\Core\ChoiceList; * @author Bernhard Schussek * * @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 diff --git a/src/Symfony/Component/Form/Extension/Core/DataMapper/RadioListMapper.php b/src/Symfony/Component/Form/Extension/Core/DataMapper/RadioListMapper.php index aecdb2fad0..19db183a28 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataMapper/RadioListMapper.php +++ b/src/Symfony/Component/Form/Extension/Core/DataMapper/RadioListMapper.php @@ -58,8 +58,6 @@ class RadioListMapper implements DataMapperInterface foreach ($radios as $radio) { if ($radio->getData()) { if ('placeholder' === $radio->getName()) { - $choice = null; - return; } diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToBooleanArrayTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToBooleanArrayTransformer.php index a0b5039317..108c1ca6a3 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToBooleanArrayTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToBooleanArrayTransformer.php @@ -19,7 +19,7 @@ use Symfony\Component\Form\Exception\TransformationFailedException; * @author Bernhard Schussek * * @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); } /** diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php index c38c363329..a632bc03c7 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php @@ -19,7 +19,7 @@ use Symfony\Component\Form\Exception\TransformationFailedException; * @author Bernhard Schussek * * @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); } /** diff --git a/src/Symfony/Component/Form/Extension/Core/EventListener/FixCheckboxInputListener.php b/src/Symfony/Component/Form/Extension/Core/EventListener/FixCheckboxInputListener.php index 297987f799..85b08c7b32 100644 --- a/src/Symfony/Component/Form/Extension/Core/EventListener/FixCheckboxInputListener.php +++ b/src/Symfony/Component/Form/Extension/Core/EventListener/FixCheckboxInputListener.php @@ -22,6 +22,10 @@ use Symfony\Component\Form\FormEvents; * indexed array. * * @author Bernhard Schussek + * + * @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) diff --git a/src/Symfony/Component/Form/Extension/Core/EventListener/FixRadioInputListener.php b/src/Symfony/Component/Form/Extension/Core/EventListener/FixRadioInputListener.php index d5067b6e33..8641ea725d 100644 --- a/src/Symfony/Component/Form/Extension/Core/EventListener/FixRadioInputListener.php +++ b/src/Symfony/Component/Form/Extension/Core/EventListener/FixRadioInputListener.php @@ -21,6 +21,10 @@ use Symfony\Component\Form\FormEvents; * to an array. * * @author Bernhard Schussek + * + * @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) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 7e80a00bde..a950be8d89 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -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); diff --git a/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php b/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php index 65d7af2464..0cbeecab9f 100644 --- a/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php +++ b/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php @@ -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 + * + * @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); } } diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php index 031cced280..716468276a 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php @@ -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(); diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php index 360d46729f..a2b817ed8d 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php @@ -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);