You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/YamlExtension.php
+11-3
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@
12
12
namespaceSymfony\Bridge\Twig\Extension;
13
13
14
14
useSymfony\Component\Yaml\DumperasYamlDumper;
15
+
useSymfony\Component\Yaml\Yaml;
15
16
16
17
/**
17
18
* Provides integration of the Yaml component with Twig.
@@ -39,9 +40,16 @@ public function encode($input, $inline = 0, $dumpObjects = 0)
39
40
$dumper = newYamlDumper();
40
41
}
41
42
42
-
if (defined('Symfony\Component\Yaml\Yaml::DUMP_OBJECT') && is_bool($dumpObjects)) {
43
-
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
44
-
$dumpObjects = (int) $dumpObjects;
43
+
if (defined('Symfony\Component\Yaml\Yaml::DUMP_OBJECT')) {
44
+
if (is_bool($dumpObjects)) {
45
+
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
52
+
53
+
if ($flags) {
54
+
$flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE;
55
+
} else {
56
+
$flags = 0;
57
+
}
58
+
}
59
+
60
+
if (func_num_args() >= 5) {
52
61
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
53
62
54
-
$flags = (int) $flags;
63
+
if (func_get_arg(4)) {
64
+
$flags |= Yaml::DUMP_OBJECT;
65
+
}
55
66
}
56
67
57
68
$output = '';
58
69
$prefix = $indent ? str_repeat('', $indent) : '';
59
70
60
71
if ($inline <= 0 || !is_array($input) || empty($input)) {
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
130
+
131
+
if ($flags) {
132
+
$flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE;
133
+
} else {
134
+
$flags = 0;
135
+
}
136
+
}
137
+
138
+
if (func_num_args() >= 3) {
130
139
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
131
140
132
-
$flags = (int) $flags;
141
+
if (func_get_arg(2)) {
142
+
$flags |= Yaml::DUMP_OBJECT;
143
+
}
133
144
}
134
145
135
146
switch (true) {
136
147
caseis_resource($value):
137
-
if ($exceptionOnInvalidType) {
148
+
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
138
149
thrownewDumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value)));
139
150
}
140
151
@@ -144,13 +155,13 @@ public static function dump($value, $exceptionOnInvalidType = false, $flags = 0)
144
155
return'!php/object:'.serialize($value);
145
156
}
146
157
147
-
if ($exceptionOnInvalidType) {
158
+
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
148
159
thrownewDumpException('Object support when dumping a YAML file has been disabled.');
$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');
185
185
}
@@ -205,6 +205,15 @@ public function testObjectSupportDisabledButNoExceptions()
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
95
+
96
+
if ($flags) {
97
+
$flags = self::DUMP_EXCEPTION_ON_INVALID_TYPE;
98
+
} else {
99
+
$flags = 0;
100
+
}
101
+
}
102
+
103
+
if (func_num_args() >= 5) {
94
104
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
0 commit comments