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

Skip to content

Commit 8d78b8a

Browse files
committed
[FrameworkBundle] Display original definition for aliases in debug:container
1 parent c2a0bcf commit 8d78b8a

14 files changed

+265
-23
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function describe(OutputInterface $output, $object, array $options = arra
5454
$this->describeContainerTags($object, $options);
5555
break;
5656
case $object instanceof ContainerBuilder && isset($options['id']):
57-
$this->describeContainerService($this->resolveServiceDefinition($object, $options['id']), $options);
57+
$this->describeContainerService($this->resolveServiceDefinition($object, $options['id']), $options, $object);
5858
break;
5959
case $object instanceof ContainerBuilder && isset($options['parameter']):
6060
$this->describeContainerParameter($object->resolveEnvPlaceholders($object->getParameter($options['parameter'])), $options);
@@ -140,8 +140,9 @@ abstract protected function describeContainerTags(ContainerBuilder $builder, arr
140140
*
141141
* @param Definition|Alias|object $service
142142
* @param array $options
143+
* @param ContainerBuilder|null $builder
143144
*/
144-
abstract protected function describeContainerService($service, array $options = array());
145+
abstract protected function describeContainerService($service, array $options = array(), ContainerBuilder $builder = null);
145146

146147
/**
147148
* Describes container services.
@@ -165,10 +166,11 @@ abstract protected function describeContainerDefinition(Definition $definition,
165166
/**
166167
* Describes a service alias.
167168
*
168-
* @param Alias $alias
169-
* @param array $options
169+
* @param Alias $alias
170+
* @param array $options
171+
* @param ContainerBuilder|null $builder
170172
*/
171-
abstract protected function describeContainerAlias(Alias $alias, array $options = array());
173+
abstract protected function describeContainerAlias(Alias $alias, array $options = array(), ContainerBuilder $builder = null);
172174

173175
/**
174176
* Describes a container parameter.

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio
7777
/**
7878
* {@inheritdoc}
7979
*/
80-
protected function describeContainerService($service, array $options = array())
80+
protected function describeContainerService($service, array $options = array(), ContainerBuilder $builder = null)
8181
{
8282
if (!isset($options['id'])) {
8383
throw new \InvalidArgumentException('An "id" option must be provided.');
8484
}
8585

8686
if ($service instanceof Alias) {
87-
$this->writeData($this->getContainerAliasData($service), $options);
87+
$this->describeContainerAlias($service, $options, $builder);
8888
} elseif ($service instanceof Definition) {
8989
$this->writeData($this->getContainerDefinitionData($service), $options);
9090
} else {
@@ -129,9 +129,16 @@ protected function describeContainerDefinition(Definition $definition, array $op
129129
/**
130130
* {@inheritdoc}
131131
*/
132-
protected function describeContainerAlias(Alias $alias, array $options = array())
132+
protected function describeContainerAlias(Alias $alias, array $options = array(), ContainerBuilder $builder = null)
133133
{
134-
$this->writeData($this->getContainerAliasData($alias), $options);
134+
if (!$builder) {
135+
return $this->writeData($this->getContainerAliasData($alias), $options);
136+
}
137+
138+
$this->writeData(
139+
array($this->getContainerAliasData($alias), $this->getContainerDefinitionData($builder->getDefinition((string) $alias))),
140+
array_merge($options, array('id' => (string) $alias))
141+
);
135142
}
136143

137144
/**

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio
9797
/**
9898
* {@inheritdoc}
9999
*/
100-
protected function describeContainerService($service, array $options = array())
100+
protected function describeContainerService($service, array $options = array(), ContainerBuilder $builder = null)
101101
{
102102
if (!isset($options['id'])) {
103103
throw new \InvalidArgumentException('An "id" option must be provided.');
@@ -106,7 +106,7 @@ protected function describeContainerService($service, array $options = array())
106106
$childOptions = array('id' => $options['id'], 'as_array' => true);
107107

108108
if ($service instanceof Alias) {
109-
$this->describeContainerAlias($service, $childOptions);
109+
$this->describeContainerAlias($service, $childOptions, $builder);
110110
} elseif ($service instanceof Definition) {
111111
$this->describeContainerDefinition($service, $childOptions);
112112
} else {
@@ -236,12 +236,23 @@ protected function describeContainerDefinition(Definition $definition, array $op
236236
/**
237237
* {@inheritdoc}
238238
*/
239-
protected function describeContainerAlias(Alias $alias, array $options = array())
239+
protected function describeContainerAlias(Alias $alias, array $options = array(), ContainerBuilder $builder = null)
240240
{
241241
$output = '- Service: `'.$alias.'`'
242242
."\n".'- Public: '.($alias->isPublic() ? 'yes' : 'no');
243243

244-
$this->write(isset($options['id']) ? sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output) : $output);
244+
if (!isset($options['id'])) {
245+
return $this->write($output);
246+
}
247+
248+
$this->write(sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output));
249+
250+
if (!$builder) {
251+
return;
252+
}
253+
254+
$this->write("\n");
255+
$this->describeContainerDefinition($builder->getDefinition((string) $alias), array_merge($options, array('id' => (string) $alias)));
245256
}
246257

247258
/**

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio
139139
/**
140140
* {@inheritdoc}
141141
*/
142-
protected function describeContainerService($service, array $options = array())
142+
protected function describeContainerService($service, array $options = array(), ContainerBuilder $builder = null)
143143
{
144144
if (!isset($options['id'])) {
145145
throw new \InvalidArgumentException('An "id" option must be provided.');
146146
}
147147

148148
if ($service instanceof Alias) {
149-
$this->describeContainerAlias($service, $options);
149+
$this->describeContainerAlias($service, $options, $builder);
150150
} elseif ($service instanceof Definition) {
151151
$this->describeContainerDefinition($service, $options);
152152
} else {
@@ -333,9 +333,15 @@ protected function describeContainerDefinition(Definition $definition, array $op
333333
/**
334334
* {@inheritdoc}
335335
*/
336-
protected function describeContainerAlias(Alias $alias, array $options = array())
336+
protected function describeContainerAlias(Alias $alias, array $options = array(), ContainerBuilder $builder = null)
337337
{
338338
$options['output']->comment(sprintf('This service is an alias for the service <info>%s</info>', (string) $alias));
339+
340+
if (!$builder) {
341+
return;
342+
}
343+
344+
return $this->describeContainerDefinition($builder->getDefinition((string) $alias), array_merge($options, array('id' => (string) $alias)));
339345
}
340346

341347
/**

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio
6262
/**
6363
* {@inheritdoc}
6464
*/
65-
protected function describeContainerService($service, array $options = array())
65+
protected function describeContainerService($service, array $options = array(), ContainerBuilder $builder = null)
6666
{
6767
if (!isset($options['id'])) {
6868
throw new \InvalidArgumentException('An "id" option must be provided.');
6969
}
7070

71-
$this->writeDocument($this->getContainerServiceDocument($service, $options['id']));
71+
$this->writeDocument($this->getContainerServiceDocument($service, $options['id'], $builder));
7272
}
7373

7474
/**
@@ -90,9 +90,18 @@ protected function describeContainerDefinition(Definition $definition, array $op
9090
/**
9191
* {@inheritdoc}
9292
*/
93-
protected function describeContainerAlias(Alias $alias, array $options = array())
93+
protected function describeContainerAlias(Alias $alias, array $options = array(), ContainerBuilder $builder = null)
9494
{
95-
$this->writeDocument($this->getContainerAliasDocument($alias, isset($options['id']) ? $options['id'] : null));
95+
$dom = new \DOMDocument('1.0', 'UTF-8');
96+
$dom->appendChild($dom->importNode($this->getContainerAliasDocument($alias, isset($options['id']) ? $options['id'] : null)->childNodes->item(0), true));
97+
98+
if (!$builder) {
99+
return $this->writeDocument($dom);
100+
}
101+
102+
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($builder->getDefinition((string) $alias), (string) $alias)->childNodes->item(0), true));
103+
104+
$this->writeDocument($dom);
96105
}
97106

98107
/**
@@ -261,17 +270,21 @@ private function getContainerTagsDocument(ContainerBuilder $builder, $showPrivat
261270
}
262271

263272
/**
264-
* @param mixed $service
265-
* @param string $id
273+
* @param mixed $service
274+
* @param string $id
275+
* @param ContainerBuilder|null $builder
266276
*
267277
* @return \DOMDocument
268278
*/
269-
private function getContainerServiceDocument($service, $id)
279+
private function getContainerServiceDocument($service, $id, ContainerBuilder $builder = null)
270280
{
271281
$dom = new \DOMDocument('1.0', 'UTF-8');
272282

273283
if ($service instanceof Alias) {
274284
$dom->appendChild($dom->importNode($this->getContainerAliasDocument($service, $id)->childNodes->item(0), true));
285+
if ($builder) {
286+
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($builder->getDefinition((string) $service), (string) $service)->childNodes->item(0), true));
287+
}
275288
} elseif ($service instanceof Definition) {
276289
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($service, $id)->childNodes->item(0), true));
277290
} else {

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,35 @@ public function getDescribeContainerAliasTestData()
9090
return $this->getDescriptionTestData(ObjectsProvider::getContainerAliases());
9191
}
9292

93+
/** @dataProvider getDescribeContainerDefinitionWhichIsAnAliasTestData */
94+
public function testDescribeContainerDefinitionWhichIsAnAlias(Alias $alias, $expectedDescription, ContainerBuilder $builder, $options = array())
95+
{
96+
$this->assertDescription($expectedDescription, $builder, $options);
97+
}
98+
99+
public function getDescribeContainerDefinitionWhichIsAnAliasTestData()
100+
{
101+
$builder = current(ObjectsProvider::getContainerBuilders());
102+
$builder->setDefinition('service_1', $builder->getDefinition('definition_1'));
103+
$builder->setDefinition('service_2', $builder->getDefinition('definition_2'));
104+
105+
$aliases = ObjectsProvider::getContainerAliases();
106+
$aliasesWithDefinitions = array();
107+
foreach ($aliases as $name => $alias) {
108+
$aliasesWithDefinitions[str_replace('alias_', 'alias_with_definition_', $name)] = $alias;
109+
}
110+
111+
$i = 0;
112+
$data = $this->getDescriptionTestData($aliasesWithDefinitions);
113+
foreach ($aliases as $name => $alias) {
114+
$data[$i][] = $builder;
115+
$data[$i][] = array('id' => $name);
116+
++$i;
117+
}
118+
119+
return $data;
120+
}
121+
93122
/** @dataProvider getDescribeContainerParameterTestData */
94123
public function testDescribeContainerParameter($parameter, $expectedDescription, array $options)
95124
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"service": "service_1",
4+
"public": true
5+
},
6+
{
7+
"class": "Full\\Qualified\\Class1",
8+
"public": true,
9+
"synthetic": false,
10+
"lazy": true,
11+
"shared": true,
12+
"abstract": true,
13+
"autowire": false,
14+
"autowiring_types": [],
15+
"file": null,
16+
"factory_class": "Full\\Qualified\\FactoryClass",
17+
"factory_method": "get",
18+
"tags": []
19+
}
20+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
alias_1
2+
~~~~~~~
3+
4+
- Service: `service_1`
5+
- Public: yes
6+
7+
service_1
8+
~~~~~~~~~
9+
10+
- Class: `Full\Qualified\Class1`
11+
- Public: yes
12+
- Synthetic: no
13+
- Lazy: yes
14+
- Shared: yes
15+
- Abstract: yes
16+
- Autowired: no
17+
- Factory Class: `Full\Qualified\FactoryClass`
18+
- Factory Method: `get`
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
 // This service is an alias for the service service_1
2+
3+
Information for Service "service_1"
4+
===================================
5+
6+
------------------ -----------------------------
7+
 Option   Value 
8+
------------------ -----------------------------
9+
Service ID service_1
10+
Class Full\Qualified\Class1
11+
Tags -
12+
Public yes
13+
Synthetic no
14+
Lazy yes
15+
Shared yes
16+
Abstract yes
17+
Autowired no
18+
Autowiring Types -
19+
Factory Class Full\Qualified\FactoryClass
20+
Factory Method get
21+
------------------ -----------------------------
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<alias id="alias_1" service="service_1" public="true"/>
3+
<definition id="service_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" file="">
4+
<factory class="Full\Qualified\FactoryClass" method="get"/>
5+
</definition>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[
2+
{
3+
"service": "service_2",
4+
"public": false
5+
},
6+
{
7+
"class": "Full\\Qualified\\Class2",
8+
"public": false,
9+
"synthetic": true,
10+
"lazy": false,
11+
"shared": true,
12+
"abstract": false,
13+
"autowire": false,
14+
"autowiring_types": [],
15+
"file": "\/path\/to\/file",
16+
"factory_service": "factory.service",
17+
"factory_method": "get",
18+
"calls": [
19+
"setMailer"
20+
],
21+
"tags": [
22+
{
23+
"name": "tag1",
24+
"parameters": {
25+
"attr1": "val1",
26+
"attr2": "val2"
27+
}
28+
},
29+
{
30+
"name": "tag1",
31+
"parameters": {
32+
"attr3": "val3"
33+
}
34+
},
35+
{
36+
"name": "tag2",
37+
"parameters": []
38+
}
39+
]
40+
}
41+
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
alias_2
2+
~~~~~~~
3+
4+
- Service: `service_2`
5+
- Public: no
6+
7+
service_2
8+
~~~~~~~~~
9+
10+
- Class: `Full\Qualified\Class2`
11+
- Public: no
12+
- Synthetic: yes
13+
- Lazy: no
14+
- Shared: yes
15+
- Abstract: no
16+
- Autowired: no
17+
- File: `/path/to/file`
18+
- Factory Service: `factory.service`
19+
- Factory Method: `get`
20+
- Call: `setMailer`
21+
- Tag: `tag1`
22+
- Attr1: val1
23+
- Attr2: val2
24+
- Tag: `tag1`
25+
- Attr3: val3
26+
- Tag: `tag2`

0 commit comments

Comments
 (0)