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 26074f9

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 26074f9
Copy full SHA for 26074f9

File tree

2 files changed

+14
-6
lines changed
Filter options

2 files changed

+14
-6
lines changed

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

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

36+
public static function initialize(int $flags, int $parsedLineNumber = null)
37+
{
38+
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
39+
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
40+
self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags);
41+
self::$constantSupport = (bool) (Yaml::PARSE_CONSTANT & $flags);
42+
43+
if (null !== $parsedLineNumber) {
44+
self::$parsedLineNumber = $parsedLineNumber;
45+
}
46+
}
47+
3648
/**
3749
* Converts a YAML string to a PHP value.
3850
*
@@ -78,10 +90,7 @@ public static function parse($value, $flags = 0, $references = array())
7890
}
7991
}
8092

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);
93+
self::initialize($flags);
8594

8695
$value = trim($value);
8796

‎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.