Suggest using quotes instead of Yaml::PARSE_KEYS_AS_STRINGS

This commit is contained in:
Guilhem Niot 2017-07-23 14:40:01 +02:00
parent 07638982c7
commit 9fd425ea14
7 changed files with 23 additions and 31 deletions

View File

@ -365,8 +365,7 @@ Yaml
* Deprecated support for implicitly parsing non-string mapping keys as strings.
Mapping keys that are no strings will lead to a `ParseException` in Symfony
4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
strings.
4.0. Use quotes to opt-in for keys to be parsed as strings.
Before:
@ -374,7 +373,6 @@ Yaml
$yaml = <<<YAML
null: null key
true: boolean true
1: integer key
2.0: float key
YAML;
@ -386,13 +384,12 @@ Yaml
```php
$yaml = <<<YAML
null: null key
true: boolean true
1: integer key
2.0: float key
"null": null key
"true": boolean true
"2.0": float key
YAML;
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
Yaml::parse($yaml);
```
* Omitting the key of a mapping is deprecated and will throw a `ParseException` in Symfony 4.0.

View File

@ -326,8 +326,8 @@ FrameworkBundle
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass` class
has been removed. Use the `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass`
class instead.
* The `Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory` class has been removed.
* The `Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory` class has been removed.
Use `Symfony\Component\Validator\ContainerConstraintValidatorFactory` instead.
HttpFoundation
@ -555,8 +555,8 @@ Yaml
throws a `ParseException`.
* Removed support for implicitly parsing non-string mapping keys as strings.
Mapping keys that are no strings will result in a `ParseException`. Use the
`PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as strings.
Mapping keys that are no strings will result in a `ParseException`. Use
quotes to opt-in for keys to be parsed as strings.
Before:
@ -564,7 +564,6 @@ Yaml
$yaml = <<<YAML
null: null key
true: boolean true
1: integer key
2.0: float key
YAML;
@ -576,13 +575,12 @@ Yaml
```php
$yaml = <<<YAML
null: null key
true: boolean true
1: integer key
2.0: float key
"null": null key
"true": boolean true
"2.0": float key
YAML;
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
Yaml::parse($yaml);
```
* Omitting the key of a mapping is not supported anymore and throws a `ParseException`.

View File

@ -9,8 +9,7 @@ CHANGELOG
* Deprecated support for implicitly parsing non-string mapping keys as strings.
Mapping keys that are no strings will lead to a `ParseException` in Symfony
4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
strings.
4.0. Use quotes to opt-in for keys to be parsed as strings.
Before:
@ -18,7 +17,6 @@ CHANGELOG
$yaml = <<<YAML
null: null key
true: boolean true
1: integer key
2.0: float key
YAML;
@ -30,13 +28,12 @@ CHANGELOG
```php
$yaml = <<<YAML
null: null key
true: boolean true
1: integer key
2.0: float key
"null": null key
"true": boolean true
"2.0": float key
YAML;
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
Yaml::parse($yaml);
```
* Omitted mapping values will be parsed as `null`.

View File

@ -494,7 +494,7 @@ class Inline
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey) && !is_int($evaluatedKey)) {
@trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.', E_USER_DEPRECATED);
@trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', E_USER_DEPRECATED);
}
}

View File

@ -238,7 +238,7 @@ class Parser
if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags) && !is_string($key) && !is_int($key)) {
$keyType = is_numeric($key) ? 'numeric key' : 'non-string key';
@trigger_error(sprintf('Implicit casting of %s to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.', $keyType), E_USER_DEPRECATED);
@trigger_error(sprintf('Implicit casting of %s to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', $keyType), E_USER_DEPRECATED);
}
// Convert float keys to strings, to avoid being converted to integers by PHP

View File

@ -730,7 +730,7 @@ class InlineTest extends TestCase
/**
* @group legacy
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
* @dataProvider getNotPhpCompatibleMappingKeyData
*/
public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected)

View File

@ -1081,7 +1081,7 @@ EOF;
/**
* @group legacy
* @expectedDeprecation Implicit casting of numeric key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.
* @expectedDeprecation Implicit casting of numeric key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
*/
public function testFloatKeys()
{
@ -1103,7 +1103,7 @@ EOF;
/**
* @group legacy
* @expectedDeprecation Implicit casting of non-string key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.
* @expectedDeprecation Implicit casting of non-string key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
*/
public function testBooleanKeys()
{