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

Skip to content

Commit 9d4ae07

Browse files
committed
Add support for method autowiring in the XML loader
1 parent 83eb6a5 commit 9d4ae07

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ private function parseDefinition(\DOMElement $service, $file)
239239
$definition->addAutowiringType($type->textContent);
240240
}
241241

242+
$autowireTags = array();
243+
foreach ($this->getChildren($service, 'autowire') as $type) {
244+
$autowireTags[] = $type->textContent;
245+
}
246+
if (!empty($autowireTags)) {
247+
$definition->setAutowired($autowireTags);
248+
}
249+
242250
if ($value = $service->getAttribute('decorates')) {
243251
$renameId = $service->hasAttribute('decoration-inner-name') ? $service->getAttribute('decoration-inner-name') : null;
244252
$priority = $service->hasAttribute('decoration-priority') ? $service->getAttribute('decoration-priority') : 0;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<xsd:element name="tag" type="tag" minOccurs="0" maxOccurs="unbounded" />
101101
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
102102
<xsd:element name="autowiring-type" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
103+
<xsd:element name="autowire" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
103104
</xsd:choice>
104105
<xsd:attribute name="id" type="xsd:string" />
105106
<xsd:attribute name="class" type="xsd:string" />
@@ -113,7 +114,7 @@
113114
<xsd:attribute name="decorates" type="xsd:string" />
114115
<xsd:attribute name="decoration-inner-name" type="xsd:string" />
115116
<xsd:attribute name="decoration-priority" type="xsd:integer" />
116-
<xsd:attribute name="autowire" type="boolean" />
117+
<xsd:attribute name="autowire" type="boolean_or_star" />
117118
</xsd:complexType>
118119

119120
<xsd:complexType name="tag">
@@ -204,4 +205,10 @@
204205
<xsd:pattern value="(%.+%|true|false)" />
205206
</xsd:restriction>
206207
</xsd:simpleType>
208+
209+
<xsd:simpleType name="boolean_or_star">
210+
<xsd:restriction base="xsd:string">
211+
<xsd:pattern value="(%.+%|true|false|\*)" />
212+
</xsd:restriction>
213+
</xsd:simpleType>
207214
</xsd:schema>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
<service id="autowire_star" class="Foo" autowire="*" />
5+
<service id="autowire_array" class="Foo">
6+
<autowire>setFoo</autowire>
7+
<autowire>bar</autowire>
8+
</service>
9+
</services>
10+
</container>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,11 @@ public function testAutowire()
554554
$loader->load('services23.xml');
555555

556556
$this->assertTrue($container->getDefinition('bar')->isAutowired());
557+
$this->assertTrue($container->getDefinition('bar')->getAutowired());
558+
559+
$loader->load('services25.xml');
560+
$this->assertSame('*', $container->getDefinition('autowire_star')->getAutowired());
561+
$this->assertEquals(array('setFoo', 'bar'), $container->getDefinition('autowire_array')->getAutowired());
557562
}
558563

559564
/**

0 commit comments

Comments
 (0)