8000 [DependencyInjection] Introduce a flag to enable setter autowiring by dunglas · Pull Request #19631 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Introduce a flag to enable setter autowiring #19631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add missing support for YAML and XML loaders
  • Loading branch information
dunglas committed Aug 16, 2016
commit ca649aaa58834f1fd0d5d67f3a9404d90bdf0213
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ private function parseDefinition(\DOMElement $service, $file)
$definition->setAutowired(XmlUtils::phpize($value));
}

if ($value = $service->getAttribute('autowire-setters')) {
$definition->setAutowiredSetters(XmlUtils::phpize($value));
}

if ($files = $this->getChildren($service, 'file')) {
$definition->setFile($files[0]->nodeValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class YamlFileLoader extends FileLoader
'decoration_inner_name' => 'decoration_inner_name',
'decoration_priority' => 'decoration_priority',
'autowire' => 'autowire',
'autowire_setters' => 'autowire_setters',
'autowiring_types' => 'autowiring_types',
);

Expand Down Expand Up @@ -305,6 +306,10 @@ private function parseDefinition($id, $service, $file)
$definition->setAutowired($service['autowire']);
}

if (isset($service['autowire_setters'])) {
$definition->setAutowiredSetters($service['autowire_setters']);
}

if (isset($service['autowiring_types'])) {
if (is_string($service['autowiring_types'])) {
$definition->addAutowiringType($service['autowiring_types']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<xsd:attribute name="decoration-inner-name" type="xsd:string" />
<xsd:attribute name="decoration-priority" type="xsd:integer" />
<xsd:attribute name="autowire" type="boolean" />
<xsd:attribute name="autowire-setters" type="boolean" />
</xsd:complexType>

<xsd:complexType name="tag">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<services>
<service id="bar" class="Bar" autowire="true" autowire-setters="true" />
</services>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
bar_service:
class: BarClass
autowire: true
autowire_setters: true
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,15 @@ public function testAutowire()
$this->assertTrue($container->getDefinition('bar')->isAutowired());
}

public function testAutowireSetters()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('services25.xml');

$this->assertTrue($container->getDefinition('bar')->hasAutowiredSetters());
}

/**
* @group legacy
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ public function testAutowire()
$this->assertTrue($container->getDefinition('bar_service')->isAutowired());
}

public function testAutowireSetters()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('services25.yml');

$this->assertTrue($container->getDefinition('bar_service')->hasAutowiredSetters());
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage The value of the "decorates" option for the "bar" service must be the id of the service without the "@" prefix (replace "@foo" with "foo").
Expand Down
0