8000 Fixed PR comments · symfony/symfony@89b30e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 89b30e3

Browse files
committed
Fixed PR comments
1 parent 04f6eea commit 89b30e3

18 files changed

+78
-208
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,12 @@ public function loadChoiceList($value = null)
9797
}
9898

9999
/**
100-
* Loads the values corresponding to the given objects.
101-
*
102-
* The values are returned with the same keys and in the same order as the
103-
* corresponding objects in the given array.
104-
*
105-
* Optionally, a callable can be passed for generating the choice values.
106-
* The callable receives the object as first and the array key as the second
107-
* argument.
108-
*
109-
* @param array $objects An array of objects. Non-existing objects in
110-
* this array are ignored
111-
* @param null|callable $value The callable generating the choice values
112-
*
113-
* @return string[] An array of choice values
100+
* {@inheritdoc}
114101
*/
115-
public function loadValuesForChoices(array $objects, $value = null)
102+
public function loadValuesForChoices(array $choices, $value = null)
116103
{
117104
// Performance optimization
118-
if (empty($objects)) {
105+
if (empty($choices)) {
119106
return array();
120107
}
121108

@@ -127,7 +114,7 @@ public function loadValuesForChoices(array $objects, $value = null)
127114
$values = array();
128115

129116
// Maintain order and indices of the given objects
130-
foreach ($objects as $i => $object) {
117+
foreach ($choices as $i => $object) {
131118
if ($object instanceof $this->class) {
132119
// Make sure to convert to the right format
133120
$values[$i] = (string) $this->idReader->getIdValue($object);
@@ -137,24 +124,11 @@ public function loadValuesForChoices(array $objects, $value = null)
137124
return $values;
138125
}
139126

140-
return $this->loadChoiceList($value)->getValuesForChoices($objects);
127+
return $this->loadChoiceList($value)->getValuesForChoices($choices);
141128
}
142129

143130
/**
144-
* Loads the objects corresponding to the given values.
145-
*
146-
* The objects are returned with the same keys and in the same order as the
147-
* corresponding values in the given array.
148-
*
149-
* Optionally, a callable can be passed for generating the choice values.
150-
* The callable receives the object as first and the array key as the second
151-
* argument.
152-
*
153-
* @param string[] $values An array of choice values. Non-existing
154-
* values in this array are ignored
155-
* @param null|callable $value The callable generating the choice values
156-
*
157-
* @return array An array of objects
131+
* {@inheritdoc}
158132
*/
159133
public function loadChoicesForValues(array $values, $value = null)
160134
{

src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ public function __construct(ObjectManager $manager, $class, $labelPath = null, E
129129
}
130130

131131
parent::__construct($entities, $labelPath, $preferredEntities, $groupPath, null, $propertyAccessor);
132+
133+
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);
132134
}
133135

134136
/**

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,6 @@ public function configureOptions(OptionsResolver $resolver)
116116
$choiceLoaders = &$this->choiceLoaders;
117117
$type = $this;
118118

119-
$idReader = function (Options $options) use (&$idReaders) {
120-
$hash = CachingFactoryDecorator::generateHash(array(
121-
$options['em'],
122-
$options['class'],
123-
));
124-
125-
// The ID reader is a utility that is needed to read the object IDs
126-
// when generating the field values. The callback generating the
127-
// field values has no access to the object manager or the class
128-
// of the field, so we store that information in the reader.
129-
// The reader is cached so that two choice lists for the same class
130-
// (and hence with the same reader) can successfully be cached.
131-
if (!isset($idReaders[$hash])) {
132-
$classMetadata = $options['em']->getClassMetadata($options['class']);
133-
$idReaders[$hash] = new IdReader($options['em'], $classMetadata);
134-
}
135-
136-
return $idReaders[$hash];
137-
};
138-
139119
$choiceLoader = function (Options $options) use ($choiceListFactory, &$choiceLoaders, $type) {
140120
// Unless the choices are given explicitly, load them on demand
141121
if (null === $options['choices']) {
@@ -257,6 +237,28 @@ public function configureOptions(OptionsResolver $resolver)
257237
return $queryBuilder;
258238
};
259239

240+
// Set the "id_reader" option via the normalizer. This option is not
241+
// supposed to be set by the user.
242+
$idReaderNormalizer = function (Options $options) use (&$idReaders) {
243+
$hash = CachingFactoryDecorator::generateHash(array(
244+
$options['em'],
245+
$options['class'],
246+
));
247+
248+
// The ID reader is a utility that is needed to read the object IDs
249+
// when generating the field values. The callback generating the
250+
// field values has no access to the object manager or the class
251+
// of the field, so we store that information in the reader.
252+
// The reader is cached so that two choice lists for the same class
253+
// (and hence with the same reader) can successfully be cached.
254+
if (!isset($idReaders[$hash])) {
255+
$classMetadata = $options['em']->getClassMetadata($options['class']);
256+
$idReaders[$hash] = new IdReader($options['em'], $classMetadata);
257+
}
258+
259+
return $idReaders[$hash];
260+
};
261+
260262
$resolver->setDefaults(array(
261263
'em' => null,
262264
'property' => null, // deprecated, use "choice_label"
@@ -268,13 +270,14 @@ public function configureOptions(OptionsResolver $resolver)
268270
'choice_label' => $choiceLabel,
269271
'choice_name' => $choiceName,
270272
'choice_value' => $choiceValue,
271-
'id_reader' => $idReader,
273+
'id_reader' => null, // internal
272274
));
273275

274276
$resolver->setRequired(array('class'));
275277

276278
$resolver->setNormalizer('em', $emNormalizer);
277279
$resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
280+
$resolver->setNormalizer('id_reader', $idReaderNormalizer);
278281

279282
$resolver->setAllowedTypes('em', array('null', 'string', 'Doctrine\Common\Persistence\ObjectManager'));
280283
$resolver->setAllowedTypes('loader', array('null', 'Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface'));

src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ class ArrayChoiceList implements ChoiceListInterface
5151
*
5252
* The given choice array must have the same array keys as the value array.
5353
*
54-
* @param array $choices The selectable choices
55-
* @param callable $value The callable for creating the value for a
56-
* choice. If `null` is passed, incrementing
57-
* integers are used as values
54+
* @param array $choices The selectable choices
55+
* @param callable|null $value The callable for creating the value for a
56+
* choice. If `null` is passed, incrementing
57+
* integers are used as values
5858
*/
5959
public function __construct(array $choices, $value = null)
6060
{

src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @author Bernhard Schussek <bschussek@gmail.com>
4242
*
4343
* @deprecated Added for backwards compatibility in Symfony 2.7, to be removed
44-
* in Symfony 3.0.
44+
* in Symfony 3.0. Use {@link ArrayChoiceList} instead.
4545
*/
4646
class ArrayKeyChoiceList extends ArrayChoiceList
4747
{
@@ -113,6 +113,8 @@ public function __construct(array $choices, $value = null)
113113
}
114114

115115
parent::__construct($choices, $value);
116+
117+
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);
116118
}
117119

118120
/**

src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ public static function flattenFlipped(array $array, &$output)
8585
*/
8686
public function createListFromChoices($choices, $value = null)
8787
{
88-
if (!is_array($choices) && !$choices instanceof \Traversable) {
89-
throw new UnexpectedTypeException($choices, 'array or \Traversable');
90-
}
91-
9288
if ($choices instanceof \Traversable) {
9389
$choices = iterator_to_array($choices);
9490
}
@@ -109,10 +105,6 @@ public function createListFromChoices($choices, $value = null)
1091 10000 05
*/
110106
public function createListFromFlippedChoices($choices, $value = null)
111107
{
112-
if (!is_array($choices) && !$choices instanceof \Traversable) {
113-
throw new UnexpectedTypeException($choices, 'array or \Traversable');
114-
}
115-
116108
if ($choices instanceof \Traversable) {
117109
$choices = iterator_to_array($choices);
118110
}
@@ -140,10 +132,6 @@ public function createListFromFlippedChoices($choices, $value = null)
140132
*/
141133
public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null)
142134
{
143-
if (null !== $value && !is_callable($value)) {
144-
throw new UnexpectedTypeException($value, 'null or callable');
145-
}
146-
147135
return new LazyChoiceList($loader, $value);
148136
}
149137

@@ -152,26 +140,6 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul
152140
*/
153141
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
154142
{
155-
if (null !== $preferredChoices && !is_array($preferredChoices) && !is_callable($preferredChoices)) {
156-
throw new UnexpectedTypeException($preferredChoices, 'null, array or callable');
157-
}
158-
159-
if (null !== $label && !is_callable($label)) {
160-
throw new UnexpectedTypeException($label, 'null or callable');
161-
}
162-
163-
if (null !== $index && !is_callable($index)) {
164-
throw new UnexpectedTypeException($index, 'null or callable');
165-
}
166-
167-
if (null !== $groupBy && !is_array($groupBy) && !$groupBy instanceof \Traversable && !is_callable($groupBy)) {
168-
throw new UnexpectedTypeException($groupBy, 'null, array, \Traversable or callable');
169-
}
170-
171-
if (null !== $attr && !is_array($attr) && !is_callable($attr)) {
172-
throw new UnexpectedTypeException($attr, 'null, array or callable');
173-
}
174-
175143
// Backwards compatibility
176144
if ($list instanceof LegacyChoiceListInterface && null === $preferredChoices
177145
&& null === $label && null === $index && null === $groupBy && null === $attr) {

src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,12 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul
153153
/**
154154
* {@inheritdoc}
155155
*
156-
* @param ChoiceListInterface $list The choice list
157-
* @param null|array|callable|PropertyPath $preferredChoices The preferred choices
158-
* @param null|callable|PropertyPath $label The callable or path
159-
* generating the choice labels
160-
* @param null|callable|PropertyPath $index The callable or path
161-
* generating the view indices
162-
* @param null|array|\Traversable|callable|PropertyPath $groupBy The callable or path
163-
* generating the group names
164-
* @param null|array|callable|PropertyPath $attr The callable or path
165-
* generating the HTML attributes
156+
* @param ChoiceListInterface $list The choice list
157+
* @param null|array|callable|string|PropertyPath $preferredChoices The preferred choices
158+
* @param null|callable|string|PropertyPath $label The callable or path generating the choice labels
159+
* @param null|callable|string|PropertyPath $index The callable or path generating the view indices
160+
* @param null|array|\Traversable|callable|string|PropertyPath $groupBy The callable or path generating the group names
161+
* @param null|array|callable|string|PropertyPath $attr The callable or path generating the HTML attributes
166162
*
167163
* @return ChoiceListView The choice list view
168164
*/

src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LazyChoiceList implements ChoiceListInterface
5151
private $compareByValue;
5252

5353
/**
54-
* @var ChoiceListInterface
54+
* @var ChoiceListInterface|null
5555
*/
5656
private $loadedList;
5757

src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @author Bernhard Schussek <bschussek@gmail.com>
3636
*
3737
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
38-
* Use {@link \Symfony\Component\Form\ArrayChoiceList\ArrayChoiceList} instead.
38+
* Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList} instead.
3939
*/
4040
class ChoiceList implements ChoiceListInterface
4141
{
@@ -92,6 +92,8 @@ public function __construct($choices, array $labels, array $preferredChoices = a
9292
}
9393

9494
$this->initialize($choices, $labels, $preferredChoices);
95+
96+
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);
9597
}
9698

9799
/**

src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceListInterface.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
1313

14+
use Symfony\Component\Form\ChoiceList\ChoiceListInterface as BaseChoiceListInterface;
15+
1416
/**
1517
* Contains choices that can be selected in a form field.
1618
*
@@ -27,10 +29,9 @@
2729
* @author Bernhard Schussek <bschussek@gmail.com>
2830
*
2931
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
30-
* Use {@link \Symfony\Component\Form\ArrayChoiceList\ChoiceListInterface}
31-
* instead.
32+
* Use {@link BaseChoiceListInterface} instead.
3233
*/
33-
interface ChoiceListInterface extends \Symfony\Component\Form\ChoiceList\ChoiceListInterface
34+
interface ChoiceListInterface extends BaseChoiceListInterface
3435
{
3536
/**
3637
* Returns the choice views of the preferred choices as nested array with

src/Symfony/Component/Form/Extension/Core/ChoiceList/LazyChoiceList.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @author Bernhard Schussek <bschussek@gmail.com>
2424
*
2525
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
26-
* Use {@link \Symfony\Component\Form\ArrayChoiceList\LazyChoiceList}
26+
* Use {@link \Symfony\Component\Form\ChoiceList\LazyChoiceList}
2727
* instead.
2828
*/
2929
abstract class LazyChoiceList implements ChoiceListInterface
@@ -35,6 +35,11 @@ abstract class LazyChoiceList implements ChoiceListInterface
3535
*/
3636
private $choiceList;
3737

38+
public function __construct()
39+
{
40+
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);
41+
}
42+
3843
/**
3944
* {@inheritdoc}
4045
*/

src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @author Bernhard Schussek <bschussek@gmail.com>
3535
*
3636
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
37-
* Use {@link \Symfony\Component\Form\ArrayChoiceList\ArrayChoiceList}
37+
* Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList}
3838
* instead.
3939
*/
4040
class ObjectChoiceList extends ChoiceList
@@ -97,6 +97,8 @@ public function __construct($choices, $labelPath = null, array $preferredChoices
9797
$this->valuePath = null !== $valuePath ? new PropertyPath($valuePath) : null;
9898

9999
parent::__construct($choices, array(), $preferredChoices);
100+
101+
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);
100102
}
101103

102104
/**

src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @author Bernhard Schussek <bschussek@gmail.com>
3131
*
3232
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
33-
* Use {@link \Symfony\Component\Form\ArrayChoiceList\ArrayKeyChoiceList}
33+
* Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList}
3434
* instead.
3535
*/
3636
class SimpleChoiceList extends ChoiceList

src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToBooleanArrayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @author Bernhard Schussek <bschussek@gmail.com>
2020
*
2121
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
22-
* Use {@link \Symfony\Component\Form\ArrayChoiceList\LazyChoiceList}
22+
* Use {@link \Symfony\Component\Form\ChoiceList\LazyChoiceList}
2323
* instead.
2424
*/
2525
class ChoiceToBooleanArrayTransformer implements DataTransformerInterface

src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @author Bernhard Schussek <bschussek@gmail.com>
2020
*
2121
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
22-
* Use {@link \Symfony\Component\Form\ArrayChoiceList\LazyChoiceList}
22+
* Use {@link \Symfony\Component\Form\ChoiceList\LazyChoiceList}
2323
* instead.
2424
*/
2525
class ChoicesToBooleanArrayTransformer implements DataTransformerInterface

0 commit comments

Comments
 (0)
0