Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitbcc2388

Browse files
GromNaNnicolas-grekas
authored andcommitted
[Yaml] Restore deprecated php/const: syntax in YAML key
1 parentea9ed6c commitbcc2388

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add support for`!php/enum` and`!php/enum *->value`
8+
* Deprecate the`!php/const:` tag in key which will be replaced by the`!php/const` tag (without the colon) since 3.4
89

910
6.1
1011
---

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,14 @@ private function doParse(string $value, int $flags)
198198
array_pop($this->refsBeingParsed);
199199
}
200200
}elseif (
201-
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|[^\'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u',rtrim($this->currentLine),$values)
201+
// @todo in 7.0 remove legacy "(?:!?!php/const:)?"
202+
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^\'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u',rtrim($this->currentLine),$values)
202203
&& (!str_contains($values['key'],' #') ||\in_array($values['key'][0], ['"',"'"]))
203204
) {
205+
if (str_starts_with($values['key'],'!php/const:')) {
206+
trigger_deprecation('symfony/yaml','6.2','YAML syntax for key "%s" is deprecated and replaced by "!php/const %s".',$values['key'],substr($values['key'],11));
207+
}
208+
204209
if ($context &&'sequence' ==$context) {
205210
thrownewParseException('You cannot define a mapping item when in a sequence.',$this->currentLineNb +1,$this->currentLine,$this->filename);
206211
}

‎src/Symfony/Component/Yaml/Tests/ParserTest.php‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
namespaceSymfony\Component\Yaml\Tests;
1313

1414
usePHPUnit\Framework\TestCase;
15+
useSymfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
useSymfony\Component\Yaml\Exception\ParseException;
1617
useSymfony\Component\Yaml\Parser;
1718
useSymfony\Component\Yaml\Tag\TaggedValue;
1819
useSymfony\Component\Yaml\Yaml;
1920

2021
class ParserTestextends TestCase
2122
{
22-
/** @var Parser */
23-
protected$parser;
23+
use ExpectDeprecationTrait;
24+
25+
private ?Parser$parser;
2426

2527
protectedfunctionsetUp():void
2628
{
@@ -1557,6 +1559,7 @@ public function testParseDateAsMappingValue()
15571559
/**
15581560
* @param $lineNumber
15591561
* @param $yaml
1562+
*
15601563
* @dataProvider parserThrowsExceptionWithCorrectLineNumberProvider
15611564
*/
15621565
publicfunctiontestParserThrowsExceptionWithCorrectLineNumber($lineNumber,$yaml)
@@ -2484,6 +2487,17 @@ public function testDeprecatedPhpConstantSyntax()
24842487
$this->parser->parse('!php/const:App\Kernel::SEMART_VERSION', Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT);
24852488
}
24862489

2490+
/**
2491+
* @group legacy
2492+
*/
2493+
publicfunctiontestDeprecatedPhpConstantSyntaxAsScalarKey()
2494+
{
2495+
$this->expectDeprecation('Since symfony/yaml 6.2: YAML syntax for key "!php/const:Symfony\Component\Yaml\Tests\B::BAR" is deprecated and replaced by "!php/const Symfony\Component\Yaml\Tests\B::BAR".');
2496+
$actual =$this->parser->parse('!php/const:Symfony\Component\Yaml\Tests\B::BAR: value', Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT);
2497+
2498+
$this->assertSame(['bar' =>'value'],$actual);
2499+
}
2500+
24872501
publicfunctiontestPhpConstantTagMappingAsScalarKey()
24882502
{
24892503
$yaml =<<<YAML

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp