Skip to content

Commit f1c43f9

Browse files
peter-gribanovPeter Gribanov
authored andcommitted
not use reflection to get value of FormType::$emptyData
1 parent 13a3a26 commit f1c43f9

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
class FormType extends BaseType
3131
{
3232
private $dataMapper;
33-
private static $emptyData = null;
33+
34+
/**
35+
* @internal
36+
*
37+
* @deprecated Don't use this property. It will be removed in symfony/form 6.0
38+
*/
39+
public static $emptyData = null;
3440

3541
public function __construct(PropertyAccessorInterface $propertyAccessor = null)
3642
{
@@ -160,7 +166,7 @@ public function configureOptions(OptionsResolver $resolver)
160166
};
161167

162168
// Derive "empty_data" closure from "data_class" option
163-
if (self::$emptyData === null) {
169+
if (null === self::$emptyData) {
164170
self::$emptyData = function (Options $options) {
165171
$class = $options['data_class'];
166172

src/Symfony/Component/Form/Extension/Core/Type/TextType.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2727
// See https://github.com/symfony/symfony/issues/5906#issuecomment-203189375
2828
if ('' === $options['empty_data']) {
2929
$builder->addViewTransformer($this);
30-
} elseif ($options['empty_data'] instanceof \Closure) {
31-
$emptyData = new \ReflectionProperty(FormType::class, 'emptyData');
32-
$emptyData->setAccessible(true);
33-
// Closure in "empty_data" option is the default value from FormType::configureOptions()
34-
if ($emptyData->getValue($builder->getForm()) === $options['empty_data']) {
35-
trigger_deprecation('symfony/form', '5.4', 'The default value of "empty_data" option in "%s" will be changed to empty string. Declare "NULL" as value for "empty_data" if you still want use "NULL" as data.', __CLASS__);
36-
}
30+
} elseif (FormType::$emptyData === $options['empty_data']) {
31+
// "empty_data" option is the default value from FormType::configureOptions()
32+
trigger_deprecation('symfony/form', '5.4', 'The default value of "empty_data" option in "%s" will be changed to empty string. Declare "NULL" as value for "empty_data" if you still want use "NULL" as data.', __CLASS__);
3733
}
3834
}
3935

src/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function testPreferOwnLabelTranslationParameters()
186186
])
187187
->add('child', $this->getTestedType(), $this->getTestedTypeOptions() + [
188188
'label_translation_parameters' => ['%override_param%' => 'child_value'],
189-
]))
189+
])
190190
->getForm()
191191
->createView();
192192

@@ -203,7 +203,7 @@ public function testPreferOwnAttrTranslationParameters()
203203
])
204204
->add('child', $this->getTestedType(), $this->getTestedTypeOptions() + [
205205
'attr_translation_parameters' => ['%override_param%' => 'child_value'],
206-
]))
206+
])
207207
->getForm()
208208
->createView();
209209

@@ -292,7 +292,7 @@ protected function getTestedType()
292292
return static::TESTED_TYPE;
293293
}
294294

295-
protected function getTestedTypeOptions()
295+
protected function getTestedTypeOptions(): array
296296
{
297297
return static::TESTED_TYPE_OPTIONS;
298298
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/BirthdayTypeTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
class BirthdayTypeTest extends DateTypeTest
2020
{
2121
public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\BirthdayType';
22-
public const TESTED_TYPE_OPTIONS = [
23-
];
22+
public const TESTED_TYPE_OPTIONS = [];
2423

2524
public function testSetInvalidYearsOption()
2625
{

src/Symfony/Component/Form/Tests/Extension/Core/Type/EnumTypeTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
final class EnumTypeTest extends BaseTypeTest
2626
{
2727
public const TESTED_TYPE = EnumType::class;
28-
public const TESTED_TYPE_OPTIONS = ['class' => Suit::class];
28+
public const TESTED_TYPE_OPTIONS = [
29+
'class' => Suit::class,
30+
];
2931

3032
public function testClassOptionIsRequired()
3133
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy