Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f5014a

Browse files
committed
Making tags under _defaults always apply and removing inherit_tags entirely
Now that inherit_tags has been removed, 3.3 has the same functionality as 3.2: tags are *never* cascaded from parent to child (but you tags do inherit from defaults to a service and instanceof to a service).
1 parent 7010a7a commit 3f5014a

16 files changed

+21
-185
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ CHANGELOG
2222
* added "iterator" argument type for lazy iteration over a set of values and services
2323
* added "closure-proxy" argument type for turning services' methods into lazy callables
2424
* added file-wide configurable defaults for service attributes "public", "tags",
25-
"autowire" and "inherit-tags"
26-
* added "inherit-tags" service attribute to control tags' inheritance from parent context
25+
"autowire" and "autoconfigure"
2726
* made the "class" attribute optional, using the "id" as fallback
2827
* using the `PhpDumper` with an uncompiled `ContainerBuilder` is deprecated and
2928
will not be supported anymore in 4.0

src/Symfony/Component/DependencyInjection/ChildDefinition.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
class ChildDefinition extends Definition
2424
{
2525
private $parent;
26-
private $inheritTags = false;
2726

2827
/**
2928
* @param string $parent The id of Definition instance to decorate
@@ -57,30 +56,6 @@ public function setParent($parent)
5756
return $this;
5857
}
5958

60-
/**
61-
* Sets whether tags should be inherited from the parent or not.
62-
*
63-
* @param bool $boolean
64-
*
65-
* @return $this
66-
*/
67-
public function setInheritTags($boolean)
68-
{
69-
$this->inheritTags = (bool) $boolean;
70-
71-
return $this;
72-
}
73-
74-
/**
75-
* Returns whether tags should be inherited from the parent or not.
76-
*
77-
* @return bool
78-
*/
79-
public function getInheritTags()
80-
{
81-
return $this->inheritTags;
82-
}
83-
8459
/**
8560
* Gets an argument to pass to the service constructor/factory method.
8661
*

src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public function __construct()
4343
100 => array(
4444
$resolveClassPass = new ResolveClassPass(),
4545
new ResolveInstanceofConditionalsPass(),
46-
new ResolveTagsInheritancePass(),
4746
),
4847
);
4948

src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private function processDefinition(ContainerBuilder $container, $id, Definition
7777
foreach ($instanceofDefs as $key => $instanceofDef) {
7878
/** @var ChildDefinition $instanceofDef */
7979
$instanceofDef = clone $instanceofDef;
80-
$instanceofDef->setAbstract(true)->setInheritTags(false)->setParent($parent ?: 'abstract.instanceof.'.$id);
80+
$instanceofDef->setAbstract(true)->setParent($parent ?: 'abstract.instanceof.'.$id);
8181
$parent = 'instanceof.'.$interface.'.'.$key.'.'.$id;
8282
$container->setDefinition($parent, $instanceofDef);
8383
$instanceofTags[] = $instanceofDef->getTags();

src/Symfony/Component/DependencyInjection/Compiler/ResolveTagsInheritancePass.php

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@ private function getServiceDefaults(\DOMDocument $xml, $file)
178178
if ($defaultsNode->hasAttribute('public')) {
179179
$defaults['public'] = XmlUtils::phpize($defaultsNode->getAttribute('public'));
180180
}
181-
if ($defaultsNode->hasAttribute('inherit-tags')) {
182-
$defaults['inherit-tags'] = XmlUtils::phpize($defaultsNode->getAttribute('inherit-tags'));
183-
}
184181
if ($defaultsNode->hasAttribute('autoconfigure')) {
185182
$defaults['autoconfigure'] = XmlUtils::phpize($defaultsNode->getAttribute('autoconfigure'));
186183
}
@@ -225,13 +222,6 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults =
225222
}
226223

227224
$definition = new ChildDefinition($parent);
228-
229-
if ($value = $service->getAttribute('inherit-tags')) {
230-
$definition->setInheritTags(XmlUtils::phpize($value));
231-
} elseif (isset($defaults['inherit-tags'])) {
232-
$definition->setInheritTags($defaults['inherit-tags']);
233-
}
234-
$defaults = array();
235225
} else {
236226
$definition = new Definition();
237227

@@ -318,13 +308,7 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults =
318308

319309
$tags = $this->getChildren($service, 'tag');
320310

321-
if (empty($defaults['tags'])) {
322-
// no-op
323-
} elseif (!$value = $service->getAttribute('inherit-tags')) {
324-
if (!$tags) {
325-
$tags = $defaults['tags'];
326-
}
327-
} elseif (XmlUtils::phpize($value)) {
311+
if (!empty($defaults['tags'])) {
328312
$tags = array_merge($tags, $defaults['tags']);
329313
}
330314

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class YamlFileLoader extends FileLoader
5151
'configurator' => 'configurator',
5252
'calls' => 'calls',
5353
'tags' => 'tags',
54-
'inherit_tags' => 'inherit_tags',
5554
'decorates' => 'decorates',
5655
'decoration_inner_name' => 'decoration_inner_name',
5756
'decoration_priority' => 'decoration_priority',
@@ -74,7 +73,6 @@ class YamlFileLoader extends FileLoader
7473
'configurator' => 'configurator',
7574
'calls' => 'calls',
7675
'tags' => 'tags',
77-
'inherit_tags' => 'inherit_tags',
7876
'autowire' => 'autowire',
7977
'autoconfigure' => 'autoconfigure',
8078
);
@@ -93,7 +91,6 @@ class YamlFileLoader extends FileLoader
9391
private static $defaultsKeywords = array(
9492
'public' => 'public',
9593
'tags' => 'tags',
96-
'inherit_tags' => 'inherit_tags',
9794
'autowire' => 'autowire',
9895
'autoconfigure' => 'autoconfigure',
9996
);
@@ -365,15 +362,11 @@ private function parseDefinition($id, $service, $file, array $defaults)
365362
}
366363

367364
$definition = new ChildDefinition($service['parent']);
368-
369-
$inheritTag = isset($service['inherit_tags']) ? $service['inherit_tags'] : (isset($defaults['inherit_tags']) ? $defaults['inherit_tags'] : null);
370-
if (null !== $inheritTag) {
371-
$definition->setInheritTags($inheritTag);
372-
}
373-
$defaults = array();
374365
} else {
375366
$definition = new Definition();
367+
}
376368

369+
if (!$this->isLoadingInstanceof) {
377370
if (isset($defaults['public'])) {
378371
$definition->setPublic($defaults['public']);
379372
}
@@ -384,7 +377,15 @@ private function parseDefinition($id, $service, $file, array $defaults)
384377
$definition->setAutoconfigured($defaults['autoconfigure']);
385378
}
386379

387-
$definition->setChanges(array());
380+
// don't reset changes for children, otherwise their
381+
// parent values will always win, even if they're not
382+
// explicitly set. We should be able to remove this if
383+
// the ResolveDefinitionTemplatesPass is made smarter
384+
// to only override values from the parent *if* they
385+
// are explicitly set.
386+
if (!$definition instanceof ChildDefinition) {
387+
$definition->setChanges(array());
388+
}
388389
}
389390

390391
if (isset($service['class'])) {
@@ -458,13 +459,7 @@ private function parseDefinition($id, $service, $file, array $defaults)
458459
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
459460
}
460461

461-
if (!isset($defaults['tags'])) {
462-
// no-op
463-
} elseif (!isset($service['inherit_tags'])) {
464-
if (!isset($service['tags'])) {
465-
$tags = $defaults['tags'];
466-
}
467-
} elseif ($service['inherit_tags']) {
462+
if (isset($defaults['tags'])) {
468463
$tags = array_merge($tags, $defaults['tags']);
469464
}
470465

src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
</xsd:choice>
104104
<xsd:attribute name="public" type="boolean" />
105105
<xsd:attribute name="autowire" type="boolean" />
106-
<xsd:attribute name="inherit-tags" type="boolean" />
107106
<xsd:attribute name="autoconfigure" type="boolean" />
108107
</xsd:complexType>
109108

@@ -132,7 +131,6 @@
132131
<xsd:attribute name="decoration-inner-name" type="xsd:string" />
133132
<xsd:attribute name="decoration-priority" type="xsd:integer" />
134133
<xsd:attribute name="autowire" type="boolean" />
135-
<xsd:attribute name="inherit-tags" type="boolean" />
136134
<xsd:attribute name="autoconfigure" type="boolean" />
137135
</xsd:complexType>
138136

@@ -169,7 +167,6 @@
169167
<xsd:attribute name="abstract" type="boolean" />
170168
<xsd:attribute name="parent" type="xsd:string" />
171169
<xsd:attribute name="autowire" type="boolean" />
172-
<xsd:attribute name="inherit-tags" type="boolean" />
173170
<xsd:attribute name="autoconfigure" type="boolean" />
174171
</xsd:complexType>
175172

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\DependencyInjection\ChildDefinition;
1616
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
1717
use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
18-
use Symfony\Component\DependencyInjection\Compiler\ResolveTagsInheritancePass;
1918
use Symfony\Component\DependencyInjection\ContainerBuilder;
2019

2120
class ResolveInstanceofConditionalsPassTest extends TestCase
@@ -35,7 +34,6 @@ public function testProcess()
3534
$this->assertEmpty($def->getInstanceofConditionals());
3635
$this->assertInstanceof(ChildDefinition::class, $def);
3736
$this->assertTrue($def->isAutowired());
38-
$this->assertFalse($def->getInheritTags());
3937
$this->assertSame($parent, $def->getParent());
4038
$this->assertSame(array('tag' => array(array()), 'baz' => array(array('attr' => 123))), $def->getTags());
4139

@@ -121,7 +119,6 @@ public function testProcessUsesAutoconfiguredInstanceof()
121119
->setFactory('autoconfigured_factory');
122120

123121
(new ResolveInstanceofConditionalsPass())->process($container);
124-
(new ResolveTagsInheritancePass())->process($container);
125122
(new ResolveDefinitionTemplatesPass())->process($container);
126123

127124
$def = $container->getDefinition('normal_service');

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveTagsInheritancePassTest.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services29.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</defaults>
77

88
<service id="with_defaults" class="Foo" />
9-
<service id="no_defaults" class="Foo" public="true" autowire="false" inherit-tags="false">
9+
<service id="no_defaults" class="Foo" public="true" autowire="false">
1010
</service>
1111
</services>
1212
</container>

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/integration/defaults_instanceof_importance/expected.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ services:
1616
# these 2 are from instanceof
1717
- { name: foo_tag, tag_option: from_instanceof }
1818
- { name: bar_tag }
19-
# the tag from defaults do NOT cascade (but see #22530)
20-
# - { name: from_defaults }
19+
- { name: from_defaults }
2120
# calls from instanceof are kept, but this comes later
2221
calls:
2322
# first call is from instanceof

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ services:
1414
class: Foo
1515
public: true
1616
autowire: ~
17-
inherit_tags: false
1817

1918
no_defaults:
2019
class: Foo

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ services:
44

55
Foo\Bar:
66
tags: invalid
7-
inherit_tags: true

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ public function testDefaults()
655655

656656
$this->assertTrue($container->getDefinition('no_defaults')->isPublic());
657657

658-
$this->assertSame(array(), $container->getDefinition('no_defaults')->getTags());
658+
$this->assertSame(array('foo' => array(array())), $container->getDefinition('no_defaults')->getTags());
659659

660660
$this->assertFalse($container->getDefinition('no_defaults')->isAutowired());
661661
}

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,9 @@ public function testDefaults()
412412
$this->assertTrue($container->getDefinition('with_null')->isPublic());
413413
$this->assertTrue($container->getDefinition('no_defaults')->isPublic());
414414

415-
$this->assertSame(array(), $container->getDefinition('with_null')->getTags());
416-
$this->assertSame(array(), $container->getDefinition('no_defaults')->getTags());
415+
// foo tag is inherited from defaults
416+
$this->assertSame(array('foo' => array(array())), $container->getDefinition('with_null')->getTags());
417+
$this->assertSame(array('foo' => array(array())), $container->getDefinition('no_defaults')->getTags());
417418

418419
$this->assertTrue($container->getDefinition('with_null')->isAutowired());
419420
$this->assertFalse($container->getDefinition('no_defaults')->isAutowired());

0 commit comments

Comments
 (0)