@@ -52,6 +52,7 @@ class YamlFileLoader extends FileLoader
5252 'configurator ' => 'configurator ' ,
5353 'calls ' => 'calls ' ,
5454 'tags ' => 'tags ' ,
55+ 'inherit_tags ' => 'inherit_tags ' ,
5556 'decorates ' => 'decorates ' ,
5657 'decoration_inner_name ' => 'decoration_inner_name ' ,
5758 'decoration_priority ' => 'decoration_priority ' ,
@@ -156,7 +157,7 @@ private function parseDefinitions($content, $file)
156157 @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 );
157158 $ defaults = array ();
158159 } else {
159- $ defaultKeys = array ('public ' , 'tags ' , 'autowire ' );
160+ $ defaultKeys = array ('public ' , 'tags ' , 'inherit_tags ' , ' autowire ' );
160161 unset($ content ['services ' ]['_defaults ' ]);
161162
162163 foreach ($ defaults as $ key => $ default ) {
@@ -240,6 +241,11 @@ private function parseDefinition($id, $service, $file, array $defaults)
240241
241242 if (isset ($ service ['parent ' ])) {
242243 $ definition = new ChildDefinition ($ service ['parent ' ]);
244+
245+ $ inheritTag = isset ($ service ['inherit_tags ' ]) ? $ service ['inherit_tags ' ] : (isset ($ defaults ['inherit_tags ' ]) ? $ defaults ['inherit_tags ' ] : null );
246+ if (null !== $ inheritTag ) {
247+ $ definition ->setInheritTags ($ inheritTag );
248+ }
243249 $ defaults = array ();
244250 } else {
245251 $ definition = new Definition ();
@@ -312,7 +318,18 @@ private function parseDefinition($id, $service, $file, array $defaults)
312318 }
313319 }
314320
315- $ tags = isset ($ service ['tags ' ]) ? $ service ['tags ' ] : (isset ($ defaults ['tags ' ]) ? $ defaults ['tags ' ] : null );
321+ $ tags = isset ($ service ['tags ' ]) ? $ service ['tags ' ] : array ();
322+
323+ if (!isset ($ defaults ['tags ' ])) {
324+ // no-op
325+ } elseif (!isset ($ service ['inherit_tags ' ])) {
326+ if (!isset ($ service ['tags ' ])) {
327+ $ tags = $ defaults ['tags ' ];
328+ }
329+ } elseif ($ service ['inherit_tags ' ]) {
330+ $ tags = array_merge ($ tags , $ defaults ['tags ' ]);
331+ }
332+
316333 if (null !== $ tags ) {
317334 if (!is_array ($ tags )) {
318335 throw new InvalidArgumentException (sprintf ('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax. ' , $ id , $ file ));
0 commit comments