minor #20425 [Form] fixed "empty_value" option deprecation (HeahDude)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form] fixed "empty_value" option deprecation

| Q             | A
| ------------- | ---
| Branch?       | 2.x only
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/15945#r86547326
| License       | MIT
| Doc PR        | ~

I didn't make any profiling but a resolver instance is passed to `configureOptions()` creating locale variables including those exceptions for each field using one of the patched form types, so I guess the memory usage can grow really fast.

Commits
-------

7e84907 [Form] fixed "empty_value" option deprecation
This commit is contained in:
Fabien Potencier 2016-12-03 11:52:40 +01:00
commit fe15381a45
3 changed files with 11 additions and 6 deletions

View File

@ -39,6 +39,11 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class ChoiceType extends AbstractType
{
/**
* @internal To be removed in 3.0
*/
const DEPRECATED_EMPTY_VALUE = '__deprecated_empty_value__';
/**
* Caches created choice lists.
*
@ -336,7 +341,7 @@ class ChoiceType extends AbstractType
};
$placeholderNormalizer = function (Options $options, $placeholder) use ($that) {
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
if ($that::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) {
@trigger_error(sprintf('The form option "empty_value" of the "%s" form type (%s) is deprecated since version 2.6 and will be removed in 3.0. Use "placeholder" instead.', $that->getName(), __CLASS__), E_USER_DEPRECATED);
if (null === $placeholder || '' === $placeholder) {
@ -388,7 +393,7 @@ class ChoiceType extends AbstractType
'preferred_choices' => array(),
'group_by' => null,
'empty_data' => $emptyData,
'empty_value' => new \Exception(), // deprecated
'empty_value' => self::DEPRECATED_EMPTY_VALUE,
'placeholder' => $placeholder,
'error_bubbling' => false,
'compound' => $compound,

View File

@ -183,7 +183,7 @@ class DateType extends AbstractType
};
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
if (ChoiceType::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) {
@trigger_error('The form option "empty_value" is deprecated since version 2.6 and will be removed in 3.0. Use "placeholder" instead.', E_USER_DEPRECATED);
$placeholder = $options['empty_value'];
@ -218,7 +218,7 @@ class DateType extends AbstractType
'format' => $format,
'model_timezone' => null,
'view_timezone' => null,
'empty_value' => new \Exception(), // deprecated
'empty_value' => ChoiceType::DEPRECATED_EMPTY_VALUE,
'placeholder' => $placeholder,
'html5' => true,
// Don't modify \DateTime classes by reference, we treat

View File

@ -184,7 +184,7 @@ class TimeType extends AbstractType
};
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
if (ChoiceType::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) {
@trigger_error('The form option "empty_value" is deprecated since version 2.6 and will be removed in 3.0. Use "placeholder" instead.', E_USER_DEPRECATED);
$placeholder = $options['empty_value'];
@ -216,7 +216,7 @@ class TimeType extends AbstractType
'with_seconds' => false,
'model_timezone' => null,
'view_timezone' => null,
'empty_value' => new \Exception(), // deprecated
'empty_value' => ChoiceType::DEPRECATED_EMPTY_VALUE,
'placeholder' => $placeholder,
'html5' => true,
// Don't modify \DateTime classes by reference, we treat