Skip to content

Commit f618e43

Browse files
committed
include file and line no in deprecation message
1 parent bd3bc69 commit f618e43

File tree

3 files changed

+56
-28
lines changed

3 files changed

+56
-28
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i
348348
}
349349

350350
if ($output && '%' === $output[0]) {
351-
@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);
351+
@trigger_error(self::getDeprecationMessage(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);
352352
}
353353

354354
if ($evaluate) {
@@ -500,19 +500,19 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
500500
}
501501

502502
if (':' === $key) {
503-
@trigger_error('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
503+
@trigger_error(self::getDeprecationMessage('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.'), E_USER_DEPRECATED);
504504
}
505505

506506
if (!$isKeyQuoted) {
507507
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
508508

509509
if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey) && !is_int($evaluatedKey)) {
510-
@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);
510+
@trigger_error(self::getDeprecationMessage('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);
511511
}
512512
}
513513

514514
if (':' !== $key && !$isKeyQuoted && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
515-
@trigger_error('Using a colon after an unquoted mapping key 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);
515+
@trigger_error(self::getDeprecationMessage('Using a colon after an unquoted mapping key 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);
516516
}
517517

518518
while ($i < $len) {
@@ -532,7 +532,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
532532
// Parser cannot abort this mapping earlier, since lines
533533
// are processed sequentially.
534534
if (isset($output[$key])) {
535-
@trigger_error(sprintf('Duplicate key "%s" detected 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), E_USER_DEPRECATED);
535+
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected 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)), E_USER_DEPRECATED);
536536
$duplicate = true;
537537
}
538538
break;
@@ -543,7 +543,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
543543
// Parser cannot abort this mapping earlier, since lines
544544
// are processed sequentially.
545545
if (isset($output[$key])) {
546-
@trigger_error(sprintf('Duplicate key "%s" detected 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), E_USER_DEPRECATED);
546+
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected 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)), E_USER_DEPRECATED);
547547
$duplicate = true;
548548
}
549549
break;
@@ -553,7 +553,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
553553
// Parser cannot abort this mapping earlier, since lines
554554
// are processed sequentially.
555555
if (isset($output[$key])) {
556-
@trigger_error(sprintf('Duplicate key "%s" detected 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), E_USER_DEPRECATED);
556+
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected 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)), E_USER_DEPRECATED);
557557
$duplicate = true;
558558
}
559559
--$i;
@@ -622,18 +622,18 @@ private static function evaluateScalar($scalar, $flags, $references = array())
622622
case '!' === $scalar[0]:
623623
switch (true) {
624624
case 0 === strpos($scalar, '!str'):
625-
@trigger_error('Support for the !str tag is deprecated since version 3.4. Use the !!str tag instead.', E_USER_DEPRECATED);
625+
@trigger_error(self::getDeprecationMessage('Support for the !str tag is deprecated since version 3.4. Use the !!str tag instead.'), E_USER_DEPRECATED);
626626

627627
return (string) substr($scalar, 5);
628628
case 0 === strpos($scalar, '!!str '):
629629
return (string) substr($scalar, 6);
630630
case 0 === strpos($scalar, '! '):
631-
@trigger_error('Using the non-specific tag "!" is deprecated since version 3.4 as its behavior will change in 4.0. It will force non-evaluating your values in 4.0. Use plain integers or !!float instead.', E_USER_DEPRECATED);
631+
@trigger_error(self::getDeprecationMessage('Using the non-specific tag "!" is deprecated since version 3.4 as its behavior will change in 4.0. It will force non-evaluating your values in 4.0. Use plain integers or !!float instead.'), E_USER_DEPRECATED);
632632

633633
return (int) self::parseScalar(substr($scalar, 2), $flags);
634634
case 0 === strpos($scalar, '!php/object:'):
635635
if (self::$objectSupport) {
636-
@trigger_error('The !php/object: tag to indicate dumped PHP objects is deprecated since version 3.4 and will be removed in 4.0. Use the !php/object (without the colon) tag instead.', E_USER_DEPRECATED);
636+
@trigger_error(self::getDeprecationMessage('The !php/object: tag to indicate dumped PHP objects is deprecated since version 3.4 and will be removed in 4.0. Use the !php/object (without the colon) tag instead.'), E_USER_DEPRECATED);
637637

638638
return unserialize(substr($scalar, 12));
639639
}
@@ -645,7 +645,7 @@ private static function evaluateScalar($scalar, $flags, $references = array())
645645
return;
646646
case 0 === strpos($scalar, '!!php/object:'):
647647
if (self::$objectSupport) {
648-
@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 (without the colon) tag instead.', E_USER_DEPRECATED);
648+
@trigger_error(self::getDeprecationMessage('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 (without the colon) tag instead.'), E_USER_DEPRECATED);
649649

650650
return unserialize(substr($scalar, 13));
651651
}
@@ -667,7 +667,7 @@ private static function evaluateScalar($scalar, $flags, $references = array())
667667
return;
668668
case 0 === strpos($scalar, '!php/const:'):
669669
if (self::$constantSupport) {
670-
@trigger_error('The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead.', E_USER_DEPRECATED);
670+
@trigger_error(self::getDeprecationMessage('The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead.'), E_USER_DEPRECATED);
671671

672672
if (defined($const = substr($scalar, 11))) {
673673
return constant($const);
@@ -698,7 +698,7 @@ private static function evaluateScalar($scalar, $flags, $references = array())
698698
case 0 === strpos($scalar, '!!binary '):
699699
return self::evaluateBinaryScalar(substr($scalar, 9));
700700
default:
701-
@trigger_error(sprintf('Using the unquoted scalar value "%s" is deprecated since version 3.3 and will be considered as a tagged value in 4.0. You must quote it.', $scalar), E_USER_DEPRECATED);
701+
@trigger_error(self::getDeprecationMessage(sprintf('Using the unquoted scalar value "%s" is deprecated since version 3.3 and will be considered as a tagged value in 4.0. You must quote it.', $scalar)), E_USER_DEPRECATED);
702702
}
703703

704704
// Optimize for returning strings.
@@ -732,7 +732,7 @@ private static function evaluateScalar($scalar, $flags, $references = array())
732732
case Parser::preg_match('/^(-|\+)?[0-9][0-9,]*(\.[0-9_]+)?$/', $scalar):
733733
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
734734
if (false !== strpos($scalar, ',')) {
735-
@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);
735+
@trigger_error(self::getDeprecationMessage('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);
736736
}
737737

738738
return (float) str_replace(array(',', '_'), '', $scalar);
@@ -854,4 +854,19 @@ private static function getHexRegex()
854854
{
855855
return '~^0x[0-9a-f_]++$~i';
856856
}
857+
858+
private static function getDeprecationMessage($message)
859+
{
860+
$message = rtrim($message, '.');
861+
862+
if (null !== self::$parsedFilename) {
863+
$message .= ' in '.self::$parsedFilename;
864+
}
865+
866+
if (-1 !== self::$parsedLineNumber) {
867+
$message .= ' on line '.self::$parsedLineNumber;
868+
}
869+
870+
return $message.'.';
871+
}
857872
}

src/Symfony/Component/Yaml/Parser.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ private function doParse($value, $flags)
214214
}
215215

216216
if (isset($values['value'][1]) && '?' === $values['value'][0] && ' ' === $values['value'][1]) {
217-
@trigger_error('Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', E_USER_DEPRECATED);
217+
@trigger_error($this->getDeprecationMessage('Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.'), E_USER_DEPRECATED);
218218
}
219219

220220
// array
@@ -272,7 +272,7 @@ private function doParse($value, $flags)
272272

273273
if (!is_string($key) && !is_int($key)) {
274274
$keyType = is_numeric($key) ? 'numeric key' : 'non-string key';
275-
@trigger_error(sprintf('Implicit casting of %s to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', $keyType), E_USER_DEPRECATED);
275+
@trigger_error($this->getDeprecationMessage(sprintf('Implicit casting of %s to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', $keyType)), E_USER_DEPRECATED);
276276
}
277277

278278
// Convert float keys to strings, to avoid being converted to integers by PHP
@@ -346,7 +346,7 @@ private function doParse($value, $flags)
346346
$data[$key] = null;
347347
}
348348
} else {
349-
@trigger_error(sprintf('Duplicate key "%s" detected 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), E_USER_DEPRECATED);
349+
@trigger_error($this->getDeprecationMessage(sprintf('Duplicate key "%s" detected 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)), E_USER_DEPRECATED);
350350
}
351351
} else {
352352
// remember the parsed line number here in case we need it to provide some contexts in error messages below
@@ -361,7 +361,7 @@ private function doParse($value, $flags)
361361
$data[$key] = $value;
362362
}
363363
} else {
364-
@trigger_error(sprintf('Duplicate key "%s" detected 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), E_USER_DEPRECATED);
364+
@trigger_error($this->getDeprecationMessage(sprintf('Duplicate key "%s" detected 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)), E_USER_DEPRECATED);
365365
}
366366
}
367367
} else {
@@ -371,7 +371,7 @@ private function doParse($value, $flags)
371371
if ($allowOverwrite || !isset($data[$key])) {
372372
$data[$key] = $value;
373373
} else {
374-
@trigger_error(sprintf('Duplicate key "%s" detected 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), E_USER_DEPRECATED);
374+
@trigger_error($this->getDeprecationMessage(sprintf('Duplicate key "%s" detected 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)), E_USER_DEPRECATED);
375375
}
376376
}
377377
if ($isRef) {
@@ -384,7 +384,7 @@ private function doParse($value, $flags)
384384
}
385385

386386
if (isset($this->currentLine[1]) && '?' === $this->currentLine[0] && ' ' === $this->currentLine[1]) {
387-
@trigger_error('Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', E_USER_DEPRECATED);
387+
@trigger_error($this->getDeprecationMessage('Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.'), E_USER_DEPRECATED);
388388
}
389389

390390
// 1-liner optionally followed by newline(s)
@@ -699,7 +699,7 @@ private function parseValue($value, $flags, $context)
699699
if ('!!binary' === $matches['tag']) {
700700
return Inline::evaluateBinaryScalar($data);
701701
} elseif ('!' !== $matches['tag']) {
702-
@trigger_error(sprintf('Using the custom tag "%s" for the value "%s" is deprecated since version 3.3. It will be replaced by an instance of %s in 4.0.', $matches['tag'], $data, TaggedValue::class), E_USER_DEPRECATED);
702+
@trigger_error($this->getDeprecationMessage(sprintf('Using the custom tag "%s" for the value "%s" is deprecated since version 3.3. It will be replaced by an instance of %s in 4.0.', $matches['tag'], $data, TaggedValue::class)), E_USER_DEPRECATED);
703703
}
704704
}
705705

@@ -1083,4 +1083,17 @@ private function getLineTag($value, $flags, $nextLineCheck = true)
10831083

10841084
throw new ParseException(sprintf('Tags support is not enabled. You must use the flag `Yaml::PARSE_CUSTOM_TAGS` to use "%s".', $matches['tag']), $this->getRealCurrentLineNb() + 1, $value, $this->filename);
10851085
}
1086+
1087+
private function getDeprecationMessage($message)
1088+
{
1089+
$message = rtrim($message, '.');
1090+
1091+
if (null !== $this->filename) {
1092+
$message .= ' in '.$this->filename;
1093+
}
1094+
1095+
$message .= ' on line '.($this->getRealCurrentLineNb() + 1);
1096+
1097+
return $message.'.';
1098+
}
10861099
}

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