21
21
class ExtraLazyChoiceLoader implements ChoiceLoaderInterface
22
22
{
23
23
private ?ChoiceListInterface $ choiceList = null ;
24
- private array $ choices = [];
25
- private bool $ cached = false ;
26
24
27
25
public function __construct (
28
26
private readonly ChoiceLoaderInterface $ decorated ,
@@ -31,38 +29,21 @@ public function __construct(
31
29
32
30
public function loadChoiceList (callable $ value = null ): ChoiceListInterface
33
31
{
34
- if (null !== $ this ->choiceList && $ this ->cached ) {
35
- return $ this ->choiceList ;
36
- }
37
-
38
- $ this ->cached = true ;
39
-
40
- return $ this ->choiceList = new ArrayChoiceList ($ this ->choices , $ value );
32
+ return $ this ->choiceList ??= new ArrayChoiceList ([], $ value );
41
33
}
42
34
43
35
public function loadChoicesForValues (array $ values , callable $ value = null ): array
44
36
{
45
- if ($ this ->choices !== $ choices = $ this ->decorated ->loadChoicesForValues ($ values , $ value )) {
46
- $ this ->cached = false ;
47
- }
37
+ $ choices = $ this ->decorated ->loadChoicesForValues ($ values , $ value );
38
+ $ this ->choiceList = new ArrayChoiceList ($ choices , $ value );
48
39
49
- return $ this -> choices = $ choices ;
40
+ return $ choices ;
50
41
}
51
42
52
43
public function loadValuesForChoices (array $ choices , callable $ value = null ): array
53
44
{
54
45
$ values = $ this ->decorated ->loadValuesForChoices ($ choices , $ value );
55
-
56
- if ([] === $ values || ['' ] === $ values ) {
57
- $ newChoices = [];
58
- } else {
59
- $ newChoices = $ choices ;
60
- }
61
-
62
- if ($ this ->choices !== $ newChoices ) {
63
- $ this ->choices = $ newChoices ;
64
- $ this ->cached = false ;
65
- }
46
+ $ this ->loadChoicesForValues ($ values , $ value );
66
47
67
48
return $ values ;
68
49
}
0 commit comments