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

Appearance settings

Commit 5c140e3

Browse filesBrowse files
committed
[Yaml] add inline parser context initializer
Calling the parser to initialize some internal context does not look like a good idea. Additionally, this change allows to not accept null values in `Inline::parse()` in 3.4 anymore.
1 parent 0beb598 commit 5c140e3
Copy full SHA for 5c140e3

File tree

2 files changed

+18
-6
lines changed
Filter options

2 files changed

+18
-6
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+17-4Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ class Inline
3333
private static $objectForMap = false;
3434
private static $constantSupport = false;
3535

36+
/**
37+
* @param int $flags
38+
* @param int|null $parsedLineNumber
39+
*/
40+
public static function initialize($flags, $parsedLineNumber = null)
41+
{
42+
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
43+
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
44+
self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags);
45+
self::$constantSupport = (bool) (Yaml::PARSE_CONSTANT & $flags);
46+
47+
if (null !== $parsedLineNumber) {
48+
self::$parsedLineNumber = $parsedLineNumber;
49+
}
50+
}
51+
3652
/**
3753
* Converts a YAML string to a PHP value.
3854
*
@@ -78,10 +94,7 @@ public static function parse($value, $flags = 0, $references = array())
7894
}
7995
}
8096

81-
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
82-
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
83-
self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags);
84-
self::$constantSupport = (bool) (Yaml::PARSE_CONSTANT & $flags);
97+
self::initialize($flags);
8598

8699
$value = trim($value);
87100

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Parser.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ private function doParse($value, $flags)
223223
$context = 'mapping';
224224

225225
// force correct settings
226-
Inline::parse(null, $flags, $this->refs);
226+
Inline::initialize($flags, $this->getRealCurrentLineNb());
227227
try {
228-
Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
229228
$i = 0;
230229
$evaluateKey = !(Yaml::PARSE_KEYS_AS_STRINGS & $flags);
231230

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.