Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 15814d1

Browse filesBrowse files
committed
Adding XML support for auto-configure-instanceof
1 parent 6209a77 commit 15814d1
Copy full SHA for 15814d1

File tree

4 files changed

+32
-0
lines changed
Filter options

4 files changed

+32
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ private function getServiceDefaults(\DOMDocument $xml, $file)
180180
if ($defaultsNode->hasAttribute('inherit-tags')) {
181181
$defaults['inherit-tags'] = XmlUtils::phpize($defaultsNode->getAttribute('inherit-tags'));
182182
}
183+
if ($defaultsNode->hasAttribute('auto-configure-instanceof')) {
184+
$defaults['auto-configure-instanceof'] = XmlUtils::phpize($defaultsNode->getAttribute('auto-configure-instanceof'));
185+
}
186+
183187

184188
return $defaults;
185189
}
@@ -243,6 +247,12 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults =
243247
$definition->setAutowired($defaults['autowire']);
244248
}
245249

250+
if ($autoConfigureInstanceOfAttr = $service->getAttribute('auto-configure-instanceof')) {
251+
$definition->setShouldAutoConfigureInstanceofConditionals(XmlUtils::phpize($autoConfigureInstanceOfAttr));
252+
} elseif (isset($defaults['auto-configure-instanceof'])) {
253+
$definition->setShouldAutoConfigureInstanceofConditionals($defaults['auto-configure-instanceof']);
254+
}
255+
246256
if ($files = $this->getChildren($service, 'file')) {
247257
$definition->setFile($files[0]->nodeValue);
248258
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<xsd:attribute name="public" type="boolean" />
105105
<xsd:attribute name="autowire" type="autowire" />
106106
<xsd:attribute name="inherit-tags" type="boolean" />
107+
<xsd:attribute name="auto-configure-instanceof" type="boolean" />
107108
</xsd:complexType>
108109

109110
<xsd:complexType name="service">
@@ -132,6 +133,7 @@
132133
<xsd:attribute name="decoration-priority" type="xsd:integer" />
133134
<xsd:attribute name="autowire" type="autowire" />
134135
<xsd:attribute name="inherit-tags" type="boolean" />
136+
<xsd:attribute name="auto-configure-instanceof" type="boolean" />
135137
</xsd:complexType>
136138

137139
<xsd:complexType name="instanceof">
@@ -171,6 +173,7 @@
171173
<xsd:attribute name="parent" type="xsd:string" />
172174
<xsd:attribute name="autowire" type="autowire" />
173175
<xsd:attribute name="inherit-tags" type="boolean" />
176+
<xsd:attribute name="auto-configure-instanceof" type="boolean" />
174177
</xsd:complexType>
175178

176179
<xsd:complexType name="tag">
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<defaults auto-configure-instanceof="true" />
5+
6+
<service id="use_defaults_settings" />
7+
<service id="override_defaults_settings_to_false" auto-configure-instanceof="false" />
8+
</services>
9+
</container>

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,16 @@ public function testInstanceof()
687687
$this->assertTrue($definition->isLazy());
688688
$this->assertSame(array('foo' => array(array()), 'bar' => array(array())), $definition->getTags());
689689
}
690+
691+
public function testAutoConfigureInstanceof()
692+
{
693+
$container = new ContainerBuilder();
694+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
695+
$loader->load('services_auto_configure_instanceof.xml');
696+
697+
$this->assertTrue($container->getDefinition('use_defaults_settings')->getShouldAutoConfigureInstanceofConditionals());
698+
$this->assertFalse($container->getDefinition('override_defaults_settings_to_false')->getShouldAutoConfigureInstanceofConditionals());
699+
}
690700
}
691701

692702
interface BarInterface

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.