Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e5636dd

Browse files
committed
[Yaml] Deprecate tags using colon
1 parent e891d55 commit e5636dd

File tree

9 files changed

+153
-30
lines changed

9 files changed

+153
-30
lines changed

UPGRADE-3.4.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ FrameworkBundle
2525
require symfony/stopwatch` in your `dev` environment.
2626

2727
* Using the `KERNEL_DIR` environment variable or the automatic guessing based
28-
on the `phpunit.xml` / `phpunit.xml.dist` file location is deprecated since 3.4.
28+
on the `phpunit.xml` / `phpunit.xml.dist` file location is deprecated since 3.4.
2929
Set the `KERNEL_CLASS` environment variable to the fully-qualified class name
30-
of your Kernel instead. Not setting the `KERNEL_CLASS` environment variable
31-
will throw an exception on 4.0 unless you override the `KernelTestCase::createKernel()`
30+
of your Kernel instead. Not setting the `KERNEL_CLASS` environment variable
31+
will throw an exception on 4.0 unless you override the `KernelTestCase::createKernel()`
3232
or `KernelTestCase::getKernelClass()` method.
33-
34-
* The `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()`
33+
34+
* The `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()`
3535
methods are deprecated since 3.4 and will be removed in 4.0.
3636

3737
* The `--no-prefix` option of the `translation:update` command is deprecated and
@@ -61,5 +61,23 @@ Validator
6161
Yaml
6262
----
6363

64+
* using the `!php/object:` tag is deprecated and won't be supported in 4.0. Use
65+
the `!php/object` tag (without the colon) instead.
66+
67+
* using the `!php/const:` tag is deprecated and won't be supported in 4.0. Use
68+
the `!php/const` tag (without the colon) instead.
69+
70+
Before:
71+
72+
```yml
73+
!php/const:PHP_INT_MAX
74+
```
75+
76+
After:
77+
78+
```yml
79+
!php/const PHP_INT_MAX
80+
```
81+
6482
* Using the non-specific tag `!` is deprecated and will have a different
6583
behavior in 4.0. Use a plain integer or `!!float` instead.

UPGRADE-4.0.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ FrameworkBundle
332332
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass` class
333333
has been removed. Use the `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass`
334334
class instead.
335-
335+
336336
* Using the `KERNEL_DIR` environment variable and the automatic guessing based
337-
on the `phpunit.xml` file location have been removed from the `KernelTestCase::getKernelClass()`
337+
on the `phpunit.xml` file location have been removed from the `KernelTestCase::getKernelClass()`
338338
method implementation. Set the `KERNEL_CLASS` environment variable to the
339-
fully-qualified class name of your Kernel or override the `KernelTestCase::createKernel()`
339+
fully-qualified class name of your Kernel or override the `KernelTestCase::createKernel()`
340340
or `KernelTestCase::getKernelClass()` method instead.
341-
341+
342342
* The methods `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()`
343343
have been removed.
344344

@@ -705,3 +705,21 @@ Yaml
705705

706706
* The behavior of the non-specific tag `!` is changed and now forces
707707
non-evaluating your values.
708+
709+
* The `!php/object:` tag was removed in favor of the `!php/object` tag (without
710+
the colon).
711+
712+
* The `!php/const:` tag was removed in favor of the `!php/const` tag (without
713+
the colon).
714+
715+
Before:
716+
717+
```yml
718+
!php/const:PHP_INT_MAX
719+
```
720+
721+
After:
722+
723+
```yml
724+
!php/const PHP_INT_MAX
725+
```

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ CHANGELOG
44
3.4.0
55
-----
66

7+
* Deprecated the tag`!php/object:` tag which will be replaced by the
8+
`!php/object` tag (without the colon) in 4.0.
9+
10+
* Deprecated the tag`!php/const:` tag which will be replaced by the
11+
`!php/const` tag (without the colon) in 4.0.
12+
713
* Deprecated using the non-specific tag `!` as its behavior will change in 4.0.
814
It will force non-evaluating your values in 4.0. Use plain integers or `!!float` instead.
915

src/Symfony/Component/Yaml/Inline.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public static function dump($value, $flags = 0)
170170
}
171171

172172
if (Yaml::DUMP_OBJECT & $flags) {
173-
return '!php/object:'.serialize($value);
173+
return '!php/object '.self::dump(serialize($value));
174174
}
175175

176176
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
@@ -616,6 +616,8 @@ private static function evaluateScalar($scalar, $flags, $references = array())
616616
return (int) self::parseScalar(substr($scalar, 2), $flags);
617617
case 0 === strpos($scalar, '!php/object:'):
618618
if (self::$objectSupport) {
619+
@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);
620+
619621
return unserialize(substr($scalar, 12));
620622
}
621623

@@ -626,7 +628,7 @@ private static function evaluateScalar($scalar, $flags, $references = array())
626628
return;
627629
case 0 === strpos($scalar, '!!php/object:'):
628630
if (self::$objectSupport) {
629-
@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);
631+
@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);
630632

631633
return unserialize(substr($scalar, 13));
632634
}
@@ -635,9 +637,21 @@ private static function evaluateScalar($scalar, $flags, $references = array())
635637
throw new ParseException('Object support when parsing a YAML file has been disabled.');
636638
}
637639

640+
return;
641+
case 0 === strpos($scalar, '!php/object'):
642+
if (self::$objectSupport) {
643+
return unserialize(self::parseScalar(substr($scalar, 12)));
644+
}
645+
646+
if (self::$exceptionOnInvalidType) {
647+
throw new ParseException('Object support when parsing a YAML file has been disabled.');
648+
}
649+
638650
return;
639651
case 0 === strpos($scalar, '!php/const:'):
640652
if (self::$constantSupport) {
653+
@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);
654+
641655
if (defined($const = substr($scalar, 11))) {
642656
return constant($const);
643657
}
@@ -648,6 +662,20 @@ private static function evaluateScalar($scalar, $flags, $references = array())
648662
throw new ParseException(sprintf('The string "%s" could not be parsed as a constant. Have you forgotten to pass the "Yaml::PARSE_CONSTANT" flag to the parser?', $scalar));
649663
}
650664

665+
return;
666+
667+
case 0 === strpos($scalar, '!php/const'):
668+
if (self::$constantSupport) {
669+
if (defined($const = self::parseScalar(substr($scalar, 11)))) {
670+
return constant($const);
671+
}
672+
673+
throw new ParseException(sprintf('The constant "%s" is not defined.', $const));
674+
}
675+
if (self::$exceptionOnInvalidType) {
676+
throw new ParseException(sprintf('The string "%s" could not be parsed as a constant. Have you forgotten to pass the "Yaml::PARSE_CONSTANT" flag to the parser?', $scalar));
677+
}
678+
651679
return;
652680
case 0 === strpos($scalar, '!!float '):
653681
return (float) substr($scalar, 8);

src/Symfony/Component/Yaml/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private function doParse($value, $flags)
208208
$this->refs[$isRef] = end($data);
209209
}
210210
} elseif (
211-
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
211+
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
212212
&& (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))
213213
) {
214214
if ($context && 'sequence' == $context) {

src/Symfony/Component/Yaml/Tests/Command/LintCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testLintIncorrectFile()
5454
public function testConstantAsKey()
5555
{
5656
$yaml = <<<YAML
57-
!php/const:Symfony\Component\Yaml\Tests\Command\Foo::TEST: bar
57+
!php/const 'Symfony\Component\Yaml\Tests\Command\Foo::TEST': bar
5858
YAML;
5959
$ret = $this->createCommandTester()->execute(array('filename' => $this->createFile($yaml)), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
6060
$this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success');

src/Symfony/Component/Yaml/Tests/DumperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function testObjectSupportEnabled()
210210
{
211211
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, Yaml::DUMP_OBJECT);
212212

213-
$this->assertEquals('{ foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects');
213+
$this->assertEquals('{ foo: !php/object \'O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}\', bar: 1 }', $dump, '->dump() is able to dump objects');
214214
}
215215

216216
/**
@@ -220,7 +220,7 @@ public function testObjectSupportEnabledPassingTrue()
220220
{
221221
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true);
222222

223-
$this->assertEquals('{ foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects');
223+
$this->assertEquals('{ foo: !php/object \'O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}\', bar: 1 }', $dump, '->dump() is able to dump objects');
224224
}
225225

226226
public function testObjectSupportDisabledButNoExceptions()

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public function testParsePhpConstants($yaml, $value)
4949
public function getTestsForParsePhpConstants()
5050
{
5151
return array(
52-
array('!php/const:Symfony\Component\Yaml\Yaml::PARSE_CONSTANT', Yaml::PARSE_CONSTANT),
53-
array('!php/const:PHP_INT_MAX', PHP_INT_MAX),
54-
array('[!php/const:PHP_INT_MAX]', array(PHP_INT_MAX)),
55-
array('{ foo: !php/const:PHP_INT_MAX }', array('foo' => PHP_INT_MAX)),
52+
array('!php/const Symfony\Component\Yaml\Yaml::PARSE_CONSTANT', Yaml::PARSE_CONSTANT),
53+
array('!php/const PHP_INT_MAX', PHP_INT_MAX),
54+
array('[!php/const PHP_INT_MAX]', array(PHP_INT_MAX)),
55+
array('{ foo: !php/const PHP_INT_MAX }', array('foo' => PHP_INT_MAX)),
5656
);
5757
}
5858

@@ -62,16 +62,25 @@ public function getTestsForParsePhpConstants()
6262
*/
6363
public function testParsePhpConstantThrowsExceptionWhenUndefined()
6464
{
65-
Inline::parse('!php/const:WRONG_CONSTANT', Yaml::PARSE_CONSTANT);
65+
Inline::parse('!php/const WRONG_CONSTANT', Yaml::PARSE_CONSTANT);
6666
}
6767

6868
/**
6969
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
70-
* @expectedExceptionMessageRegExp #The string "!php/const:PHP_INT_MAX" could not be parsed as a constant.*#
70+
* @expectedExceptionMessageRegExp #The string "!php/const PHP_INT_MAX" could not be parsed as a constant.*#
7171
*/
7272
public function testParsePhpConstantThrowsExceptionOnInvalidType()
7373
{
74-
Inline::parse('!php/const:PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
74+
Inline::parse('!php/const PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
75+
}
76+
77+
/**
78+
* @group legacy
79+
* @expectedDeprecation 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.
80+
*/
81+
public function testDeprecatedConstantTag()
82+
{
83+
Inline::parse('!php/const:PHP_INT_MAX', Yaml::PARSE_CONSTANT);
7584
}
7685

7786
/**

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

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public function testBlockLiteralWithLeadingNewlines()
469469
public function testObjectSupportEnabled()
470470
{
471471
$input = <<<'EOF'
472-
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
472+
foo: !php/object O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
473473
bar: 1
474474
EOF;
475475
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
@@ -489,14 +489,29 @@ public function testObjectSupportEnabledPassingTrue()
489489

490490
/**
491491
* @group legacy
492+
* @dataProvider deprecatedObjectValueProvider
492493
*/
493-
public function testObjectSupportEnabledWithDeprecatedTag()
494+
public function testObjectSupportEnabledWithDeprecatedTag($yaml)
494495
{
495-
$input = <<<'EOF'
496+
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($yaml, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
497+
}
498+
499+
public function deprecatedObjectValueProvider()
500+
{
501+
return array(
502+
array(
503+
<<<YAML
496504
foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
497505
bar: 1
498-
EOF;
499-
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
506+
YAML
507+
),
508+
array(
509+
<<<YAML
510+
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
511+
bar: 1
512+
YAML
513+
),
514+
);
500515
}
501516

502517
/**
@@ -1823,6 +1838,35 @@ public function testParserCleansUpReferencesBetweenRuns()
18231838
public function testPhpConstantTagMappingKey()
18241839
{
18251840
$yaml = <<<YAML
1841+
transitions:
1842+
!php/const 'Symfony\Component\Yaml\Tests\B::FOO':
1843+
from:
1844+
- !php/const 'Symfony\Component\Yaml\Tests\B::BAR'
1845+
to: !php/const 'Symfony\Component\Yaml\Tests\B::BAZ'
1846+
YAML;
1847+
$expected = array(
1848+
'transitions' => array(
1849+
'foo' => array(
1850+
'from' => array(
1851+
'bar',
1852+
),
1853+
'to' => 'baz',
1854+
),
1855+
),
1856+
);
1857+
1858+
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
1859+
}
1860+
1861+
/**
1862+
* @group legacy
1863+
* @expectedDeprecation 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.
1864+
* @expectedDeprecation 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.
1865+
* @expectedDeprecation 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.
1866+
*/
1867+
public function testDeprecatedPhpConstantTagMappingKey()
1868+
{
1869+
$yaml = <<<YAML
18261870
transitions:
18271871
!php/const:Symfony\Component\Yaml\Tests\B::FOO:
18281872
from:
@@ -1847,10 +1891,10 @@ public function testPhpConstantTagMappingKeyWithKeysCastToStrings()
18471891
{
18481892
$yaml = <<<YAML
18491893
transitions:
1850-
!php/const:Symfony\Component\Yaml\Tests\B::FOO:
1894+
!php/const 'Symfony\Component\Yaml\Tests\B::FOO':
18511895
from:
1852-
- !php/const:Symfony\Component\Yaml\Tests\B::BAR
1853-
to: !php/const:Symfony\Component\Yaml\Tests\B::BAZ
1896+
- !php/const 'Symfony\Component\Yaml\Tests\B::BAR'
1897+
to: !php/const 'Symfony\Component\Yaml\Tests\B::BAZ'
18541898
YAML;
18551899
$expected = array(
18561900
'transitions' => array(

0 commit comments

Comments
 (0)