remove legacy php/const and php/object tag support
This commit is contained in:
parent
b27c96558d
commit
7f6a0d8ef2
@ -554,30 +554,6 @@ class Inline
|
|||||||
return (string) substr($scalar, 6);
|
return (string) substr($scalar, 6);
|
||||||
case 0 === strpos($scalar, '! '):
|
case 0 === strpos($scalar, '! '):
|
||||||
return substr($scalar, 2);
|
return substr($scalar, 2);
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::$exceptionOnInvalidType) {
|
|
||||||
throw new ParseException('Object support when parsing a YAML file has been disabled.');
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (without the colon) tag instead.', E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
return unserialize(substr($scalar, 13));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::$exceptionOnInvalidType) {
|
|
||||||
throw new ParseException('Object support when parsing a YAML file has been disabled.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
case 0 === strpos($scalar, '!php/object'):
|
case 0 === strpos($scalar, '!php/object'):
|
||||||
if (self::$objectSupport) {
|
if (self::$objectSupport) {
|
||||||
return unserialize(self::parseScalar(substr($scalar, 12)));
|
return unserialize(self::parseScalar(substr($scalar, 12)));
|
||||||
@ -587,21 +563,6 @@ class Inline
|
|||||||
throw new ParseException('Object support when parsing a YAML file has been disabled.');
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
return;
|
||||||
case 0 === strpos($scalar, '!php/const'):
|
case 0 === strpos($scalar, '!php/const'):
|
||||||
if (self::$constantSupport) {
|
if (self::$constantSupport) {
|
||||||
@ -690,7 +651,7 @@ class Inline
|
|||||||
$nextOffset += strspn($value, ' ', $nextOffset);
|
$nextOffset += strspn($value, ' ', $nextOffset);
|
||||||
|
|
||||||
// Is followed by a scalar and is a built-in tag
|
// Is followed by a scalar and is a built-in tag
|
||||||
if ($tag && (!isset($value[$nextOffset]) || !in_array($value[$nextOffset], array('[', '{'), true)) && ('!' === $tag[0] || 'str' === $tag || 0 === strpos($tag, 'php/const:') || 0 === strpos($tag, 'php/object:'))) {
|
if ($tag && (!isset($value[$nextOffset]) || !in_array($value[$nextOffset], array('[', '{'), true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) {
|
||||||
// Manage in {@link self::evaluateScalar()}
|
// Manage in {@link self::evaluateScalar()}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -74,15 +74,6 @@ class InlineTest extends TestCase
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getTestsForDump
|
* @dataProvider getTestsForDump
|
||||||
*/
|
*/
|
||||||
|
@ -441,39 +441,12 @@ EOF;
|
|||||||
public function testObjectSupportDisabledButNoExceptions()
|
public function testObjectSupportDisabledButNoExceptions()
|
||||||
{
|
{
|
||||||
$input = <<<'EOF'
|
$input = <<<'EOF'
|
||||||
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
|
foo: !php/object O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
|
||||||
bar: 1
|
bar: 1
|
||||||
EOF;
|
EOF;
|
||||||
$this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
|
$this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
* @dataProvider deprecatedObjectValueProvider
|
|
||||||
*/
|
|
||||||
public function testObjectSupportEnabledWithDeprecatedTag($yaml)
|
|
||||||
{
|
|
||||||
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($yaml, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function deprecatedObjectValueProvider()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array(
|
|
||||||
<<<YAML
|
|
||||||
foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
|
||||||
bar: 1
|
|
||||||
YAML
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
<<<YAML
|
|
||||||
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
|
||||||
bar: 1
|
|
||||||
YAML
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getObjectForMapTests
|
* @dataProvider getObjectForMapTests
|
||||||
*/
|
*/
|
||||||
@ -1782,35 +1755,6 @@ YAML;
|
|||||||
|
|
||||||
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
|
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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.
|
|
||||||
* @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.
|
|
||||||
* @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 testDeprecatedPhpConstantTagMappingKey()
|
|
||||||
{
|
|
||||||
$yaml = <<<YAML
|
|
||||||
transitions:
|
|
||||||
!php/const:Symfony\Component\Yaml\Tests\B::FOO:
|
|
||||||
from:
|
|
||||||
- !php/const:Symfony\Component\Yaml\Tests\B::BAR
|
|
||||||
to: !php/const:Symfony\Component\Yaml\Tests\B::BAZ
|
|
||||||
YAML;
|
|
||||||
$expected = array(
|
|
||||||
'transitions' => array(
|
|
||||||
'foo' => array(
|
|
||||||
'from' => array(
|
|
||||||
'bar',
|
|
||||||
),
|
|
||||||
'to' => 'baz',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class B
|
class B
|
||||||
|
Reference in New Issue
Block a user