Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa99245

Browse files
minor#41998 [Form] add union types (nicolas-grekas)
This PR was squashed before being merged into the 6.0 branch.Discussion----------[Form] add union types| Q | A| ------------- | ---| Branch? | 6.0| Bug fix? | no| New feature? | no| Deprecations? | no| Tickets | Part of#41424| License | MIT| Doc PR | -Commits-------0480be6 [Form] add union types
2 parents5bd3024 +0480be6 commitfa99245

File tree

80 files changed

+271
-360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+271
-360
lines changed

‎src/Symfony/Component/Form/AbstractRendererEngine.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(array $defaultThemes = [])
4444
/**
4545
* {@inheritdoc}
4646
*/
47-
publicfunctionsetTheme(FormView$view,$themes,bool$useDefaultThemes =true)
47+
publicfunctionsetTheme(FormView$view,mixed$themes,bool$useDefaultThemes =true)
4848
{
4949
$cacheKey =$view->vars[self::CACHE_KEY_VAR];
5050

‎src/Symfony/Component/Form/Button.php‎

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ public function __construct(FormConfigInterface $config)
4747
/**
4848
* Unsupported method.
4949
*
50-
* @param mixed $offset
51-
*
5250
* @return bool Always returns false
5351
*/
54-
publicfunctionoffsetExists($offset)
52+
publicfunctionoffsetExists(mixed$offset)
5553
{
5654
returnfalse;
5755
}
@@ -61,11 +59,9 @@ public function offsetExists($offset)
6159
*
6260
* This method should not be invoked.
6361
*
64-
* @param mixed $offset
65-
*
6662
* @throws BadMethodCallException
6763
*/
68-
publicfunctionoffsetGet($offset)
64+
publicfunctionoffsetGet(mixed$offset)
6965
{
7066
thrownewBadMethodCallException('Buttons cannot have children.');
7167
}
@@ -75,12 +71,9 @@ public function offsetGet($offset)
7571
*
7672
* This method should not be invoked.
7773
*
78-
* @param mixed $offset
79-
* @param mixed $value
80-
*
8174
* @throws BadMethodCallException
8275
*/
83-
publicfunctionoffsetSet($offset,$value)
76+
publicfunctionoffsetSet(mixed$offset,mixed$value)
8477
{
8578
thrownewBadMethodCallException('Buttons cannot have children.');
8679
}
@@ -90,11 +83,9 @@ public function offsetSet($offset, $value)
9083
*
9184
* This method should not be invoked.
9285
*
93-
* @param mixed $offset
94-
*
9586
* @throws BadMethodCallException
9687
*/
97-
publicfunctionoffsetUnset($offset)
88+
publicfunctionoffsetUnset(mixed$offset)
9889
{
9990
thrownewBadMethodCallException('Buttons cannot have children.');
10091
}
@@ -128,7 +119,7 @@ public function getParent()
128119
*
129120
* @throws BadMethodCallException
130121
*/
131-
publicfunctionadd($child,string$type =null,array$options = [])
122+
publicfunctionadd(string|FormInterface$child,string$type =null,array$options = [])
132123
{
133124
thrownewBadMethodCallException('Buttons cannot have children.');
134125
}
@@ -188,11 +179,9 @@ public function getErrors(bool $deep = false, bool $flatten = true)
188179
*
189180
* This method should not be invoked.
190181
*
191-
* @param mixed $modelData
192-
*
193182
* @return $this
194183
*/
195-
publicfunctionsetData($modelData)
184+
publicfunctionsetData(mixed$modelData)
196185
{
197186
// no-op, called during initialization of the form tree
198187
return$this;
@@ -353,26 +342,21 @@ public function initialize()
353342
/**
354343
* Unsupported method.
355344
*
356-
* @param mixed $request
357-
*
358345
* @throws BadMethodCallException
359346
*/
360-
publicfunctionhandleRequest($request =null)
347+
publicfunctionhandleRequest(mixed$request =null)
361348
{
362349
thrownewBadMethodCallException('Buttons cannot handle requests. Call handleRequest() on the root form instead.');
363350
}
364351

365352
/**
366353
* Submits data to the button.
367354
*
368-
* @param string|null $submittedData Not used
369-
* @param bool $clearMissing Not used
370-
*
371355
* @return $this
372356
*
373357
* @throws Exception\AlreadySubmittedException if the button has already been submitted
374358
*/
375-
publicfunctionsubmit($submittedData,bool$clearMissing =true)
359+
publicfunctionsubmit(array|string|null$submittedData,bool$clearMissing =true)
376360
{
377361
if ($this->submitted) {
378362
thrownewAlreadySubmittedException('A form can only be submitted once.');

‎src/Symfony/Component/Form/ButtonBuilder.php‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
useSymfony\Component\EventDispatcher\EventSubscriberInterface;
1515
useSymfony\Component\Form\Exception\BadMethodCallException;
1616
useSymfony\Component\Form\Exception\InvalidArgumentException;
17+
useSymfony\Component\PropertyAccess\PropertyPathInterface;
1718

1819
/**
1920
* A builder for {@link Button} instances.
@@ -71,7 +72,7 @@ public function __construct(?string $name, array $options = [])
7172
*
7273
* @throws BadMethodCallException
7374
*/
74-
publicfunctionadd($child,string$type =null,array$options = [])
75+
publicfunctionadd(string|FormBuilderInterface$child,string$type =null,array$options = [])
7576
{
7677
thrownewBadMethodCallException('Buttons cannot have children.');
7778
}
@@ -217,7 +218,7 @@ public function resetModelTransformers()
217218
/**
218219
* {@inheritdoc}
219220
*/
220-
publicfunctionsetAttribute(string$name,$value)
221+
publicfunctionsetAttribute(string$name,mixed$value)
221222
{
222223
$this->attributes[$name] =$value;
223224

@@ -263,11 +264,9 @@ public function setDisabled(bool $disabled)
263264
*
264265
* This method should not be invoked.
265266
*
266-
* @param mixed $emptyData
267-
*
268267
* @throws BadMethodCallException
269268
*/
270-
publicfunctionsetEmptyData($emptyData)
269+
publicfunctionsetEmptyData(mixed$emptyData)
271270
{
272271
thrownewBadMethodCallException('Buttons do not support empty data.');
273272
}
@@ -301,11 +300,9 @@ public function setRequired(bool $required)
301300
*
302301
* This method should not be invoked.
303302
*
304-
* @param null $propertyPath
305-
*
306303
* @throws BadMethodCallException
307304
*/
308-
publicfunctionsetPropertyPath($propertyPath)
305+
publicfunctionsetPropertyPath(string|PropertyPathInterface|null$propertyPath)
309306
{
310307
thrownewBadMethodCallException('Buttons do not support property paths.');
311308
}
@@ -363,11 +360,9 @@ public function setType(ResolvedFormTypeInterface $type)
363360
*
364361
* This method should not be invoked.
365362
*
366-
* @param mixed $data
367-
*
368363
* @throws BadMethodCallException
369364
*/
370-
publicfunctionsetData($data)
365+
publicfunctionsetData(mixed$data)
371366
{
372367
thrownewBadMethodCallException('Buttons do not support data.');
373368
}
@@ -629,11 +624,9 @@ public function hasAttribute(string $name)
629624
/**
630625
* Returns the value of the given attribute.
631626
*
632-
* @param mixed $default The value returned if the attribute does not exist
633-
*
634627
* @return mixed The attribute value
635628
*/
636-
publicfunctiongetAttribute(string$name,$default =null)
629+
publicfunctiongetAttribute(string$name,mixed$default =null)
637630
{
638631
return\array_key_exists($name,$this->attributes) ?$this->attributes[$name] :$default;
639632
}
@@ -739,11 +732,9 @@ public function hasOption(string $name)
739732
/**
740733
* Returns the value of a specific option.
741734
*
742-
* @param mixed $default The value returned if the option does not exist
743-
*
744735
* @return mixed The option value
745736
*/
746-
publicfunctiongetOption(string$name,$default =null)
737+
publicfunctiongetOption(string$name,mixed$default =null)
747738
{
748739
return\array_key_exists($name,$this->options) ?$this->options[$name] :$default;
749740
}

‎src/Symfony/Component/Form/CallbackTransformer.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public function __construct(callable $transform, callable $reverseTransform)
2929
/**
3030
* {@inheritdoc}
3131
*/
32-
publicfunctiontransform($data)
32+
publicfunctiontransform(mixed$data)
3333
{
3434
return ($this->transform)($data);
3535
}
3636

3737
/**
3838
* {@inheritdoc}
3939
*/
40-
publicfunctionreverseTransform($data)
40+
publicfunctionreverseTransform(mixed$data)
4141
{
4242
return ($this->reverseTransform)($data);
4343
}

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

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,117 +35,107 @@ final class ChoiceList
3535
/**
3636
* Creates a cacheable loader from any callable providing iterable choices.
3737
*
38-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
39-
* @param callable $choices A callable that must return iterable choices or grouped choices
40-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the loader
38+
* @param callable $choices A callable that must return iterable choices or grouped choices
39+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the loader
4140
*/
42-
publicstaticfunctionlazy($formType,callable$choices,$vary =null):ChoiceLoader
41+
publicstaticfunctionlazy(FormTypeInterface|FormTypeExtensionInterface$formType,callable$choices,mixed$vary =null):ChoiceLoader
4342
{
4443
returnself::loader($formType,newCallbackChoiceLoader($choices),$vary);
4544
}
4645

4746
/**
4847
* Decorates a loader to make it cacheable.
4948
*
50-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
51-
* @param ChoiceLoaderInterface $loader A loader responsible for creating loading choices or grouped choices
52-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the loader
49+
* @param ChoiceLoaderInterface $loader A loader responsible for creating loading choices or grouped choices
50+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the loader
5351
*/
54-
publicstaticfunctionloader($formType,ChoiceLoaderInterface$loader,$vary =null):ChoiceLoader
52+
publicstaticfunctionloader(FormTypeInterface|FormTypeExtensionInterface$formType,ChoiceLoaderInterface$loader,mixed$vary =null):ChoiceLoader
5553
{
5654
returnnewChoiceLoader($formType,$loader,$vary);
5755
}
5856

5957
/**
6058
* Decorates a "choice_value" callback to make it cacheable.
6159
*
62-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
63-
* @param callable $value Any pseudo callable to create a unique string value from a choice
64-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the callback
60+
* @param callable|array $value Any pseudo callable to create a unique string value from a choice
61+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the callback
6562
*/
66-
publicstaticfunctionvalue($formType,$value,$vary =null):ChoiceValue
63+
publicstaticfunctionvalue(FormTypeInterface|FormTypeExtensionInterface$formType,callable|array$value,mixed$vary =null):ChoiceValue
6764
{
6865
returnnewChoiceValue($formType,$value,$vary);
6966
}
7067

7168
/**
72-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
73-
* @param callable $filter Any pseudo callable to filter a choice list
74-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the callback
69+
* @param callable|array $filter Any pseudo callable to filter a choice list
70+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the callback
7571
*/
76-
publicstaticfunctionfilter($formType,$filter,$vary =null):ChoiceFilter
72+
publicstaticfunctionfilter(FormTypeInterface|FormTypeExtensionInterface$formType,callable|array$filter,mixed$vary =null):ChoiceFilter
7773
{
7874
returnnewChoiceFilter($formType,$filter,$vary);
7975
}
8076

8177
/**
8278
* Decorates a "choice_label" option to make it cacheable.
8379
*
84-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
85-
* @param callable|false $label Any pseudo callable to create a label from a choice or false to discard it
86-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option
80+
* @param callable|false $label Any pseudo callable to create a label from a choice or false to discard it
81+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the option
8782
*/
88-
publicstaticfunctionlabel($formType,$label,$vary =null):ChoiceLabel
83+
publicstaticfunctionlabel(FormTypeInterface|FormTypeExtensionInterface$formType,callable|false$label,mixed$vary =null):ChoiceLabel
8984
{
9085
returnnewChoiceLabel($formType,$label,$vary);
9186
}
9287

9388
/**
9489
* Decorates a "choice_name" callback to make it cacheable.
9590
*
96-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
97-
* @param callable $fieldName Any pseudo callable to create a field name from a choice
98-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the callback
91+
* @param callable|array $fieldName Any pseudo callable to create a field name from a choice
92+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the callback
9993
*/
100-
publicstaticfunctionfieldName($formType,$fieldName,$vary =null):ChoiceFieldName
94+
publicstaticfunctionfieldName(FormTypeInterface|FormTypeExtensionInterface$formType,callable|array$fieldName,mixed$vary =null):ChoiceFieldName
10195
{
10296
returnnewChoiceFieldName($formType,$fieldName,$vary);
10397
}
10498

10599
/**
106100
* Decorates a "choice_attr" option to make it cacheable.
107101
*
108-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
109-
* @param callable|array $attr Any pseudo callable or array to create html attributes from a choice
110-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option
102+
* @param callable|array $attr Any pseudo callable or array to create html attributes from a choice
103+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the option
111104
*/
112-
publicstaticfunctionattr($formType,$attr,$vary =null):ChoiceAttr
105+
publicstaticfunctionattr(FormTypeInterface|FormTypeExtensionInterface$formType,callable|array$attr,mixed$vary =null):ChoiceAttr
113106
{
114107
returnnewChoiceAttr($formType,$attr,$vary);
115108
}
116109

117110
/**
118111
* Decorates a "choice_translation_parameters" option to make it cacheable.
119112
*
120-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
121-
* @param callable|array $translationParameters Any pseudo callable or array to create translation parameters from a choice
122-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option
113+
* @param callable|array $translationParameters Any pseudo callable or array to create translation parameters from a choice
114+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the option
123115
*/
124-
publicstaticfunctiontranslationParameters($formType,$translationParameters,$vary =null):ChoiceTranslationParameters
116+
publicstaticfunctiontranslationParameters(FormTypeInterface|FormTypeExtensionInterface$formType,callable|array$translationParameters,mixed$vary =null):ChoiceTranslationParameters
125117
{
126118
returnnewChoiceTranslationParameters($formType,$translationParameters,$vary);
127119
}
128120

129121
/**
130122
* Decorates a "group_by" callback to make it cacheable.
131123
*
132-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
133-
* @param callable $groupBy Any pseudo callable to return a group name from a choice
134-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the callback
124+
* @param callable|array $groupBy Any pseudo callable to return a group name from a choice
125+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the callback
135126
*/
136-
publicstaticfunctiongroupBy($formType,$groupBy,$vary =null):GroupBy
127+
publicstaticfunctiongroupBy(FormTypeInterface|FormTypeExtensionInterface$formType,callable|array$groupBy,mixed$vary =null):GroupBy
137128
{
138129
returnnewGroupBy($formType,$groupBy,$vary);
139130
}
140131

141132
/**
142133
* Decorates a "preferred_choices" option to make it cacheable.
143134
*
144-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
145-
* @param callable|array $preferred Any pseudo callable or array to return a group name from a choice
146-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option
135+
* @param callable|array $preferred Any pseudo callable or array to return a group name from a choice
136+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the option
147137
*/
148-
publicstaticfunctionpreferred($formType,$preferred,$vary =null):PreferredChoice
138+
publicstaticfunctionpreferred(FormTypeInterface|FormTypeExtensionInterface$formType,callable|array$preferred,mixed$vary =null):PreferredChoice
149139
{
150140
returnnewPreferredChoice($formType,$preferred,$vary);
151141
}

‎src/Symfony/Component/Form/ChoiceList/Factory/Cache/AbstractStaticOption.php‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,11 @@ abstract class AbstractStaticOption
3434
private$option;
3535

3636
/**
37-
* @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list
38-
* @param mixed $option Any pseudo callable, array, string or bool to define a choice list option
39-
* @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option
37+
* @param mixed $option Any pseudo callable, array, string or bool to define a choice list option
38+
* @param mixed $vary Dynamic data used to compute a unique hash when caching the option
4039
*/
41-
finalpublicfunction__construct($formType,$option,$vary =null)
40+
finalpublicfunction__construct(FormTypeInterface|FormTypeExtensionInterface$formType,mixed$option,mixed$vary =null)
4241
{
43-
if (!$formTypeinstanceof FormTypeInterface && !$formTypeinstanceof FormTypeExtensionInterface) {
44-
thrownew \TypeError(sprintf('Expected an instance of "%s" or "%s", but got "%s".', FormTypeInterface::class, FormTypeExtensionInterface::class,get_debug_type($formType)));
45-
}
46-
4742
$hash = CachingFactoryDecorator::generateHash([static::class,$formType,$vary]);
4843

4944
$this->option =self::$options[$hash] ??self::$options[$hash] =$option;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp