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/Component/DependencyInjection/Loader/YamlFileLoader.php
+67-16Lines changed: 67 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -148,9 +148,56 @@ private function parseDefinitions($content, $file)
148
148
if (!is_array($content['services'])) {
149
149
thrownewInvalidArgumentException(sprintf('The "services" key should contain an array in %s. Check your YAML syntax.', $file));
150
150
}
151
+
if (isset($content['services']['_defaults'])) {
152
+
if (!is_array($defaults = $content['services']['_defaults'])) {
153
+
thrownewInvalidArgumentException(sprintf('Service defaults must be an array, "%s" given in "%s".', gettype($defaults), $file));
154
+
}
155
+
if (isset($defaults['alias']) || isset($defaults['class']) || isset($defaults['factory'])) {
156
+
@trigger_error('Giving a service the "_defaults" name is deprecated since Symfony 3.3 and will be forbidden in 4.0. Rename your service.', E_USER_DEPRECATED);
thrownewInvalidArgumentException(sprintf('The configuration key "%s" cannot be used to define a default value in "%s". Allowed keys are "%s".', $key, $file, implode('", "', $defaultKeys)));
165
+
}
166
+
}
167
+
if (isset($defaults['tags'])) {
168
+
if (!is_array($tags = $defaults['tags'])) {
169
+
thrownewInvalidArgumentException(sprintf('Parameter "tags" in "_defaults" must be an array in %s. Check your YAML syntax.', $file));
170
+
}
171
+
172
+
foreach ($tagsas$tag) {
173
+
if (!is_array($tag)) {
174
+
$tag = array('name' => $tag);
175
+
}
176
+
177
+
if (!isset($tag['name'])) {
178
+
thrownewInvalidArgumentException(sprintf('A "tags" entry in "_defaults" is missing a "name" key in %s.', $file));
179
+
}
180
+
$name = $tag['name'];
181
+
unset($tag['name']);
182
+
183
+
if (!is_string($name) || '' === $name) {
184
+
thrownewInvalidArgumentException(sprintf('The tag name in "_defaults" must be a non-empty string in %s.', $file));
185
+
}
186
+
187
+
foreach ($tagas$attribute => $value) {
188
+
if (!is_scalar($value) && null !== $value) {
189
+
thrownewInvalidArgumentException(sprintf('Tag "%s", attribute "%s" in "_defaults" must be of a scalar-type in %s. Check your YAML syntax.', $name, $attribute, $file));
thrownewInvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
268
319
}
269
320
270
-
foreach ($service['tags']as$tag) {
321
+
foreach ($tagsas$tag) {
271
322
if (!is_array($tag)) {
272
323
$tag = array('name' => $tag);
273
324
}
274
325
275
326
if (!isset($tag['name'])) {
276
327
thrownewInvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
277
328
}
329
+
$name = $tag['name'];
330
+
unset($tag['name']);
278
331
279
-
if (!is_string($tag['name']) || '' === $tag['name']) {
332
+
if (!is_string($name) || '' === $name) {
280
333
thrownewInvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
281
334
}
282
335
283
-
$name = $tag['name'];
284
-
unset($tag['name']);
285
-
286
336
foreach ($tagas$attribute => $value) {
287
337
if (!is_scalar($value) && null !== $value) {
288
338
thrownewInvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file));
@@ -303,11 +353,12 @@ private function parseDefinition($id, $service, $file)
* @expectedExceptionMessage The value of the "decorates" option for the "bar" service must be the id of the service without the "@" prefix (replace "@foo" with "foo").
0 commit comments