Skip to content

Commit 1c6aa67

Browse files
committed
bug #39692 [FrameworkBundle] Dump abstract arguments (jderusse)
This PR was merged into the 5.1 branch. Discussion ---------- [FrameworkBundle] Dump abstract arguments | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #24138 | License | MIT | Doc PR | - This PR fixes n exception thrown when dumping abstract arguments (ie. `./bin/console debug:containter session.abstract_handler --show-arguments`) Commits ------- df769ec84c Dump abstract arguments
2 parents f52d2c9 + 03710ff commit 1c6aa67

File tree

9 files changed

+50
-25
lines changed

9 files changed

+50
-25
lines changed

Console/Descriptor/JsonDescriptor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Exception\LogicException;
1515
use Symfony\Component\Console\Exception\RuntimeException;
1616
use Symfony\Component\DependencyInjection\Alias;
17+
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1718
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
1819
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1920
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -393,6 +394,10 @@ private function describeValue($value, bool $omitTags, bool $showArguments)
393394
];
394395
}
395396

397+
if ($value instanceof AbstractArgument) {
398+
return ['type' => 'abstract', 'text' => $value->getText()];
399+
}
400+
396401
if ($value instanceof ArgumentInterface) {
397402
return $this->describeValue($value->getValues(), $omitTags, $showArguments);
398403
}

Console/Descriptor/TextDescriptor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Helper\Table;
1717
use Symfony\Component\Console\Style\SymfonyStyle;
1818
use Symfony\Component\DependencyInjection\Alias;
19+
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1920
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
2021
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
2122
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
@@ -347,6 +348,8 @@ protected function describeContainerDefinition(Definition $definition, array $op
347348
$argumentsInformation[] = sprintf('Service locator (%d element(s))', \count($argument->getValues()));
348349
} elseif ($argument instanceof Definition) {
349350
$argumentsInformation[] = 'Inlined Service';
351+
} elseif ($argument instanceof AbstractArgument) {
352+
$argumentsInformation[] = sprintf('Abstract argument (%s)', $argument->getText());
350353
} else {
351354
$argumentsInformation[] = \is_array($argument) ? sprintf('Array (%d element(s))', \count($argument)) : $argument;
352355
}

Console/Descriptor/XmlDescriptor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Exception\LogicException;
1515
use Symfony\Component\Console\Exception\RuntimeException;
1616
use Symfony\Component\DependencyInjection\Alias;
17+
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1718
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1819
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1920
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
@@ -409,6 +410,9 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom): array
409410
}
410411
} elseif ($argument instanceof Definition) {
411412
$argumentXML->appendChild($dom->importNode($this->getContainerDefinitionDocument($argument, null, false, true)->childNodes->item(0), true));
413+
} elseif ($argument instanceof AbstractArgument) {
414+
$argumentXML->setAttribute('type', 'abstract');
415+
$argumentXML->appendChild(new \DOMText($argument->getText()));
412416
} elseif (\is_array($argument)) {
413417
$argumentXML->setAttribute('type', 'collection');
414418

Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
1313

1414
use Symfony\Component\DependencyInjection\Alias;
15+
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1516
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
@@ -144,6 +145,7 @@ public static function getContainerDefinitions()
144145
new Reference('definition_1'),
145146
new Reference('.definition_2'),
146147
]))
148+
->addArgument(new AbstractArgument('placeholder'))
147149
->setFactory(['Full\\Qualified\\FactoryClass', 'get']),
148150
'.definition_2' => $definition2
149151
->setPublic(false)

Tests/Fixtures/Descriptor/builder_1_arguments.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@
6060
"type": "service",
6161
"id": ".definition_2"
6262
}
63-
]
63+
],
64+
{
65+
"type": "abstract",
66+
"text": "placeholder"
67+
}
6468
],
6569
"file": null,
6670
"factory_class": "Full\\Qualified\\FactoryClass",

Tests/Fixtures/Descriptor/builder_1_arguments.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<argument type="service" id="definition_1"/>
2323
<argument type="service" id=".definition_2"/>
2424
</argument>
25+
<argument type="abstract">placeholder</argument>
2526
</definition>
2627
<definition id="definition_without_class" class="" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file=""/>
2728
<definition id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="">

Tests/Fixtures/Descriptor/definition_arguments_1.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@
5858
"type": "service",
5959
"id": ".definition_2"
6060
}
61-
]
61+
],
62+
{
63+
"type": "abstract",
64+
"text": "placeholder"
65+
}
6266
],
6367
"file": null,
6468
"factory_class": "Full\\Qualified\\FactoryClass",
Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
---------------- -----------------------------
2-
 Option   Value 
3-
---------------- -----------------------------
4-
Service ID -
5-
Class Full\Qualified\Class1
6-
Tags -
7-
Public yes
8-
Synthetic no
9-
Lazy yes
10-
Shared yes
11-
Abstract yes
12-
Autowired no
13-
Autoconfigured no
14-
Factory Class Full\Qualified\FactoryClass
15-
Factory Method get
16-
 Arguments Service(.definition_2) 
17-
 %parameter% 
18-
 Inlined Service 
19-
 Array (3 element(s)) 
20-
 Iterator (2 element(s)) 
21-
 - Service(definition_1) 
22-
 - Service(.definition_2)
23-
---------------- -----------------------------
1+
---------------- ---------------------------------
2+
 Option   Value 
3+
---------------- ---------------------------------
4+
Service ID -
5+
Class Full\Qualified\Class1
6+
Tags -
7+
Public yes
8+
Synthetic no
9+
Lazy yes
10+
Shared yes
11+
Abstract yes
12+
Autowired no
13+
Autoconfigured no
14+
Factory Class Full\Qualified\FactoryClass
15+
Factory Method get
16+
 Arguments Service(.definition_2) 
17+
 %parameter% 
18+
 Inlined Service 
19+
 Array (3 element(s)) 
20+
 Iterator (2 element(s)) 
21+
 - Service(definition_1) 
22+
 - Service(.definition_2) 
23+
 Abstract argument (placeholder)
24+
---------------- ---------------------------------
2425

Tests/Fixtures/Descriptor/definition_arguments_1.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@
2020
<argument type="service" id="definition_1"/>
2121
<argument type="service" id=".definition_2"/>
2222
</argument>
23+
<argument type="abstract">placeholder</argument>
2324
</definition>

0 commit comments

Comments
 (0)