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 c7edc87

Browse filesBrowse files
committed
feature #22770 [Yaml] remove deprecated features (xabbuh)
This PR was merged into the 4.0-dev branch. Discussion ---------- [Yaml] remove deprecated features | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- efe2337 [Yaml] remove deprecated features
2 parents 044c00e + efe2337 commit c7edc87
Copy full SHA for c7edc87

13 files changed

+89
-583
lines changed

‎src/Symfony/Component/Yaml/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/CHANGELOG.md
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
CHANGELOG
22
=========
33

4+
4.0.0
5+
-----
6+
7+
* complex mappings will throw a `ParseException`
8+
* support for the comma as a group separator for floats has been dropped, use
9+
the underscore instead
10+
* support for the `!!php/object` tag has been dropped, use the `!php/object`
11+
tag instead
12+
* duplicate mapping keys throw a `ParseException`
13+
* non-string mapping keys throw a `ParseException`, use the `Yaml::PARSE_KEYS_AS_STRINGS`
14+
flag to cast them to strings
15+
* `%` at the beginning of an unquoted string throw a `ParseException`
16+
* mappings with a colon (`:`) that is not followed by a whitespace throw a
17+
`ParseException`
18+
* the `Dumper::setIndentation()` method has been removed
19+
* being able to pass boolean options to the `Yaml::parse()`, `Yaml::dump()`,
20+
`Parser::parse()`, and `Dumper::dump()` methods to configure the behavior of
21+
the parser and dumper is no longer supported, pass bitmask flags instead
22+
* the constructor arguments of the `Parser` class have been removed
23+
* the `Inline` class is internal and no longer part of the BC promise
24+
425
3.3.0
526
-----
627

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Dumper.php
-30Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@ public function __construct($indentation = 4)
3737
$this->indentation = $indentation;
3838
}
3939

40-
/**
41-
* Sets the indentation.
42-
*
43-
* @param int $num The amount of spaces to use for indentation of nested nodes
44-
*/
45-
public function setIndentation($num)
46-
{
47-
@trigger_error('The '.__METHOD__.' method is deprecated since version 3.1 and will be removed in 4.0. Pass the indentation to the constructor instead.', E_USER_DEPRECATED);
48-
49-
$this->indentation = (int) $num;
50-
}
51-
5240
/**
5341
* Dumps a PHP value to YAML.
5442
*
@@ -61,24 +49,6 @@ public function setIndentation($num)
6149
*/
6250
public function dump($input, $inline = 0, $indent = 0, $flags = 0)
6351
{
64-
if (is_bool($flags)) {
65-
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
66-
67-
if ($flags) {
68-
$flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE;
69-
} else {
70-
$flags = 0;
71-
}
72-
}
73-
74-
if (func_num_args() >= 5) {
75-
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
76-
77-
if (func_get_arg(4)) {
78-
$flags |= Yaml::DUMP_OBJECT;
79-
}
80-
}
81-
8252
$output = '';
8353
$prefix = $indent ? str_repeat(' ', $indent) : '';
8454
$dumpObjectAsInlineMap = true;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+21-96Lines changed: 21 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,6 @@ class Inline
4646
*/
4747
public static function parse($value, $flags = 0, $references = array())
4848
{
49-
if (is_bool($flags)) {
50-
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
51-
52-
if ($flags) {
53-
$flags = Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE;
54-
} else {
55-
$flags = 0;
56-
}
57-
}
58-
59-
if (func_num_args() >= 3 && !is_array($references)) {
60-
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT flag instead.', E_USER_DEPRECATED);
61-
62-
if ($references) {
63-
$flags |= Yaml::PARSE_OBJECT;
64-
}
65-
66-
if (func_num_args() >= 4) {
67-
@trigger_error('Passing a boolean flag to toggle object for map support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT_FOR_MAP flag instead.', E_USER_DEPRECATED);
68-
69-
if (func_get_arg(3)) {
70-
$flags |= Yaml::PARSE_OBJECT_FOR_MAP;
71-
}
72-
}
73-
74-
if (func_num_args() >= 5) {
75-
$references = func_get_arg(4);
76-
} else {
77-
$references = array();
78-
}
79-
}
80-
8149
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
8250
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
8351
self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags);
@@ -137,24 +105,6 @@ public static function parse($value, $flags = 0, $references = array())
137105
*/
138106
public static function dump($value, $flags = 0)
139107
{
140-
if (is_bool($flags)) {
141-
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
142-
143-
if ($flags) {
144-
$flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE;
145-
} else {
146-
$flags = 0;
147-
}
148-
}
149-
150-
if (func_num_args() >= 3) {
151-
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
152-
153-
if (func_get_arg(2)) {
154-
$flags |= Yaml::DUMP_OBJECT;
155-
}
156-
}
157-
158108
switch (true) {
159109
case is_resource($value):
160110
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
@@ -300,7 +250,7 @@ private static function dumpArray($value, $flags)
300250
*
301251
* @internal
302252
*/
303-
public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i = 0, $evaluate = true, $references = array(), $legacyOmittedKeySupport = false)
253+
public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i = 0, $evaluate = true, $references = array())
304254
{
305255
if (in_array($scalar[$i], array('"', "'"))) {
306256
// quoted scalar
@@ -322,22 +272,18 @@ public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i
322272
if (Parser::preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) {
323273
$output = substr($output, 0, $match[0][1]);
324274
}
325-
} elseif (Parser::preg_match('/^(.'.($legacyOmittedKeySupport ? '+' : '*').'?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
275+
} elseif (Parser::preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
326276
$output = $match[1];
327277
$i += strlen($output);
328278
} else {
329279
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar));
330280
}
331281

332282
// a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >)
333-
if ($output && ('@' === $output[0] || '`' === $output[0] || '|' === $output[0] || '>' === $output[0])) {
283+
if ($output && ('@' === $output[0] || '`' === $output[0] || '|' === $output[0] || '>' === $output[0] || '%' === $output[0])) {
334284
throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]));
335285
}
336286

337-
if ($output && '%' === $output[0]) {
338-
@trigger_error(sprintf('Not quoting the scalar "%s" starting with the "%%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.', $output), E_USER_DEPRECATED);
339-
}
340-
341287
if ($evaluate) {
342288
$output = self::evaluateScalar($output, $flags, $references);
343289
}
@@ -479,26 +425,27 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
479425
}
480426

481427
// key
482-
$key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false, array(), true);
428+
$offsetBeforeKeyParsing = $i;
429+
$key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false, array());
483430

484-
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
485-
break;
431+
if ($offsetBeforeKeyParsing === $i) {
432+
throw new ParseException('Missing mapping key.', self::$parsedLineNumber + 1, $mapping);
486433
}
487434

488-
if (':' === $key) {
489-
@trigger_error('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
435+
if (false === $i = strpos($mapping, ':', $i)) {
436+
break;
490437
}
491438

492439
if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags)) {
493440
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
494441

495442
if ('' !== $key && $evaluatedKey !== $key && !is_string($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. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.', E_USER_DEPRECATED);
443+
throw new ParseException('Non-string mapping keys are not supported. Pass the Yaml::PARSE_KEYS_AS_STRINGS flag to cast them to strings.', self::$parsedLineNumber + 1, $mapping);
497444
}
498445
}
499446

500-
if (':' !== $key && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
501-
@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);
447+
if (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true)) {
448+
throw new ParseException('Colons must be followed by a space or an indication character (i.e. " ", ",", "[", "]", "{", "}").', self::$parsedLineNumber + 1, $mapping);
502449
}
503450

504451
while ($i < $len) {
@@ -509,7 +456,6 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
509456
}
510457

511458
$tag = self::parseTag($mapping, $i, $flags);
512-
$duplicate = false;
513459
switch ($mapping[$i]) {
514460
case '[':
515461
// nested sequence
@@ -518,8 +464,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
518464
// Parser cannot abort this mapping earlier, since lines
519465
// are processed sequentially.
520466
if (isset($output[$key])) {
521-
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
522-
$duplicate = true;
467+
throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping);
523468
}
524469
break;
525470
case '{':
@@ -529,8 +474,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
529474
// Parser cannot abort this mapping earlier, since lines
530475
// are processed sequentially.
531476
if (isset($output[$key])) {
532-
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
533-
$duplicate = true;
477+
throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping);
534478
}
535479
break;
536480
default:
@@ -539,19 +483,17 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
539483
// Parser cannot abort this mapping earlier, since lines
540484
// are processed sequentially.
541485
if (isset($output[$key])) {
542-
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
543-
$duplicate = true;
486+
throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping);
544487
}
545488
--$i;
546489
}
547490

548-
if (!$duplicate) {
549-
if (null !== $tag) {
550-
$output[$key] = new TaggedValue($tag, $value);
551-
} else {
552-
$output[$key] = $value;
553-
}
491+
if (null !== $tag) {
492+
$output[$key] = new TaggedValue($tag, $value);
493+
} else {
494+
$output[$key] = $value;
554495
}
496+
555497
++$i;
556498

557499
continue 2;
@@ -620,18 +562,6 @@ private static function evaluateScalar($scalar, $flags, $references = array())
620562
throw new ParseException('Object support when parsing a YAML file has been disabled.');
621563
}
622564

623-
return;
624-
case 0 === strpos($scalar, '!!php/object:'):
625-
if (self::$objectSupport) {
626-
@trigger_error('The !!php/object tag to indicate dumped PHP objects is deprecated since version 3.1 and will be removed in 4.0. Use the !php/object tag instead.', E_USER_DEPRECATED);
627-
628-
return unserialize(substr($scalar, 13));
629-
}
630-
631-
if (self::$exceptionOnInvalidType) {
632-
throw new ParseException('Object support when parsing a YAML file has been disabled.');
633-
}
634-
635565
return;
636566
case 0 === strpos($scalar, '!php/const:'):
637567
if (self::$constantSupport) {
@@ -680,13 +610,8 @@ private static function evaluateScalar($scalar, $flags, $references = array())
680610
return -log(0);
681611
case '-.inf' === $scalarLower:
682612
return log(0);
683-
case Parser::preg_match('/^(-|\+)?[0-9][0-9,]*(\.[0-9_]+)?$/', $scalar):
684613
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
685-
if (false !== strpos($scalar, ',')) {
686-
@trigger_error('Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0.', E_USER_DEPRECATED);
687-
}
688-
689-
return (float) str_replace(array(',', '_'), '', $scalar);
614+
return (float) str_replace('_', '', $scalar);
690615
case Parser::preg_match(self::getTimestampRegex(), $scalar):
691616
if (Yaml::PARSE_DATETIME & $flags) {
692617
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.

0 commit comments

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