8000 fixup · symfony/symfony@f4a2b42 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4a2b42

Browse files
committed
fixup
1 parent 1700f87 commit f4a2b42

File tree

14 files changed

+322
-219
lines changed

14 files changed

+322
-219
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ public function configureOptions(OptionsResolver $resolver)
121121
$vary = [$options['em'], $options['class']];
122122

123123
// also if concrete Type can return important QueryBuilder parts to generate
124-
// hash key we go for it as well
125-
if ($options['query_builder'] && null !== $qbParts = $this->getQueryBuilderPartsForCachingHash($options['query_builder'])) {
126-
$vary[] = $qbParts;
124+
// hash key we go for it as well, otherwise fallback on the instance
125+
if ($options['query_builder']) {
126+
$vary[] = $this->getQueryBuilderPartsForCachingHash($options['query_builder']) ?? $options['query_builder'];
127127
}
128128

129129
return ChoiceList::loader($this, new DoctrineChoiceLoader(
@@ -147,7 +147,7 @@ public function configureOptions(OptionsResolver $resolver)
147147
// field name. We can only use numeric IDs as names, as we cannot
148148
// guarantee that a non-numeric ID contains a valid form name
149149
if ($options['id_reader'] instanceof IdReader && $options['id_reader']->isIntId()) {
150-
return ChoiceList::fieldName($this, [__CLASS__, 'createChoiceName'], $options['id_reader']);
150+
return ChoiceList::fieldName($this, [__CLASS__, 'createChoiceName']);
151151
}
152152

153153
// Otherwise, an incrementing integer is used as name automatically
@@ -246,7 +246,6 @@ public function getParent()
246246

247247
public function reset()
248248
{
249-
$this->idReaders = [];
250249
$this->entityLoaders = [];
251250
}
252251

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,11 @@ public function testSubmitSingleNonExpandedStringCastableIdentifier()
582582
}
583583

584584
/**
585+
* In Symfony 6.0 keep the test as is.
586+
*
585587
* @group legacy
586588
*
587-
* @expectedDeprecation Implicitly cached choice lists are deprecated since 5.1. Use one of "Symfony\Component\Form\ChoiceList\ChoiceList" methods instead to define choice options as of 6.0.
589+
* @expectedDeprecation Implicitly caching choice lists with dynamic options are deprecated since 5.1. Use one of "Symfony\Component\Form\ChoiceList\ChoiceList" methods to define them instead.
588590
*/
589591
public function testSubmitSingleStringCastableIdentifierExpanded()
590592
{
@@ -668,9 +670,11 @@ public function testSubmitMultipleNonExpandedStringCastableIdentifier()
668670
}
669671

670672
/**
673+
* In Symfony 6.0 keep the test as is.
674+
*
671675
* @group legacy
672676
*
673-
* @expectedDeprecation Implicitly cached choice lists are deprecated since 5.1. Use one of "Symfony\Component\Form\ChoiceList\ChoiceList" methods instead to define choice options as of 6.0.
677+
* @expectedDeprecation Implicitly caching choice lists with dynamic options are deprecated since 5.1. Use one of "Symfony\Component\Form\ChoiceList\ChoiceList" methods to define them instead.
674678
*/
675679
public function testSubmitMultipleStringCastableIdentifierExpanded()
676680
{
@@ -727,9 +731,12 @@ public function testOverrideChoices()
727731
}
728732

729733
/**
734+
* In Symfony 6.0 keep the test as is.
735+
*
730736
* @group legacy
731737
*
732-
* @expectedDeprecation Implicitly cached choice lists are deprecated since 5.1. No list will be cached in 6.0, use "Symfony\Component\Form\ChoiceList\Factory\Cache\ChoiceValue" instead to define the choice value.
738+
* @expectedDeprecation Implicitly caching choice lists per value has been deprecated since 5.1. Use "Symfony\Component\Form\ChoiceList\ChoiceList::value()" to wrap the callable instead.
739+
* @expectedDeprecation Implicitly caching choice lists with dynamic options are deprecated since 5.1. Use one of "Symfony\Component\Form\ChoiceList\ChoiceList" methods to define them instead.
733740
*/
734741
public function testOverrideChoicesValues()
735742
{
@@ -754,9 +761,12 @@ public function testOverrideChoicesValues()
754761
}
755762

756763
/**
764+
* In Symfony 6.0 keep the test as is.
765+
*
757766
* @group legacy
758767
*
759-
* @expectedDeprecation Implicitly cached choice lists are deprecated since 5.1. No list will be cached in 6.0, use "Symfony\Component\Form\ChoiceList\Factory\Cache\ChoiceValue" instead to define the choice value.
768+
* @expectedDeprecation Implicitly caching choice lists per value has been deprecated since 5.1. Use "Symfony\Component\Form\ChoiceList\ChoiceList::value()" to wrap the callable instead.
769+
* @expectedDeprecation Implicitly caching choice lists with dynamic options are deprecated since 5.1. Use one of "Symfony\Component\Form\ChoiceList\ChoiceList" methods to define them instead.
760770
*/
761771
public function testOverrideChoicesValuesWithCallable()
762772
{

src/Symfony/Component/Form/ChoiceList/Factory/Cache/AbstractStaticCallback.php renamed to src/Symfony/Component/Form/ChoiceList/Factory/Cache/AbstractStaticOption.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,53 @@
1212
namespace Symfony\Component\Form\ChoiceList\Factory\Cache;
1313

1414
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
15+
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
16+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
1517
use Symfony\Component\Form\FormTypeExtensionInterface;
1618
use Symfony\Component\Form\FormTypeInterface;
1719

1820
/**
19-
* A template for static callbacks used by {@see CachingFactoryDecorator}.
21+
* A template decorator for static {@see ChoiceType} options.
22+
*
23+
* Used as fly weight by {@see CachingFactoryDecorator}.
2024
*
2125
* @internal
2226
*
2327
* @author Jules Pietri <jules@heahprod.com>
2428
*/
25-
abstract class AbstractStaticCallback
29+
abstract class AbstractStaticOption
2630
{
27-
private static $callbacks = [];
31+
private static $options = [];
2832

29-
/** @var callable|string|array|\Closure */
30-
private $callback;
33+
/** @var bool|callable|string|array|\Closure|ChoiceLoaderInterface */
34+
private $option;
3135

3236
/**
3337
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a list
34-
* @param callable $callback Any pseudo callable to create choice list property
35-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the callback
38+
* @param mixed $option Any pseudo callable, array, sring to create choice list property
39+
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option
3640
*/
37-
final public function __construct($formType, $callback, $vary = null)
41+
final public function __construct($formType, $option, $vary = null)
3842
{
3943
if (!$formType instanceof FormTypeInterface && !$formType instanceof FormTypeExtensionInterface) {
4044
throw new \TypeError(sprintf('Expected an instance of "%s" or "%s", but got "%s".', FormTypeInterface::class, FormTypeExtensionInterface::class, \is_object($formType) ? \get_class($formType) : \gettype($formType)));
4145
}
4246

43-
$hash = CachingFactoryDecorator::generateHash($vary ? [$formType, $vary] : $formType);
44-
45-
if (empty(self::$callbacks[static::class][$hash])) {
46-
self::$callbacks[static::class][$hash] = $callback;
47-
}
47+
$hash = CachingFactoryDecorator::generateHash([static::class, $formType, $vary]);
4848

49-
$this->callback = self::$callbacks[static::class][$hash];
49+
$this->option = self::$options[$hash] ?? self::$options[$hash] = $option;
5050
}
5151

5252
/**
53-
* @return callable
53+
* @return mixed
5454
*/
55-
final public function getCallback()
55+
final public function getOption()
5656
{
57-
return $this->callback;
57+
return $this->option;
5858
}
5959

6060
final public static function reset(): void
6161
{
62-
self::$callbacks = [];
62+
self::$options = [];
6363
}
6464
}

src/Symfony/Component/Form/ChoiceList/Factory/Cache/ChoiceAttr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
*
2121
* @author Jules Pietri <jules@heahprod.com>
2222
*/
23-
final class ChoiceAttr extends AbstractStaticCallback
23+
final class ChoiceAttr extends AbstractStaticOption
2424
{
2525
}

src/Symfony/Component/Form/ChoiceList/Factory/Cache/ChoiceFieldName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
*
2121
* @author Jules Pietri <jules@heahprod.com>
2222
*/
23-
final class ChoiceFieldName extends AbstractStaticCallback
23+
final class ChoiceFieldName extends AbstractStaticOption
2424
{
2525
}

src/Symfony/Component/Form/ChoiceList/Factory/Cache/ChoiceLabel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
*
2121
* @author Jules Pietri <jules@heahprod.com>
2222
*/
23-
final class ChoiceLabel extends AbstractStaticCallback
23+
final class ChoiceLabel extends AbstractStaticOption
2424
{
2525
}

src/Symfony/Component/Form/ChoiceList/Factory/Cache/ChoiceLoader.php

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
namespace Symfony\Component\Form\ChoiceList\Factory\Cache;
1313

1414
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
15-
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
16-
use Symfony\Component\Form\FormTypeExtensionInterface;
17-
use Symfony\Component\Form\FormTypeInterface;
1815

1916
/**
2017
* A FlyWeight for types using static loaders, used by {@see CachingFactoryDecorator}.
@@ -23,60 +20,6 @@
2320
*
2421
* @author J 10000 ules Pietri <jules@heahprod.com>
2522
*/
26-
final class ChoiceLoader implements ChoiceLoaderInterface
23+
final class ChoiceLoader extends AbstractStaticOption
2724
{
28-
private static $loaders = [];
29-
30-
/** @var ChoiceLoaderInterface */
31-
private $loader;
32-
33-
/**
34-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a list
35-
* @param ChoiceLoaderInterface $loader A static loader used by the type
36-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the loader
37-
*/
38-
public function __construct($formType, ChoiceLoaderInterface $loader, $vary = null)
39-
{
40-
if (!$formType instanceof FormTypeInterface && !$formType instanceof FormTypeExtensionInterface) {
41-
throw new \TypeError(sprintf('Expected an instance of "%s" or "%s", but got "%s".', FormTypeInterface::class, FormTypeExtensionInterface::class, \is_object($formType) ? \get_class($formType) : \gettype($formType)));
42-
}
43-
44-
$hash = CachingFactoryDecorator::generateHash($vary ? [$formType, $vary] : $formType);
45-
46-
$this->loader = self::$loaders[$hash] ?? (self::$loaders[$hash] = $loader);
47-
}
48-
49-
public function getLoader(): ChoiceLoaderInterface
50-
{
51-
return $this->loader;
52-
}
53-
54-
/**
55-
* {@inheritdoc}
56-
*/
57-
public function loadChoiceList(callable $value = null)
58-
{
59-
return $this->loader->loadChoiceList($value);
60-
}
61-
62-
/**
63-
* {@inheritdoc}
64-
*/
65-
public function loadChoicesForValues(array $values, callable $value = null)
66-
{
67-
return $this->loader->loadChoicesForValues($values, $value);
68-
}
69-
70-
/**
71-
* {@inheritdoc}
72-
*/
73-
public function loadValuesForChoices(array $choices, callable $value = null)
74-
{
75-
return $this->loader->loadValuesForChoices($choices, $value);
76-
}
77-
78-
public static function reset(): void
79-
{
80-
self::$loaders = [];
81-
}
8225
}

src/Symfony/Component/Form/ChoiceList/Factory/Cache/ChoiceValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
*
2121
* @author Jules Pietri <jules@heahprod.com>
2222
*/
23-
final class ChoiceValue extends AbstractStaticCallback
23+
final class ChoiceValue extends AbstractStaticOption
2424
{
2525
}

src/Symfony/Component/Form/ChoiceList/Factory/Cache/GroupBy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
*
2121
* @author Jules Pietri <jules@heahprod.com>
2222
*/
23-
final class GroupBy extends AbstractStaticCallback
23+
final class GroupBy extends AbstractStaticOption
2424
{
2525
}
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
*
2121
* @author Jules Pietri <jules@heahprod.com>
2222
*/
23-
final class PreferredChoice extends AbstractStaticCallback
23+
final class PreferredChoice extends AbstractStaticOption
2424
{
2525
}