Skip to content

Commit baa1e7f

Browse files
committed
minor symfony#22913 [Yaml] Deprecate tags using colon (GuilhemN)
This PR was squashed before being merged into the 3.4 branch (closes symfony#22913). Discussion ---------- [Yaml] Deprecate tags using colon | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Using a colon in a tag doesn't look like yaml and causes trouble (see symfony#22878), so I propose to just deprecate these tags in favor of more consistent tags. ```yml - !php/const:PHP_INT_MAX - !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` would become ```yml - !php/const PHP_INT_MAX - !php/object O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` Commits ------- 9815af3 [Yaml] Deprecate tags using colon
2 parents 0f2563c + 9815af3 commit baa1e7f

File tree

15 files changed

+154
-32
lines changed

15 files changed

+154
-32
lines changed

UPGRADE-3.4.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,24 @@ Validator
158158
Yaml
159159
----
160160

161+
* using the `!php/object:` tag is deprecated and won't be supported in 4.0. Use
162+
the `!php/object` tag (without the colon) instead.
163+
164+
* using the `!php/const:` tag is deprecated and won't be supported in 4.0. Use
165+
the `!php/const` tag (without the colon) instead.
166+
167+
Before:
168+
169+
```yml
170+
!php/const:PHP_INT_MAX
171+
```
172+
173+
After:
174+
175+
```yml
176+
!php/const PHP_INT_MAX
177+
```
178+
161179
* Support for the `!str` tag is deprecated, use the `!!str` tag instead.
162180

163181
* Using the non-specific tag `!` is deprecated and will have a different

UPGRADE-4.0.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,3 +843,21 @@ Yaml
843843

844844
* The behavior of the non-specific tag `!` is changed and now forces
845845
non-evaluating your values.
846+
847+
* The `!php/object:` tag was removed in favor of the `!php/object` tag (without
848+
the colon).
849+
850+
* The `!php/const:` tag was removed in favor of the `!php/const` tag (without
851+
the colon).
852+
853+
Before:
854+
855+
```yml
856+
!php/const:PHP_INT_MAX
857+
```
858+
859+
After:
860+
861+
```yml
862+
!php/const PHP_INT_MAX
863+
```

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ parameters:
55
- false
66
- 0
77
- 1000.3
8-
- !php/const:PHP_INT_MAX
8+
- !php/const PHP_INT_MAX
99
bar: foo
1010
escape: '@@escapeme'
1111
foo_bar: '@foo_bar'

src/Symfony/Component/DependencyInjection/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"psr/container": "^1.0"
2121
},
2222
"require-dev": {
23-
"symfony/yaml": "~3.3|~4.0",
23+
"symfony/yaml": "~3.4|~4.0",
2424
"symfony/config": "~3.3|~4.0",
2525
"symfony/expression-language": "~2.8|~3.0|~4.0"
2626
},
@@ -35,7 +35,7 @@
3535
"symfony/config": "<3.3.1",
3636
"symfony/finder": "<3.3",
3737
"symfony/proxy-manager-bridge": "<3.4",
38-
"symfony/yaml": "<3.3"
38+
"symfony/yaml": "<3.4"
3939
},
4040
"provide": {
4141
"psr/container-implementation": "1.0"

src/Symfony/Component/Serializer/Tests/Encoder/YamlEncoderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public function testContext()
6161
$obj = new \stdClass();
6262
$obj->bar = 2;
6363

64-
$this->assertEquals(" foo: !php/object:O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}\n", $encoder->encode(array('foo' => $obj), 'yaml'));
64+
$this->assertEquals(" foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'\n", $encoder->encode(array('foo' => $obj), 'yaml'));
6565
$this->assertEquals(' { foo: null }', $encoder->encode(array('foo' => $obj), 'yaml', array('yaml_inline' => 0, 'yaml_indent' => 2, 'yaml_flags' => 0)));
66-
$this->assertEquals(array('foo' => $obj), $encoder->decode('foo: !php/object:O:8:"stdClass":1:{s:3:"bar";i:2;}', 'yaml'));
67-
$this->assertEquals(array('foo' => null), $encoder->decode('foo: !php/object:O:8:"stdClass":1:{s:3:"bar";i:2;}', 'yaml', array('yaml_flags' => 0)));
66+
$this->assertEquals(array('foo' => $obj), $encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml'));
67+
$this->assertEquals(array('foo' => null), $encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml', array('yaml_flags' => 0)));
6868
}
6969
}

src/Symfony/Component/Serializer/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": "^5.5.9|>=7.0.8"
2020
},
2121
"require-dev": {
22-
"symfony/yaml": "~3.3|~4.0",
22+
"symfony/yaml": "~3.4|~4.0",
2323
"symfony/config": "~2.8|~3.0|~4.0",
2424
"symfony/property-access": "~2.8|~3.0|~4.0",
2525
"symfony/http-foundation": "~2.8|~3.0|~4.0",
@@ -34,7 +34,7 @@
3434
"symfony/dependency-injection": "<3.2",
3535
"symfony/property-access": ">=3.0,<3.0.4|>=2.8,<2.8.4",
3636
"symfony/property-info": "<3.1",
37-
"symfony/yaml": "<3.3"
37+
"symfony/yaml": "<3.4"
3838
},
3939
"suggest": {
4040
"psr/cache-implementation": "For using the metadata cache.",

src/Symfony/Component/Validator/Tests/Mapping/Loader/mapping-with-constants.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Symfony\Component\Validator\Tests\Fixtures\Entity:
55
properties:
66
firstName:
77
- Range:
8-
max: !php/const:PHP_INT_MAX
8+
max: !php/const PHP_INT_MAX

src/Symfony/Component/Validator/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"symfony/http-kernel": "^3.3.5|~4.0",
2626
"symfony/var-dumper": "~3.3|~4.0",
2727
"symfony/intl": "^2.8.18|^3.2.5|~4.0",
28-
"symfony/yaml": "~3.3|~4.0",
28+
"symfony/yaml": "~3.4|~4.0",
2929
"symfony/config": "~2.8|~3.0|~4.0",
3030
"symfony/dependency-injection": "~3.3|~4.0",
3131
"symfony/expression-language": "~2.8|~3.0|~4.0",
@@ -39,7 +39,7 @@
3939
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
4040
"symfony/dependency-injection": "<3.3",
4141
"symfony/http-kernel": "<3.3.5",
42-
"symfony/yaml": "<3.3"
42+
"symfony/yaml": "<3.4"
4343
},
4444
"suggest": {
4545
"psr/cache-implementation": "For using the metadata cache.",

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 `!php/object:` tag which will be replaced by the
8+
`!php/object` tag (without the colon) in 4.0.
9+
10+
* Deprecated the `!php/const:` tag which will be replaced by the
11+
`!php/const` tag (without the colon) in 4.0.
12+
713
* Support for the `!str` tag is deprecated, use the `!!str` tag instead.
814

915
* Deprecated using the non-specific tag `!` as its behavior will change in 4.0.

src/Symfony/Component/Yaml/Inline.php

Lines changed: 29 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)) {
@@ -620,6 +620,8 @@ private static function evaluateScalar($scalar, $flags, $references = array())
620620
return (int) self::parseScalar(substr($scalar, 2), $flags);
621621
case 0 === strpos($scalar, '!php/object:'):
622622
if (self::$objectSupport) {
623+
@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);
624+
623625
return unserialize(substr($scalar, 12));
624626
}
625627

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

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

644+
return;
645+
case 0 === strpos($scalar, '!php/object'):
646+
if (self::$objectSupport) {
647+
return unserialize(self::parseScalar(substr($scalar, 12)));
648+
}
649+
650+
if (self::$exceptionOnInvalidType) {
651+
throw new ParseException('Object support when parsing a YAML file has been disabled.');
652+
}
653+
642654
return;
643655
case 0 === strpos($scalar, '!php/const:'):
644656
if (self::$constantSupport) {
657+
@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);
658+
645659
if (defined($const = substr($scalar, 11))) {
646660
return constant($const);
647661
}
@@ -652,6 +666,19 @@ private static function evaluateScalar($scalar, $flags, $references = array())
652666
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));
653667
}
654668

669+
return;
670+
case 0 === strpos($scalar, '!php/const'):
671+
if (self::$constantSupport) {
672+
if (defined($const = self::parseScalar(substr($scalar, 11)))) {
673+
return constant($const);
674+
}
675+
676+
throw new ParseException(sprintf('The constant "%s" is not defined.', $const));
677+
}
678+
if (self::$exceptionOnInvalidType) {
679+
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));
680+
}
681+
655682
return;
656683
case 0 === strpos($scalar, '!!float '):
657684
return (float) substr($scalar, 8);

0 commit comments

Comments
 (0)