minor #21315 [DI][FrameworkBundle] Show autowired methods in descriptors (ogizanagi)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI][FrameworkBundle] Show autowired methods in descriptors

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

so we can see the autowired methods using `debug:container`.

Commits
-------

482435c501 [DI][FrameworkBundle] Show autowired methods in descriptors
This commit is contained in:
Fabien Potencier 2017-02-16 05:25:28 -08:00
commit a27accf8e5
47 changed files with 406 additions and 52 deletions

View File

@ -220,9 +220,13 @@ class JsonDescriptor extends Descriptor
'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;
}

View File

@ -182,9 +182,16 @@ class MarkdownDescriptor extends Descriptor
."\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.'`';
}

View File

@ -295,7 +295,11 @@ class TextDescriptor extends Descriptor
$tableRows[] = array('Lazy', $definition->isLazy() ? 'yes' : 'no');
$tableRows[] = array('Shared', $definition->isShared() ? 'yes' : 'no');
$tableRows[] = array('Abstract', $definition->isAbstract() ? 'yes' : 'no');
$tableRows[] = array('Autowired', $definition->isAutowired() ? 'yes' : 'no');
$autowiredCalls = array_filter($definition->getAutowiredCalls(), function ($method) {
return $method !== '__construct';
});
$tableRows[] = array('Autowire', $definition->isAutowired() ? ($autowiredCalls ? implode("\n", $autowiredCalls) : 'yes') : 'no');
if ($autowiringTypes = $definition->getAutowiringTypes(false)) {
$tableRows[] = array('Autowiring Types', implode(', ', $autowiringTypes));

View File

@ -374,6 +374,18 @@ class XmlDescriptor extends Descriptor
$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'));

View File

@ -137,6 +137,9 @@ class ObjectsProvider
->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')),
);
}

View File

@ -11,6 +11,6 @@
- Lazy: yes
- Shared: yes
- Abstract: yes
- Autowired: no
- Autowire: no
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`

View File

@ -14,7 +14,7 @@
Lazy yes
Shared yes
Abstract yes
Autowired no
Autowire no
Factory Class Full\Qualified\FactoryClass
Factory Method get
---------------- -----------------------------

View File

@ -11,7 +11,7 @@
- Lazy: no
- Shared: yes
- Abstract: no
- Autowired: no
- Autowire: no
- File: `/path/to/file`
- Factory Service: `factory.service`
- Factory Method: `get`

View File

@ -17,7 +17,7 @@
Lazy no
Shared yes
Abstract no
Autowired no
Autowire no
Required File /path/to/file
Factory Service factory.service
Factory Method get

View File

@ -80,6 +80,33 @@
"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": {

View File

@ -12,11 +12,33 @@ Definitions
- Lazy: yes
- Shared: yes
- Abstract: yes
- Autowired: no
- Autowire: 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
-------

View File

@ -2,12 +2,14 @@
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
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
definition_autowired AutowiredService
definition_autowired_with_methods AutowiredService
service_container Symfony\Component\DependencyInjection\ContainerBuilder
----------------------------------- --------------------------------------------------------

View File

@ -29,5 +29,12 @@
<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>

View File

@ -12,6 +12,31 @@
"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": {

View File

@ -12,10 +12,30 @@ Definitions
- Lazy: yes
- Shared: yes
- Abstract: yes
- Autowired: no
- Autowire: 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
-------

View File

@ -2,12 +2,14 @@
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
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
definition_autowired AutowiredService
definition_autowired_with_methods AutowiredService
service_container Symfony\Component\DependencyInjection\ContainerBuilder
----------------------------------- --------------------------------------------------------

View File

@ -5,5 +5,12 @@
<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>

View File

@ -46,6 +46,31 @@
"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": {

View File

@ -12,7 +12,7 @@ Definitions
- Lazy: yes
- Shared: yes
- Abstract: yes
- Autowired: no
- Autowire: no
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`
@ -24,7 +24,7 @@ Definitions
- Lazy: no
- Shared: yes
- Abstract: no
- Autowired: no
- Autowire: no
- File: `/path/to/file`
- Factory Service: `factory.service`
- Factory Method: `get`
@ -36,6 +36,26 @@ 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
-------
@ -54,4 +74,4 @@ Aliases
Services
--------
- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder`
- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder`

View File

@ -2,13 +2,15 @@
Symfony Container Public and Private Services
=============================================
------------------- --------------------------------------------------------
 Service ID   Class name 
------------------- --------------------------------------------------------
alias_1 alias for "service_1"
alias_2 alias for "service_2"
definition_1 Full\Qualified\Class1
definition_2 Full\Qualified\Class2
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
definition_2 Full\Qualified\Class2
definition_autowired AutowiredService
definition_autowired_with_methods AutowiredService
service_container Symfony\Component\DependencyInjection\ContainerBuilder
----------------------------------- --------------------------------------------------------

View File

@ -21,5 +21,12 @@
<tag name="tag2"/>
</tags>
</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>

View File

@ -12,7 +12,7 @@ Definitions
- Lazy: no
- Shared: yes
- Abstract: no
- Autowired: no
- Autowire: no
- File: `/path/to/file`
- Factory Service: `factory.service`
- Factory Method: `get`

View File

@ -12,7 +12,7 @@ tag1
- Lazy: no
- Shared: yes
- Abstract: no
- Autowired: no
- Autowire: no
- File: `/path/to/file`
- Factory Service: `factory.service`
- Factory Method: `get`
@ -30,7 +30,7 @@ tag2
- Lazy: no
- Shared: yes
- Abstract: no
- Autowired: no
- Autowire: no
- File: `/path/to/file`
- Factory Service: `factory.service`
- Factory Method: `get`

View File

@ -4,6 +4,6 @@
- Lazy: yes
- Shared: yes
- Abstract: yes
- Autowired: no
- Autowire: no
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`
- Factory Method: `get`

View File

@ -9,7 +9,7 @@
Lazy yes
Shared yes
Abstract yes
Autowired no
Autowire no
Factory Class Full\Qualified\FactoryClass
Factory Method get
---------------- -----------------------------

View File

@ -4,7 +4,7 @@
- Lazy: no
- Shared: yes
- Abstract: no
- Autowired: no
- Autowire: no
- File: `/path/to/file`
- Factory Service: `factory.service`
- Factory Method: `get`
@ -14,4 +14,4 @@
- Attr2: val2
- Tag: `tag1`
- Attr3: val3
- Tag: `tag2`
- Tag: `tag2`

View File

@ -12,7 +12,7 @@
Lazy no
Shared yes
Abstract no
Autowired no
Autowire no
Required File /path/to/file
Factory Service factory.service
Factory Method get

View File

@ -4,7 +4,7 @@
- Lazy: yes
- Shared: yes
- Abstract: yes
- Autowired: no
- Autowire: no
- Arguments: yes
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`
- Factory Method: `get`

View File

@ -9,7 +9,7 @@
Lazy yes
Shared yes
Abstract yes
Autowired no
Autowire no
Factory Class Full\Qualified\FactoryClass
Factory Method get
Arguments Service(definition2)

View File

@ -4,7 +4,7 @@
- Lazy: no
- Shared: yes
- Abstract: no
- Autowired: no
- Autowire: no
- Arguments: no
- File: `/path/to/file`
- Factory Service: `factory.service`
@ -15,4 +15,4 @@
- Attr2: val2
- Tag: `tag1`
- Attr3: val3
- Tag: `tag2`
- Tag: `tag2`

View File

@ -12,7 +12,7 @@
Lazy no
Shared yes
Abstract no
Autowired no
Autowire no
Required File /path/to/file
Factory Service factory.service
Factory Method get

View File

@ -0,0 +1,12 @@
{
"class": "AutowiredService",
"public": true,
"synthetic": false,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": true,
"arguments": [],
"file": null,
"tags": []
}

View File

@ -0,0 +1,8 @@
- Class: `AutowiredService`
- Public: yes
- Synthetic: no
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: yes
- Arguments: no

View File

@ -0,0 +1,14 @@
------------ ------------------
 Option   Value 
------------ ------------------
Service ID -
Class AutowiredService
Tags -
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowire yes
------------ ------------------

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<definition class="AutowiredService" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="true" file=""/>

View File

@ -0,0 +1,15 @@
{
"class": "AutowiredService",
"public": true,
"synthetic": false,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": [
"set*",
"addFoo"
],
"arguments": [],
"file": null,
"tags": []
}

View File

@ -0,0 +1,8 @@
- Class: `AutowiredService`
- Public: yes
- Synthetic: no
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: `set*`, `addFoo`
- Arguments: no

View File

@ -0,0 +1,15 @@
------------ ------------------
 Option   Value 
------------ ------------------
Service ID -
Class AutowiredService
Tags -
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowire set*
addFoo
------------ ------------------

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<definition 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>

View File

@ -0,0 +1,11 @@
{
"class": "AutowiredService",
"public": true,
"synthetic": false,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": true,
"file": null,
"tags": []
}

View File

@ -0,0 +1,7 @@
- Class: `AutowiredService`
- Public: yes
- Synthetic: no
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: yes

View File

@ -0,0 +1,14 @@
------------ ------------------
 Option   Value 
------------ ------------------
Service ID -
Class AutowiredService
Tags -
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowire yes
------------ ------------------

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<definition class="AutowiredService" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="true" file=""/>

View File

@ -0,0 +1,14 @@
{
"class": "AutowiredService",
"public": true,
"synthetic": false,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": [
"set*",
"addFoo"
],
"file": null,
"tags": []
}

View File

@ -0,0 +1,7 @@
- Class: `AutowiredService`
- Public: yes
- Synthetic: no
- Lazy: no
- Shared: yes
- Abstract: no
- Autowire: `set*`, `addFoo`

View File

@ -0,0 +1,15 @@
------------ ------------------
 Option   Value 
------------ ------------------
Service ID -
Class AutowiredService
Tags -
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowire set*
addFoo
------------ ------------------

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<definition 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>