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

Skip to content

Commit a27accf

Browse files
committed
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 ------- 482435c [DI][FrameworkBundle] Show autowired methods in descriptors
2 parents b056d40 + 482435c commit a27accf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+406
-52
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,13 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
220220
'lazy' => $definition->isLazy(),
221221
'shared' => $definition->isShared(),
222222
'abstract' => $definition->isAbstract(),
223-
'autowire' => $definition->isAutowired(),
224223
);
225224

225+
$autowiredCalls = array_values(array_filter($definition->getAutowiredCalls(), function ($method) {
226+
return $method !== '__construct';
227+
}));
228+
$data['autowire'] = $definition->isAutowired() ? ($autowiredCalls ?: true) : false;
229+
226230
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
227231
$data['autowiring_types'][] = $autowiringType;
228232
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,16 @@ protected function describeContainerDefinition(Definition $definition, array $op
182182
."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no')
183183
."\n".'- Shared: '.($definition->isShared() ? 'yes' : 'no')
184184
."\n".'- Abstract: '.($definition->isAbstract() ? 'yes' : 'no')
185-
."\n".'- Autowired: '.($definition->isAutowired() ? 'yes' : 'no')
186185
;
187186

187+
$autowiredCalls = array_filter($definition->getAutowiredCalls(), function ($method) {
188+
return $method !== '__construct';
189+
});
190+
$output .= "\n".'- Autowire: ';
191+
$output .= $definition->isAutowired() ? ($autowiredCalls ? implode(', ', array_map(function ($method) {
192+
return "`$method`";
193+
}, $autowiredCalls)) : 'yes') : 'no';
194+
188195
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
189196
$output .= "\n".'- Autowiring Type: `'.$autowiringType.'`';
190197
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ protected function describeContainerDefinition(Definition $definition, array $op
295295
$tableRows[] = array('Lazy', $definition->isLazy() ? 'yes' : 'no');
296296
$tableRows[] = array('Shared', $definition->isShared() ? 'yes' : 'no');
297297
$tableRows[] = array('Abstract', $definition->isAbstract() ? 'yes' : 'no');
298-
$tableRows[] = array('Autowired', $definition->isAutowired() ? 'yes' : 'no');
298+
299+
$autowiredCalls = array_filter($definition->getAutowiredCalls(), function ($method) {
300+
return $method !== '__construct';
301+
});
302+
$tableRows[] = array('Autowire', $definition->isAutowired() ? ($autowiredCalls ? implode("\n", $autowiredCalls) : 'yes') : 'no');
299303

300304
if ($autowiringTypes = $definition->getAutowiringTypes(false)) {
301305
$tableRows[] = array('Autowiring Types', implode(', ', $autowiringTypes));

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
374374
$serviceXML->setAttribute('autowired', $definition->isAutowired() ? 'true' : 'false');
375375
$serviceXML->setAttribute('file', $definition->getFile());
376376

377+
$autowiredCalls = array_filter($definition->getAutowiredCalls(), function ($method) {
378+
return $method !== '__construct';
379+
});
380+
if ($autowiredCalls) {
381+
$serviceXML->appendChild($autowiredMethodsXML = $dom->createElement('autowired-calls'));
382+
foreach ($autowiredCalls as $autowiredMethod) {
383+
$autowiredMethodXML = $dom->createElement('autowired-call');
384+
$autowiredMethodXML->appendChild(new \DOMText($autowiredMethod));
385+
$autowiredMethodsXML->appendChild($autowiredMethodXML);
386+
}
387+
}
388+
377389
$calls = $definition->getMethodCalls();
378390
if (count($calls) > 0) {
379391
$serviceXML->appendChild($callsXML = $dom->createElement('calls'));

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ public static function getContainerDefinitions()
137137
->addTag('tag2')
138138
->addMethodCall('setMailer', array(new Reference('mailer')))
139139
->setFactory(array(new Reference('factory.service'), 'get')),
140+
'definition_autowired' => (new Definition('AutowiredService'))->setAutowired(true),
141+
'definition_autowired_with_methods' => (new Definition('AutowiredService'))
142+
->setAutowiredCalls(array('__construct', 'set*', 'addFoo')),
140143
);
141144
}
142145

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
- Lazy: yes
1212
- Shared: yes
1313
- Abstract: yes
14-
- Autowired: no
14+
- Autowire: no
1515
- Factory Class: `Full\Qualified\FactoryClass`
1616
- Factory Method: `get`

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Lazy yes
1515
Shared yes
1616
Abstract yes
17-
Autowired no
17+
Autowire no
1818
Factory Class Full\Qualified\FactoryClass
1919
Factory Method get
2020
---------------- -----------------------------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- Lazy: no
1212
- Shared: yes
1313
- Abstract: no
14-
- Autowired: no
14+
- Autowire: no
1515
- File: `/path/to/file`
1616
- Factory Service: `factory.service`
1717
- Factory Method: `get`

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Lazy no
1818
Shared yes
1919
Abstract no
20-
Autowired no
20+
Autowire no
2121
Required File /path/to/file
2222
Factory Service factory.service
2323
Factory Method get

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,33 @@
8080
"factory_class": "Full\\Qualified\\FactoryClass",
8181
"factory_method": "get",
8282
"tags": []
83+
},
84+
"definition_autowired": {
85+
"class": "AutowiredService",
86+
"public": true,
87+
"synthetic": false,
88+
"lazy": false,
89+
"shared": true,
90+
"abstract": false,
91+
"autowire": true,
92+
"arguments": [],
93+
"file": null,
94+
"tags": []
95+
},
96+
"definition_autowired_with_methods": {
97+
"class": "AutowiredService",
98+
"public": true,
99+
"synthetic": false,
100+
"lazy": false,
101+
"shared": true,
102+
"abstract": false,
103+
"autowire": [
104+
"set*",
105+
"addFoo"
106+
],
107+
"arguments": [],
108+
"file": null,
109+
"tags": []
83110
}
84111
},
85112
"aliases": {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,33 @@ Definitions
1212
- Lazy: yes
1313
- Shared: yes
1414
- Abstract: yes
15-
- Autowired: no
15+
- Autowire: no
1616
- Arguments: yes
1717
- Factory Class: `Full\Qualified\FactoryClass`
1818
- Factory Method: `get`
1919

20+
### definition_autowired
21+
22+
- Class: `AutowiredService`
23+
- Public: yes
24+
- Synthetic: no
25+
- Lazy: no
26+
- Shared: yes
27+
- Abstract: no
28+
- Autowire: yes
29+
- Arguments: no
30+
31+
### definition_autowired_with_methods
32+
33+
- Class: `AutowiredService`
34+
- Public: yes
35+
- Synthetic: no
36+
- Lazy: no
37+
- Shared: yes
38+
- Abstract: no
39+
- Autowire: `set*`, `addFoo`
40+
- Arguments: no
41+
2042

2143
Aliases
2244
-------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
Symfony Container Public Services
33
=================================
44

5-
------------------- --------------------------------------------------------
6-
 Service ID   Class name 
7-
------------------- --------------------------------------------------------
8-
alias_1 alias for "service_1"
9-
alias_2 alias for "service_2"
10-
definition_1 Full\Qualified\Class1
11-
service_container Symfony\Component\DependencyInjection\ContainerBuilder
12-
------------------- --------------------------------------------------------
5+
----------------------------------- --------------------------------------------------------
6+
 Service ID   Class name 
7+
----------------------------------- --------------------------------------------------------
8+
alias_1 alias for "service_1"
9+
alias_2 alias for "service_2"
10+
definition_1 Full\Qualified\Class1
11+
definition_autowired AutowiredService
12+
definition_autowired_with_methods AutowiredService
13+
service_container Symfony\Component\DependencyInjection\ContainerBuilder
14+
----------------------------------- --------------------------------------------------------
1315

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,12 @@
2929
<argument key="def2" type="service" id="definition_2"/>
3030
</argument>
3131
</definition>
32+
<definition id="definition_autowired" class="AutowiredService" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="true" file=""/>
33+
<definition id="definition_autowired_with_methods" class="AutowiredService" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="true" file="">
34+
<autowired-calls>
35+
<autowired-call>set*</autowired-call>
36+
<autowired-call>addFoo</autowired-call>
37+
</autowired-calls>
38+
</definition>
3239
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
3340
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,31 @@
1212
"factory_class": "Full\\Qualified\\FactoryClass",
1313
"factory_method": "get",
1414
"tags": []
15+
},
16+
"definition_autowired": {
17+
"class": "AutowiredService",
18+
"public": true,
19+
"synthetic": false,
20+
"lazy": false,
21+
"shared": true,
22+
"abstract": false,
23+
"autowire": true,
24+
"file": null,
25+
"tags": []
26+
},
27+
"definition_autowired_with_methods": {
28+
"class": "AutowiredService",
29+
"public": true,
30+
"synthetic": false,
31+
"lazy": false,
32+
"shared": true,
33+
"abstract": false,
34+
"autowire": [
35+
"set*",
36+
"addFoo"
37+
],
38+
"file": null,
39+
"tags": []
1540
}
1641
},
1742
"aliases": {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,30 @@ Definitions
1212
- Lazy: yes
1313
- Shared: yes
1414
- Abstract: yes
15-
- Autowired: no
15+
- Autowire: no
1616
- Factory Class: `Full\Qualified\FactoryClass`
1717
- Factory Method: `get`
1818

19+
### definition_autowired
20+
21+
- Class: `AutowiredService`
22+
- Public: yes
23+
- Synthetic: no
24+
- Lazy: no
25+
- Shared: yes
26+
- Abstract: no
27+
- Autowire: yes
28+
29+
### definition_autowired_with_methods
30+
31+
- Class: `AutowiredService`
32+
- Public: yes
33+
- Synthetic: no
34+
- Lazy: no
35+
- Shared: yes
36+
- Abstract: no
37+
- Autowire: `set*`, `addFoo`
38+
1939

2040
Aliases
2141
-------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
Symfony Container Public Services
33
=================================
44

5-
------------------- --------------------------------------------------------
6-
 Service ID   Class name 
7-
------------------- --------------------------------------------------------
8-
alias_1 alias for "service_1"
9-
alias_2 alias for "service_2"
10-
definition_1 Full\Qualified\Class1
11-
service_container Symfony\Component\DependencyInjection\ContainerBuilder
12-
------------------- --------------------------------------------------------
5+
----------------------------------- --------------------------------------------------------
6+
 Service ID   Class name 
7+
----------------------------------- --------------------------------------------------------
8+
alias_1 alias for "service_1"
9+
alias_2 alias for "service_2"
10+
definition_1 Full\Qualified\Class1
11+
definition_autowired AutowiredService
12+
definition_autowired_with_methods AutowiredService
13+
service_container Symfony\Component\DependencyInjection\ContainerBuilder
14+
----------------------------------- --------------------------------------------------------
1315

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,12 @@
55
<definition id="definition_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" file="">
66
<factory class="Full\Qualified\FactoryClass" method="get"/>
77
</definition>
8+
<definition id="definition_autowired" class="AutowiredService" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="true" file=""/>
9+
<definition id="definition_autowired_with_methods" class="AutowiredService" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="true" file="">
10+
<autowired-calls>
11+
<autowired-call>set*</autowired-call>
12+
<autowired-call>addFoo</autowired-call>
13+
</autowired-calls>
14+
</definition>
815
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
916
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@
4646
"parameters": []
4747
}
4848
]
49+
},
50+
"definition_autowired": {
51+
"class": "AutowiredService",
52+
"public": true,
53+
"synthetic": false,
54+
"lazy": false,
55+
"shared": true,
56+
"abstract": false,
57+
"autowire": true,
58+
"file": null,
59+
"tags": []
60+
},
61+
"definition_autowired_with_methods": {
62+
"class": "AutowiredService",
63+
"public": true,
64+
"synthetic": false,
65+
"lazy": false,
66+
"shared": true,
67+
"abstract": false,
68+
"autowire": [
69+
"set*",
70+
"addFoo"
71+
],
72+
"file": null,
73+
"tags": []
4974
}
5075
},
5176
"aliases": {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Definitions
1212
- Lazy: yes
1313
- Shared: yes
1414
- Abstract: yes
15-
- Autowired: no
15+
- Autowire: no
1616
- Factory Class: `Full\Qualified\FactoryClass`
1717
- Factory Method: `get`
1818

@@ -24,7 +24,7 @@ Definitions
2424
- Lazy: no
2525
- Shared: yes
2626
- Abstract: no
27-
- Autowired: no
27+
- Autowire: no
2828
- File: `/path/to/file`
2929
- Factory Service: `factory.service`
3030
- Factory Method: `get`
@@ -36,6 +36,26 @@ Definitions
3636
- Attr3: val3
3737
- Tag: `tag2`
3838

39+
### definition_autowired
40+
41+
- Class: `AutowiredService`
42+
- Public: yes
43+
- Synthetic: no
44+
- Lazy: no
45+
- Shared: yes
46+
- Abstract: no
47+
- Autowire: yes
48+
49+
### definition_autowired_with_methods
50+
51+
- Class: `AutowiredService`
52+
- Public: yes
53+
- Synthetic: no
54+
- Lazy: no
55+
- Shared: yes
56+
- Abstract: no
57+
- Autowire: `set*`, `addFoo`
58+
3959

4060
Aliases
4161
-------
@@ -54,4 +74,4 @@ Aliases
5474
Services
5575
--------
5676

57-
- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder`
77+
- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder`

0 commit comments

Comments
 (0)