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

Skip to content

Commit a3da23a

Browse files
committed
Fix @Tobion's comments
1 parent 754d026 commit a3da23a

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,15 @@ private function getMethodsToAutowire(\ReflectionClass $reflectionClass, $autowi
135135

136136
/**
137137
* @param \ReflectionClass $reflectionClass
138+
* @param string[] $autowired
138139
*
139140
* @return \ReflectionMethod[]
140141
*/
141-
public function getMethods(\ReflectionClass $reflectionClass, array $autowired)
142+
private function getMethods(\ReflectionClass $reflectionClass, array $autowired)
142143
{
143-
if (is_array($autowired)) {
144-
foreach ($autowired as $methodName) {
145-
if ($reflectionClass->hasMethod($methodName)) {
146-
yield $reflectionClass->getMethod($methodName);
147-
}
144+
foreach ($autowired as $methodName) {
145+
if ($reflectionClass->hasMethod($methodName)) {
146+
yield $reflectionClass->getMethod($methodName);
148147
}
149148
}
150149
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ private function parseDefinition(\DOMElement $service, $file)
243243
foreach ($this->getChildren($service, 'autowire') as $type) {
244244
$autowireTags[] = $type->textContent;
245245
}
246+
246247
if (!empty($autowireTags)) {
248+
if ($service->hasAttribute('autowire')) {
249+
throw new InvalidArgumentException(sprintf('The "autowire" attribute cannot be used together with "<autowire>" tags for service "%s" in %s.', (string) $service->getAttribute('id'), $file));
250+
}
251+
247252
$definition->setAutowired($autowireTags);
248253
}
249254

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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_array" class="Foo" autowire="*">
5+
<autowire>setFoo</autowire>
6+
</service>
7+
</services>
8+
</container>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,16 @@ public function testAutowire()
561561
$this->assertEquals(array('setFoo', 'bar'), $container->getDefinition('autowire_array')->getAutowired());
562562
}
563563

564+
/**
565+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
566+
*/
567+
public function testAutowireAttributeAndTag()
568+
{
569+
$container = new ContainerBuilder();
570+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
571+
$loader->load('services26.xml');
572+
}
573+
564574
/**
565575
* @group legacy
566576
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered

0 commit comments

Comments
 (0)