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

Commitfd711b8

Browse files
committed
Deprecate Yaml::PARSE_KEYS_AS_STRINGS
1 parentc5210ad commitfd711b8

File tree

7 files changed

+87
-7
lines changed

7 files changed

+87
-7
lines changed

‎UPGRADE-3.4.md‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,42 @@ Finder
1010
------
1111

1212
* The`Symfony\Component\Finder\Iterator\FilterIterator` class has been
13-
deprecated and will be removed in 4.0 as it used to fix a bug which existed
13+
deprecated and will be removed in 4.0 as it used to fix a bug which existed
1414
before version 5.5.23/5.6.7.
1515

1616
Validator
1717
---------
1818

1919
* Not setting the`strict` option of the`Choice` constraint to`true` is
2020
deprecated and will throw an exception in Symfony 4.0.
21+
22+
Yaml
23+
----
24+
25+
* Using the`Yaml::PARSE_KEYS_AS_STRINGS` flag is deprecated as it will be
26+
removed in 4.0.
27+
28+
Before:
29+
30+
```php
31+
$yaml = <<<YAML
32+
null:nullkey
33+
true:booleantrue
34+
2.0:floatkey
35+
YAML;
36+
37+
Yaml::parse($yaml,Yaml::PARSE_KEYS_AS_STRINGS);
38+
```
39+
40+
After:
41+
42+
```php
43+
44+
$yaml = <<<YAML
45+
"null":nullkey
46+
"true":booleantrue
47+
"2.0":floatkey
48+
YAML;
49+
50+
Yaml::parse($yaml);
51+
```

‎UPGRADE-4.0.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,33 @@ Yaml
590590
Yaml::parse($yaml);
591591
```
592592

593+
*Removedthe`Yaml::PARSE_KEYS_AS_STRINGS`flag.
594+
595+
Before:
596+
597+
```php
598+
$yaml = <<<YAML
599+
null:nullkey
600+
true:booleantrue
601+
2.0:floatkey
602+
YAML;
603+
604+
Yaml::parse($yaml,Yaml::PARSE_KEYS_AS_STRINGS);
605+
```
606+
607+
After:
608+
609+
```php
610+
611+
$yaml = <<<YAML
612+
"null":nullkey
613+
"true":booleantrue
614+
"2.0":floatkey
615+
YAML;
616+
617+
Yaml::parse($yaml);
618+
```
619+
593620
*Omittingthekeyofamappingisnotsupportedanymoreandthrowsa`ParseException`.
594621

595622
*Mappingswithacolon(`:`)thatisnotfollowedbyawhitespacearenot

‎src/Symfony/Component/Yaml/Inline.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
493493
if (!$isKeyQuoted) {
494494
$evaluatedKey =self::evaluateScalar($key,$flags,$references);
495495
if ('' !==$key &&$evaluatedKey !==$key && !is_string($evaluatedKey) && !is_int($evaluatedKey)) {
496-
@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.Use quotes instead.',E_USER_DEPRECATED);
496+
@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);
497497
}
498498
}
499499

‎src/Symfony/Component/Yaml/Parser.php‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public function parse($value, $flags = 0)
8686
}
8787
}
8888

89+
if (Yaml::PARSE_KEYS_AS_STRINGS &$flags) {
90+
@trigger_error('Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since version 3.4 as it will be removed in 4.0. Quote your keys when they are evaluable instead.',E_USER_DEPRECATED);
91+
}
92+
8993
if (false ===preg_match('//u',$value)) {
9094
thrownewParseException('The YAML value does not appear to be valid UTF-8.');
9195
}
@@ -220,7 +224,15 @@ private function doParse($value, $flags)
220224
Inline::parse(null,$flags,$this->refs);
221225
try {
222226
Inline::$parsedLineNumber =$this->getRealCurrentLineNb();
223-
$key = Inline::parseScalar($values['key']);
227+
$i =0;
228+
$evaluateKey = !(Yaml::PARSE_KEYS_AS_STRINGS &$flags);
229+
230+
// constants in key will be evaluated anyway
231+
if (isset($values['key'][0]) &&'!' ===$values['key'][0] && Yaml::PARSE_CONSTANT &$flags) {
232+
$evaluateKey =true;
233+
}
234+
235+
$key = Inline::parseScalar($values['key'],0,null,$i,$evaluateKey);
224236
}catch (ParseException$e) {
225237
$e->setParsedLine($this->getRealCurrentLineNb() +1);
226238
$e->setSnippet($this->currentLine);
@@ -229,7 +241,7 @@ private function doParse($value, $flags)
229241
}
230242

231243
if (!is_string($key) && !is_int($key)) {
232-
@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_STRING flag to explicitly enable the type casts.',E_USER_DEPRECATED);
244+
@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);
233245
}
234246

235247
// Convert float keys to strings, to avoid being converted to integers by PHP

‎src/Symfony/Component/Yaml/Tests/InlineTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ public function testTheEmptyStringIsAValidMappingKey()
730730

731731
/**
732732
* @group legacy
733-
* @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.Use quotes instead.
733+
* @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.
734734
* @dataProvider getNotPhpCompatibleMappingKeyData
735735
*/
736736
publicfunctiontestImplicitStringCastingOfMappingKeysIsDeprecated($yaml,$expected)

‎src/Symfony/Component/Yaml/Tests/ParserTest.php‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ public function testYamlDirective()
10641064

10651065
/**
10661066
* @group legacy
1067-
* @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_STRING flag to explicitly enable the type casts.
1067+
* @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.
10681068
*/
10691069
publicfunctiontestFloatKeys()
10701070
{
@@ -1086,7 +1086,7 @@ public function testFloatKeys()
10861086

10871087
/**
10881088
* @group legacy
1089-
* @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_STRING flag to explicitly enable the type casts.
1089+
* @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.
10901090
*/
10911091
publicfunctiontestBooleanKeys()
10921092
{
@@ -1817,6 +1817,15 @@ public function testPhpConstantTagMappingKey()
18171817

18181818
$this->assertSame($expected,$this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
18191819
}
1820+
1821+
/**
1822+
* @group legacy
1823+
* @expectedDeprecation Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since version 3.4 as it will be removed in 4.0. Quote your keys when they are evaluable instead.
1824+
*/
1825+
publicfunctiontestNonStringMappingKeys()
1826+
{
1827+
$this->assertEquals(array('false' =>'bar'),$this->parser->parse('false: bar', Yaml::PARSE_KEYS_AS_STRINGS));
1828+
}
18201829
}
18211830

18221831
class B

‎src/Symfony/Component/Yaml/Yaml.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Yaml
3131
constPARSE_CONSTANT =256;
3232
constPARSE_CUSTOM_TAGS =512;
3333
constDUMP_EMPTY_ARRAY_AS_SEQUENCE =1024;
34+
constPARSE_KEYS_AS_STRINGS =2048;
3435

3536
/**
3637
* Parses YAML into a PHP value.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp