Skip to content

Commit 0206282

Browse files
committed
deprecate implicit string casting of mapping keys
1 parent e7c12d3 commit 0206282

25 files changed

+275
-109
lines changed

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ protected function loadFile($file)
602602
}
603603

604604
try {
605-
$configuration = $this->yamlParser->parse(file_get_contents($file), Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS);
605+
$configuration = $this->yamlParser->parse(file_get_contents($file), Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_KEYS_AS_STRING);
606606
} catch (ParseException $e) {
607607
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
608608
}

src/Symfony/Component/Routing/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Yaml\Exception\ParseException;
1818
use Symfony\Component\Yaml\Parser as YamlParser;
1919
use Symfony\Component\Config\Loader\FileLoader;
20+
use Symfony\Component\Yaml\Yaml;
2021

2122
/**
2223
* YamlFileLoader loads Yaml routing files.
@@ -58,7 +59,7 @@ public function load($file, $type = null)
5859
}
5960

6061
try {
61-
$parsedConfig = $this->yamlParser->parse(file_get_contents($path));
62+
$parsedConfig = $this->yamlParser->parse(file_get_contents($path), Yaml::PARSE_KEYS_AS_STRING);
6263
} catch (ParseException $e) {
6364
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
6465
}

src/Symfony/Component/Routing/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
"require-dev": {
2222
"symfony/config": "~2.8|~3.0",
2323
"symfony/http-foundation": "~2.8|~3.0",
24-
"symfony/yaml": "~2.8|~3.0",
24+
"symfony/yaml": "~3.3",
2525
"symfony/expression-language": "~2.8|~3.0",
2626
"symfony/dependency-injection": "~2.8|~3.0",
2727
"doctrine/annotations": "~1.0",
2828
"doctrine/common": "~2.2",
2929
"psr/log": "~1.0"
3030
},
3131
"conflict": {
32-
"symfony/config": "<2.8"
32+
"symfony/config": "<2.8",
33+
"symfony/yaml": "<3.3"
3334
},
3435
"suggest": {
3536
"symfony/http-foundation": "For using a Symfony Request object",

src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
1616
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
1717
use Symfony\Component\Yaml\Parser;
18+
use Symfony\Component\Yaml\Yaml;
1819

1920
/**
2021
* YAML File Loader.
@@ -113,7 +114,7 @@ private function getClassesFromYaml()
113114
$this->yamlParser = new Parser();
114115
}
115116

116-
$classes = $this->yamlParser->parse(file_get_contents($this->file));
117+
$classes = $this->yamlParser->parse(file_get_contents($this->file), Yaml::PARSE_KEYS_AS_STRING);
117118

118119
if (empty($classes)) {
119120
return array();

src/Symfony/Component/Serializer/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.5.9"
2020
},
2121
"require-dev": {
22-
"symfony/yaml": "~3.1",
22+
"symfony/yaml": "~3.3",
2323
"symfony/config": "~2.8|~3.0",
2424
"symfony/property-access": "~2.8|~3.0",
2525
"symfony/http-foundation": "~2.8|~3.0",
@@ -34,7 +34,7 @@
3434
"symfony/dependency-injection": "<3.2",
3535
"symfony/property-access": ">=3.0,<3.0.4|>=2.8,<2.8.4",
3636
"symfony/property-info": "<3.1",
37-
"symfony/yaml": "<3.1"
37+
"symfony/yaml": "<3.3"
3838
},
3939
"suggest": {
4040
"psr/cache-implementation": "For using the metadata cache.",

src/Symfony/Component/Translation/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Translation\Exception\LogicException;
1616
use Symfony\Component\Yaml\Parser as YamlParser;
1717
use Symfony\Component\Yaml\Exception\ParseException;
18+
use Symfony\Component\Yaml\Yaml;
1819

1920
/**
2021
* YamlFileLoader loads translations from Yaml files.
@@ -39,7 +40,7 @@ protected function loadResource($resource)
3940
}
4041

4142
try {
42-
$messages = $this->yamlParser->parse(file_get_contents($resource));
43+
$messages = $this->yamlParser->parse(file_get_contents($resource), Yaml::PARSE_KEYS_AS_STRING);
4344
} catch (ParseException $e) {
4445
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
4546
}

src/Symfony/Component/Translation/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
"require-dev": {
2323
"symfony/config": "~2.8|~3.0",
2424
"symfony/intl": "^2.8.18|^3.2.5",
25-
"symfony/yaml": "~2.8|~3.0",
25+
"symfony/yaml": "~3.3",
2626
"psr/log": "~1.0"
2727
},
2828
"conflict": {
29-
"symfony/config": "<2.8"
29+
"symfony/config": "<2.8",
30+
"symfony/yaml": "<3.3"
3031
},
3132
"suggest": {
3233
"symfony/config": "",

src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Validator\Mapping\ClassMetadata;
1515
use Symfony\Component\Yaml\Exception\ParseException;
1616
use Symfony\Component\Yaml\Parser as YamlParser;
17+
use Symfony\Component\Yaml\Yaml;
1718

1819
/**
1920
* Loads validation metadata from a YAML file.
@@ -115,7 +116,7 @@ protected function parseNodes(array $nodes)
115116
private function parseFile($path)
116117
{
117118
try {
118-
$classes = $this->yamlParser->parse(file_get_contents($path));
119+
$classes = $this->yamlParser->parse(file_get_contents($path), Yaml::PARSE_KEYS_AS_STRING);
119120
} catch (ParseException $e) {
120121
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
121122
}

src/Symfony/Component/Validator/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"require-dev": {
2424
"symfony/http-foundation": "~2.8|~3.0",
2525
"symfony/intl": "^2.8.18|^3.2.5",
26-
"symfony/yaml": "~2.8|~3.0",
26+
"symfony/yaml": "~3.3",
2727
"symfony/config": "~2.8|~3.0",
2828
"symfony/expression-language": "~2.8|~3.0",
2929
"symfony/cache": "~3.1",
@@ -32,7 +32,8 @@
3232
"egulias/email-validator": "^1.2.8|~2.0"
3333
},
3434
"conflict": {
35-
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"
35+
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
36+
"symfony/yaml": "<3.3"
3637
},
3738
"suggest": {
3839
"psr/cache-implementation": "For using the metadata cache.",

src/Symfony/Component/Yaml/Inline.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,14 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
485485
@trigger_error('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
486486
}
487487

488+
if (!(Yaml::PARSE_KEYS_AS_STRING & $flags)) {
489+
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
490+
491+
if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey)) {
492+
@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);
493+
}
494+
}
495+
488496
if (':' !== $key && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
489497
@trigger_error('Using a colon that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}" is deprecated since version 3.2 and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
490498
}

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