8000 [Yaml] Deprecate tags using colon by GuilhemN · Pull Request #22913 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Yaml] Deprecate tags using colon #22913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions UPGRADE-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ FrameworkBundle
require symfony/stopwatch` in your `dev` environment.

* Using the `KERNEL_DIR` environment variable or the automatic guessing based
on the `phpunit.xml` / `phpunit.xml.dist` file location is deprecated since 3.4.
on the `phpunit.xml` / `phpunit.xml.dist` file location is deprecated since 3.4.
Set the `KERNEL_CLASS` environment variable to the fully-qualified class name
of your Kernel instead. Not setting the `KERNEL_CLASS` environment variable
will throw an exception on 4.0 unless you override the `KernelTestCase::createKernel()`
of your Kernel instead. Not setting the `KERNEL_CLASS` environment variable
will throw an exception on 4.0 unless you override the `KernelTestCase::createKernel()`
or `KernelTestCase::getKernelClass()` method.
* The `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()`

* The `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()`
methods are deprecated since 3.4 and will be removed in 4.0.

* The `--no-prefix` option of the `translation:update` command is deprecated and
Expand Down Expand Up @@ -90,7 +90,7 @@ TwigBridge
* deprecated the `Symfony\Bridge\Twig\Form\TwigRenderer` class, use the `FormRenderer`
class from the Form component instead

* deprecated `Symfony\Bridge\Twig\Command\DebugCommand::set/getTwigEnvironment` and the ability
* deprecated `Symfony\Bridge\Twig\Command\DebugCommand::set/getTwigEnvironment` and the ability
to pass a command name as first argument

* deprecated `Symfony\Bridge\Twig\Command\LintCommand::set/getTwigEnvironment` and the ability
Expand All @@ -102,7 +102,7 @@ TwigBundle
* deprecated the `Symfony\Bundle\TwigBundle\Command\DebugCommand` class, use the `DebugCommand`
class from the Twig bridge instead

* deprecated relying on the `ContainerAwareInterface` implementation for
* deprecated relying on the `ContainerAwareInterface` implementation for
`Symfony\Bundle\TwigBundle\Command\LintCommand`

Validator
Expand All @@ -114,6 +114,24 @@ Validator
Yaml
----

* using the `!php/object:` tag is deprecated and won't be supported in 4.0. Use
the `!php/object` tag (without the colon) instead.

* using the `!php/const:` tag is deprecated and won't be supported in 4.0. Use
the `!php/const` tag (without the colon) instead.

Before:

```yml
!php/const:PHP_INT_MAX
```

After:

```yml
!php/const PHP_INT_MAX
```

* Support for the `!str` tag is deprecated, use the `!!str` tag instead.

* Using the non-specific tag `!` is deprecated and will have a different
Expand Down
28 changes: 23 additions & 5 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ FrameworkBundle
class instead.

* Using the `KERNEL_ 8000 DIR` environment variable and the automatic guessing based
on the `phpunit.xml` file location have been removed from the `KernelTestCase::getKernelClass()`
on the `phpunit.xml` file location have been removed from the `KernelTestCase::getKernelClass()`
method implementation. Set the `KERNEL_CLASS` environment variable to the
fully-qualified class name of your Kernel or override the `KernelTestCase::createKernel()`
fully-qualified class name of your Kernel or override the `KernelTestCase::createKernel()`
or `KernelTestCase::getKernelClass()` method instead.

* The `Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory` class has been removed.
Expand All @@ -356,10 +356,10 @@ FrameworkBundle
* The `--no-prefix` option of the `translation:update` command has
been removed.

* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheClearerPass` class has been removed.
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheClearerPass` class has been removed.
Use the `Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass` class instead.

* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass` class has been removed.
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass` class has been removed.
Use the `Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` class instead.

* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass`
Expand Down Expand Up @@ -561,7 +561,7 @@ TwigBridge
* The `TwigRendererEngine::setEnvironment()` method has been removed.
Pass the Twig Environment as second argument of the constructor instead.

* Removed `Symfony\Bridge\Twig\Command\DebugCommand::set/getTwigEnvironment` and the ability
* Removed `Symfony\Bridge\Twig\Command\DebugCommand::set/getTwigEnvironment` and the ability
to pass a command name as first argument.

* Removed `Symfony\Bridge\Twig\Command\LintCommand::set/getTwigEnvironment` and the ability
Expand Down Expand Up @@ -773,3 +773,21 @@ Yaml

* The behavior of the non-specific tag `!` is changed and now forces
non-evaluating your values.

* The `!php/object:` tag was removed in favor of the `!php/object` tag (without
the colon).

* The `!php/const:` tag was removed in favor of the `!php/const` tag (without
the colon).

Before:

```yml
!php/const:PHP_INT_MAX
```

After:

```yml
!php/const PHP_INT_MAX
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ parameters:
- false
- 0
- 1000.3
- !php/const:PHP_INT_MAX
- !php/const PHP_INT_MAX
bar: foo
escape: '@@escapeme'
foo_bar: '@foo_bar'
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/DependencyInjection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"psr/container": "^1.0"
},
"require-dev": {
"symfony/yaml": "~3.3|~4.0",
"symfony/yaml": "~3.4|~4.0",
"symfony/config": "~3.3|~4.0",
"symfony/expression-language": "~2.8|~3.0|~4.0"
},
Expand All @@ -35,7 +35,7 @@
"symfony/config": "<3.3.1",
"symfony/finder": "<3.3",
"symfony/proxy-manager-bridge": "<3.4",
"symfony/yaml": "<3.3"
"symfony/yaml": "<3.4"
},
"provide": {
"psr/container-implementation": "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public function testContext()
$obj = new \stdClass();
$obj->bar = 2;

$this->assertEquals(" foo: !php/object:O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}\n", $encoder->encode(array('foo' => $obj), 'yaml'));
$this->assertEquals(" foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'\n", $encoder->encode(array('foo' => $obj), 'yaml'));
$this->assertEquals(' { foo: null }', $encoder->encode(array('foo' => $obj), 'yaml', array('yaml_inline' => 0, 'yaml_indent' => 2, 'yaml_flags' => 0)));
$this->assertEquals(array('foo' => $obj), $encoder->decode('foo: !php/object:O:8:"stdClass":1:{s:3:"bar";i:2;}', 'yaml'));
$this->assertEquals(array('foo' => null), $encoder->decode('foo: !php/object:O:8:"stdClass":1:{s:3:"bar";i:2;}', 'yaml', array('yaml_flags' => 0)));
$this->assertEquals(array('foo' => $obj), $encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml'));
$this->assertEquals(array('foo' => null), $encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml', array('yaml_flags' => 0)));
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Serializer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=5.5.9"
},
"require-dev": {
"symfony/yaml": "~3.3|~4.0",
"symfony/yaml": "~3.4|~4.0",
"symfony/config": "~2.8|~3.0|~4.0",
"symfony/property-access": "~2.8|~3.0|~4.0",
"symfony/http-foundation": "~2.8|~3.0|~4.0",
Expand All @@ -34,7 +34,7 @@
"symfony/dependency-injection": "<3.2",
"symfony/property-access": ">=3.0,<3.0.4|>=2.8,<2.8.4",
"symfony/property-info": "<3.1",
"symfony/yaml": "<3.3"
"symfony/yaml": "<3.4"
},
"suggest": {
"psr/cache-implementation": "For using the metadata cache.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Symfony\Component\Validator\Tests\Fixtures\Entity:
properties:
firstName:
- Range:
max: !php/const:PHP_INT_MAX
max: !php/const PHP_INT_MAX
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"symfony/http-kernel": "^3.3.5|~4.0",
"symfony/var-dumper": "~3.3|~4.0",
"symfony/intl": "^2.8.18|^3.2.5|~4.0",
"symfony/yaml": "~3.3|~4.0",
"symfony/yaml": "~3.4|~4.0",
"symfony/config": "~2.8|~3.0|~4.0",
"symfony/dependency-injection": "~3.3|~4.0",
"symfony/expression-language": "~2.8|~3.0|~4.0",
Expand All @@ -39,7 +39,7 @@
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
"symfony/dependency-injection": "<3.3",
"symfony/http-kernel": "<3.3.5",
"symfony/yaml": "<3.3"
"symfony/yaml": "<3.4"
},
"suggest": {
"psr/cache-implementation": "For using the metadata cache.",
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/Yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ CHANGELOG
3.4.0
-----

* Deprecated the `!php/object:` tag which will be replaced by the
`!php/object` tag (without the colon) in 4.0.

* Deprecated the `!php/const:` tag which will be replaced by the
`!php/const` tag (without the colon) in 4.0.

* Support for the `!str` tag is deprecated, use the `!!str` tag instead.

* Deprecated using the non-specific tag `!` as its behavior will change in 4.0.
Expand Down
31 changes: 29 additions & 2 deletions src/Symfony/Component/Yaml/Inline.php
< F987 tr data-hunk="5e9b896e198dce6322bce183a38e2d00cc1480978963745af891a91f772b4f90" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static function dump($value, $flags = 0)
}

if (Yaml::DUMP_OBJECT & $flags) {
return '!php/object:'.serialize($value);
return '!php/object '.self::dump(serialize($value));
}

if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
Expand Down Expand Up @@ -620,6 +620,8 @@ private static function evaluateScalar($scalar, $flags, $references = array())
return (int) self::parseScalar(substr($scalar, 2), $flags);
case 0 === strpos($scalar, '!php/object:'):
if (self::$objectSupport) {
@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);

return unserialize(substr($scalar, 12));
}

Expand All @@ -630,7 +632,7 @@ private static function evaluateScalar($scalar, $flags, $references = array())
return;
case 0 === strpos($scalar, '!!php/object:'):
if (self::$objectSupport) {
@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);
@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);

return unserialize(substr($scalar, 13));
}
Expand All @@ -639,9 +641,21 @@ private static function evaluateScalar($scalar, $flags, $references = array())
throw new ParseException('Object support when parsing a YAML file has been disabled.');
}

return;
case 0 === strpos($scalar, '!php/object'):
if (self::$objectSupport) {
return unserialize(self::parseScalar(substr($scalar, 12)));
}

if (self::$exceptionOnInvalidType) {
throw new ParseException('Object support when parsing a YAML file has been disabled.');
}

return;
case 0 === strpos($scalar, '!php/const:'):
if (self::$constantSupport) {
@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);

if (defined($const = substr($scalar, 11))) {
return constant($const);
}
Expand All @@ -652,6 +666,19 @@ private static function evaluateScalar($scalar, $flags, $references = array())
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));
}

return;
case 0 === strpos($scalar, '!php/const'):
if (self::$constantSupport) {
if (defined($const = self::parseScalar(substr($scalar, 11)))) {
return constant($const);
}

throw new ParseException(sprintf('The constant "%s" is not defined.', $const));
}
if (self::$exceptionOnInvalidType) {
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));
}

return;
case 0 === strpos($scalar, '!!float '):
return (float) substr($scalar, 8);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private function doParse($value, $flags)
$this->refs[$isRef] = end($data);
}
} elseif (
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
&& (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))
) {
if ($context && 'sequence' == $context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testLintIncorrectFile()
public function testConstantAsKey()
{
$yaml = <<<YAML
!php/const:Symfony\Component\Yaml\Tests\Command\Foo::TEST: bar
!php/const 'Symfony\Component\Yaml\Tests\Command\Foo::TEST': bar
YAML;
$ret = $this->createCommandTester()->execute(array('filename' => $this->createFile($yaml)), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
$this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success');
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Yaml/Tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function testObjectSupportEnabled()
{
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, Yaml::DUMP_OBJECT);

$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');
$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');
}

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

$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');
$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');
}

public function testObjectSupportDisabledButNoExceptions()
Expand Down
23 changes: 16 additions & 7 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public function testParsePhpConstants($yaml, $value)
public function getTestsForParsePhpConstants()
{
return array(
array('!php/const:Symfony\Component\Yaml\Yaml::PARSE_CONSTANT', Yaml::PARSE_CONSTANT),
array('!php/const:PHP_INT_MAX', PHP_INT_MAX),
array('[!php/const:PHP_INT_MAX]', array(PHP_INT_MAX)),
array('{ foo: !php/const:PHP_INT_MAX }', array('foo' => PHP_INT_MAX)),
array('!php/const Symfony\Component\Yaml\Yaml::PARSE_CONSTANT', Yaml::PARSE_CONSTANT),
array('!php/const PHP_INT_MAX', PHP_INT_MAX),
array('[!php/const PHP_INT_MAX]', array(PHP_INT_MAX)),
array('{ foo: !php/const PHP_INT_MAX }', array('foo' => PHP_INT_MAX)),
);
}

Expand All @@ -62,16 +62,25 @@ public function getTestsForParsePhpConstants()
*/
public function testParsePhpConstantThrowsExceptionWhenUndefined()
{
Inline::parse('!php/const:WRONG_CONSTANT', Yaml::PARSE_CONSTANT);
Inline::parse('!php/const WRONG_CONSTANT', Yaml::PARSE_CONSTANT);
}

/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessageRegExp #The string "!php/const:PHP_INT_MAX" could not be parsed as a constant.*#
* @expectedExceptionMessageRegExp #The string "!php/const PHP_INT_MAX" could not be parsed as a constant.*#
*/
public function testParsePhpConstantThrowsExceptionOnInvalidType()
{
Inline::parse('!php/const:PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
Inline::parse('!php/const PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
}

/**
* @group legacy
* @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.
*/
public function testDeprecatedConstantTag()
{
Inline::parse('!php/const:PHP_INT_MAX', Yaml::PARSE_CONSTANT);
}

/**
Expand Down
Loading
0