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
@@ -146,9 +146,56 @@ private function parseDefinitions($content, $file)
146
146
if (!is_array($content['services'])) {
147
147
thrownewInvalidArgumentException(sprintf('The "services" key should contain an array in %s. Check your YAML syntax.', $file));
148
148
}
149
+
if (isset($content['services']['_defaults'])) {
150
+
if (!is_array($defaults = $content['services']['_defaults'])) {
151
+
thrownewInvalidArgumentException(sprintf('Service defaults must be an array, "%s" given in "%s".', gettype($defaults), $file));
152
+
}
153
+
if (isset($defaults['alias']) || isset($defaults['class']) || isset($defaults['factory'])) {
154
+
@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)));
163
+
}
164
+
}
165
+
if (isset($defaults['tags'])) {
166
+
if (!is_array($tags = $defaults['tags'])) {
167
+
thrownewInvalidArgumentException(sprintf('Parameter "tags" in "_defaults" must be an array in %s. Check your YAML syntax.', $file));
168
+
}
169
+
170
+
foreach ($tagsas$tag) {
171
+
if (!is_array($tag)) {
172
+
$tag = array('name' => $tag);
173
+
}
174
+
175
+
if (!isset($tag['name'])) {
176
+
thrownewInvalidArgumentException(sprintf('A "tags" entry in "_defaults" is missing a "name" key in %s.', $file));
177
+
}
178
+
$name = $tag['name'];
179
+
unset($tag['name']);
180
+
181
+
if (!is_string($name) || '' === $name) {
182
+
thrownewInvalidArgumentException(sprintf('The tag name in "_defaults" must be a non-empty string in %s.', $file));
183
+
}
184
+
185
+
foreach ($tagas$attribute => $value) {
186
+
if (!is_scalar($value) && null !== $value) {
187
+
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));
266
317
}
267
318
268
-
foreach ($service['tags']as$tag) {
319
+
foreach ($tagsas$tag) {
269
320
if (!is_array($tag)) {
270
321
$tag = array('name' => $tag);
271
322
}
272
323
273
324
if (!isset($tag['name'])) {
274
325
thrownewInvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
275
326
}
327
+
$name = $tag['name'];
328
+
unset($tag['name']);
276
329
277
-
if (!is_string($tag['name']) || '' === $tag['name']) {
330
+
if (!is_string($name) || '' === $name) {
278
331
thrownewInvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
279
332
}
280
333
281
-
$name = $tag['name'];
282
-
unset($tag['name']);
283
-
284
334
foreach ($tagas$attribute => $value) {
285
335
if (!is_scalar($value) && null !== $value) {
286
336
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));
@@ -301,11 +351,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