Skip to content

[DI] Replace wildcard-based methods autowiring by @required annotation #21763

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

Merged
merged 2 commits into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,9 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
'lazy' => $definition->isLazy(),
'shared' => $definition->isShared(),
'abstract' => $definition->isAbstract(),
'autowire' => $definition->isAutowired(),
);

$autowiredCalls = array_values(array_filter($definition->getAutowiredCalls(), function ($method) {
return $method !== '__construct';
}));
$data['autowire'] = $definition->isAutowired() ? ($autowiredCalls ?: true) : false;

foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
$data['autowiring_types'][] = $autowiringType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,9 @@ protected function describeContainerDefinition(Definition $definition, array $op
."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no')
."\n".'- Shared: '.($definition->isShared() ? 'yes' : 'no')
."\n".'- Abstract: '.($definition->isAbstract() ? 'yes' : 'no')
."\n".'- Autowired: '.($definition->isAutowired() ? 'yes' : 'no')
;

$autowiredCalls = array_filter($definition->getAutowiredCalls(), function ($method) {
return $method !== '__construct';
});
$output .= "\n".'- Autowire: ';
$output .= $definition->isAutowired() ? ($autowiredCalls ? implode(', ', array_map(function ($method) {
return "`$method`";
}, $autowiredCalls)) : 'yes') : 'no';

foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
$output .= "\n".'- Autowiring Type: `'.$autowiringType.'`';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
$tableRows[] = array('Lazy', $definition->isLazy() ? 'yes' : 'no');
$tableRows[] = array('Shared', $definition->isShared() ? 'yes' : 'no');
$tableRows[] = array('Abstract', $definition->isAbstract() ? 'yes' : 'no');

$autowiredCalls = array_filter($definition->getAutowiredCalls(), function ($method) {
return $method !== '__construct';
});
$tableRows[] = array('Autowire', $definition->isAutowired() ? ($autowiredCalls ? implode("\n", $autowiredCalls) : 'yes') : 'no');
$tableRows[] = array('Autowired', $definition->isAutowired() ? 'yes' : 'no');

if ($autowiringTypes = $definition->getAutowiringTypes(false)) {
$tableRows[] = array('Autowiring Types', implode(', ', $autowiringTypes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,6 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
$serviceXML->setAttribute('autowired', $definition->isAutowired() ? 'true' : 'false');
$serviceXML->setAttribute('file', $definition->getFile());

$autowiredCalls = array_filter($definition->getAutowiredCalls(), function ($method) {
return $method !== '__construct';
});
if ($autowiredCalls) {
$serviceXML->appendChild($autowiredMethodsXML = $dom->createElement('autowired-calls'));
foreach ($autowiredCalls as $autowiredMethod) {
$autowiredMethodXML = $dom->createElement('autowired-call');
$autowiredMethodXML->appendChild(new \DOMText($autowiredMethod));
$autowiredMethodsXML->appendChild($autowiredMethodXML);
}
}

$calls = $definition->getMethodCalls();
if (count($calls) > 0) {
$serviceXML->appendChild($callsXML = $dom->createElement('calls'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ public static function getContainerDefinitions()
->addTag('tag2')
->addMethodCall('setMailer', array(new Reference('mailer')))
->setFactory(array(new Reference('factory.service'), 'get')),
'definition_autowired' => (new Definition('AutowiredService'))->setAutowired(true),
'definition_autowired_with_methods' => (new Definition('AutowiredService'))
->setAutowiredCalls(array('__construct', 'set*', 'addFoo')),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
- Lazy: yes
- Shared: yes
- Abstract: yes
- Autowire: no
- Autowired: no
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Lazy yes
Shared yes
Abstract yes
Autowire no
Autowired no
Factory Class Full\Qualified\FactoryClass
Factory Method get
---------------- -----------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: no
- Autowired: no
- File: `/path/to/file`
- Factory Service: `factory.service`
- Factory Method: `get`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Lazy no
Shared yes
Abstract no
Autowire no
Autowired no
Required File /path/to/file
Factory Service factory.service
Factory Method get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,6 @@
"factory_class": "Full\\Qualified\\FactoryClass",
"factory_method": "get",
"tags": []
},
"definition_autowired": {
"class": "AutowiredService",
"public": true,
"synthetic": false,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": true,
"arguments": [],
"file": null,
"tags": []
},
"definition_autowired_with_methods": {
"class": "AutowiredService",
"public": true,
"synthetic": false,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": [
"set*",
"addFoo"
],
"arguments": [],
"file": null,
"tags": []
}
},
"aliases": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,11 @@ Definitions
- Lazy: yes
- Shared: yes
- Abstract: yes
- Autowire: no
- Autowired: no
- Arguments: yes
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`

### definition_autowired

- Class: `AutowiredService`
- Public: yes
- Synthetic: no
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: yes
- Arguments: no

### definition_autowired_with_methods

- Class: `AutowiredService`
- Public: yes
- Synthetic: no
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: `set*`, `addFoo`
- Arguments: no


Aliases
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
Symfony Container Public Services
=================================

----------------------------------- --------------------------------------------------------
 Service ID   Class name 
----------------------------------- --------------------------------------------------------
alias_1 alias for "service_1"
alias_2 alias for "service_2"
definition_1 Full\Qualified\Class1
definition_autowired AutowiredService
definition_autowired_with_methods AutowiredService
service_container Symfony\Component\DependencyInjection\ContainerBuilder
----------------------------------- --------------------------------------------------------
------------------- --------------------------------------------------------
 Service ID   Class name 
------------------- --------------------------------------------------------
alias_1 alias for "service_1"
alias_2 alias for "service_2"
definition_1 Full\Qualified\Class1
service_container Symfony\Component\DependencyInjection\ContainerBuilder
------------------- --------------------------------------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,5 @@
<argument key="def2" type="service" id="definition_2"/>
</argument>
</definition>
<definition id="definition_autowired" class="AutowiredService" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="true" file=""/>
<definition id="definition_autowired_with_methods" class="AutowiredService" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="true" file="">
<autowired-calls>
<autowired-call>set*</autowired-call>
<autowired-call>addFoo</autowired-call>
</autowired-calls>
</definition>
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,6 @@
"factory_class": "Full\\Qualified\\FactoryClass",
"factory_method": "get",
"tags": []
},
"definition_autowired": {
"class": "AutowiredService",
"public": true,
"synthetic": false,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": true,
"file": null,
"tags": []
},
"definition_autowired_with_methods": {
"class": "AutowiredService",
"public": true,
"synthetic": false,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": [
"set*",
"addFoo"
],
"file": null,
"tags": []
}
},
"aliases": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,10 @@ Definitions
- Lazy: yes
- Shared: yes
- Abstract: yes
- Autowire: no
- Autowired: no
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`

### definition_autowired

- Class: `AutowiredService`
- Public: yes
- Synthetic: no
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: yes

### definition_autowired_with_methods

- Class: `AutowiredService`
- Public: yes
- Synthetic: no
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: `set*`, `addFoo`


Aliases
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
Symfony Container Public Services
=================================

----------------------------------- --------------------------------------------------------
 Service ID   Class name 
----------------------------------- --------------------------------------------------------
alias_1 alias for "service_1"
alias_2 alias for "service_2"
definition_1 Full\Qualified\Class1
definition_autowired AutowiredService
definition_autowired_with_methods AutowiredService
service_container Symfony\Component\DependencyInjection\ContainerBuilder
----------------------------------- --------------------------------------------------------
------------------- --------------------------------------------------------
 Service ID   Class name 
------------------- --------------------------------------------------------
alias_1 alias for "service_1"
alias_2 alias for "service_2"
definition_1 Full\Qualified\Class1
service_container Symfony\Component\DependencyInjection\ContainerBuilder
------------------- --------------------------------------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,5 @@
<definition id="definition_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" file="">
<factory class="Full\Qualified\FactoryClass" method="get"/>
</definition>
<definition id="definition_autowired" class="AutowiredService" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="true" file=""/>
<definition id="definition_autowired_with_methods" class="AutowiredService" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="true" file="">
<autowired-calls>
<autowired-call>set*</autowired-call>
<autowired-call>addFoo</autowired-call>
</autowired-calls>
</definition>
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,6 @@
"parameters": []
}
]
},
"definition_autowired": {
"class": "AutowiredService",
"public": true,
"synthetic": false,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": true,
"file": null,
"tags": []
},
"definition_autowired_with_methods": {
"class": "AutowiredService",
"public": true,
"synthetic": false,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": [
"set*",
"addFoo"
],
"file": null,
"tags": []
}
},
"aliases": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Definitions
- Lazy: yes
- Shared: yes
- Abstract: yes
- Autowire: no
- Autowired: no
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`

Expand All @@ -24,7 +24,7 @@ Definitions
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: no
- Autowired: no
- File: `/path/to/file`
- Factory Service: `factory.service`
- Factory Method: `get`
Expand All @@ -36,26 +36,6 @@ Definitions
- Attr3: val3
- Tag: `tag2`

### definition_autowired

- Class: `AutowiredService`
- Public: yes
- Synthetic: no
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: yes

### definition_autowired_with_methods

- Class: `AutowiredService`
- Public: yes
- Synthetic: no
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: `set*`, `addFoo`


Aliases
-------
Expand All @@ -74,4 +54,4 @@ Aliases
Services
--------

- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder`
- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder`
Loading