Permalink
Browse files

minor #21499 [FrameworkBundle][Console] Fix descriptors to support It…

…eratorArgument, ClosureProxy and arrays (ogizanagi)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[FrameworkBundle][Console] Fix descriptors to support IteratorArgument, ClosureProxy and arrays

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

Fixes both array and iterator/closure-proxy arguments support in descriptors when using `--show-arguments`

Commits
-------

a94924c [FrameworkBundle][Console] Fix descriptors to support IteratorArgument, ClosureProxy and arrays
  • Loading branch information...
2 parents 2e13d4e + a94924c commit a46e691ae17f72e15e32930f3968fe2cb76cdc38 @fabpot fabpot committed Feb 2, 2017
@@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
use Symfony\Component\DependencyInjection\Alias;
+use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -227,20 +228,7 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
}
if ($showArguments) {
- $data['arguments'] = array();
-
- foreach ($definition->getArguments() as $argument) {
- if ($argument instanceof Reference) {
- $data['arguments'][] = array(
- 'type' => 'service',
- 'id' => (string) $argument,
- );
- } elseif ($argument instanceof Definition) {
- $data['arguments'][] = $this->getContainerDefinitionData($argument, $omitTags, $showArguments);
- } else {
- $data['arguments'][] = $argument;
- }
- }
+ $data['arguments'] = $this->describeValue($definition->getArguments(), $omitTags, $showArguments);
}
$data['file'] = $definition->getFile();
@@ -388,4 +376,33 @@ private function getCallableData($callable, array $options = array())
throw new \InvalidArgumentException('Callable is not describable.');
}
+
+ private function describeValue($value, $omitTags, $showArguments)
+ {
+ if (is_array($value)) {
+ $data = array();
+ foreach ($value as $k => $v) {
+ $data[$k] = $this->describeValue($v, $omitTags, $showArguments);
+ }
+
+ return $data;
+ }
+
+ if ($value instanceof Reference) {
+ return array(
+ 'type' => 'service',
+ 'id' => (string) $value,
+ );
+ }
+
+ if ($value instanceof Definition) {
+ return $this->getContainerDefinitionData($value, $omitTags, $showArguments);
+ }
+
+ if ($value instanceof ArgumentInterface) {
+ return $this->describeValue($value->getValues(), $omitTags, $showArguments);
+ }
+
+ return $value;
+ }
}
@@ -14,6 +14,8 @@
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Alias;
+use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
+use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -325,8 +327,13 @@ protected function describeContainerDefinition(Definition $definition, array $op
$argumentsInformation[] = sprintf('Service(%s)', (string) $argument);
} elseif ($argument instanceof Definition) {
$argumentsInformation[] = 'Inlined Service';
+ } elseif ($argument instanceof IteratorArgument) {
+ $argumentsInformation[] = 'Iterator';
+ } elseif ($argument instanceof ClosureProxyArgument) {
+ list($reference, $method) = $argument->getValues();
+ $argumentsInformation[] = sprintf('ClosureProxy(Service(%s)::%s())', $reference, $method);
} else {
- $argumentsInformation[] = $argument;
+ $argumentsInformation[] = is_array($argument) ? 'Array' : $argument;
}
}
@@ -12,6 +12,8 @@
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
use Symfony\Component\DependencyInjection\Alias;
+use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
+use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -427,6 +429,17 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom)
$argumentXML->setAttribute('id', (string) $argument);
} elseif ($argument instanceof Definition) {
$argumentXML->appendChild($dom->importNode($this->getContainerDefinitionDocument($argument, null, false, true)->childNodes->item(0), true));
+ } elseif ($argument instanceof IteratorArgument) {
+ $argumentXML->setAttribute('type', 'iterator');
+
+ foreach ($this->getArgumentNodes($argument->getValues(), $dom) as $childArgumentXML) {
+ $argumentXML->appendChild($childArgumentXML);
+ }
+ } elseif ($argument instanceof ClosureProxyArgument) {
+ list($reference, $method) = $argument->getValues();
+ $argumentXML->setAttribute('type', 'closure-proxy');
+ $argumentXML->setAttribute('id', (string) $reference);
+ $argumentXML->setAttribute('method', $method);
} elseif (is_array($argument)) {
$argumentXML->setAttribute('type', 'collection');
@@ -12,6 +12,8 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
use Symfony\Component\DependencyInjection\Alias;
+use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
+use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -108,6 +110,16 @@ public static function getContainerDefinitions()
->addArgument(new Reference('definition2'))
->addArgument('%parameter%')
->addArgument(new Definition('inline_service', array('arg1', 'arg2')))
+ ->addArgument(array(
+ 'foo',
+ new Reference('definition2'),
+ new Definition('inline_service'),
+ ))
+ ->addArgument(new IteratorArgument(array(
+ new Reference('definition_1'),
+ new Reference('definition_2'),
+ )))
+ ->addArgument(new ClosureProxyArgument('definition1', 'get'))
->setFactory(array('Full\\Qualified\\FactoryClass', 'get')),
'definition_2' => $definition2
->setPublic(false)
@@ -34,7 +34,43 @@
],
"file": null,
"tags": []
- }
+ },
+ [
+ "foo",
+ {
+ "type": "service",
+ "id": "definition2"
+ },
+ {
+ "class": "inline_service",
+ "public": true,
+ "synthetic": false,
+ "lazy": false,
+ "shared": true,
+ "abstract": false,
+ "autowire": false,
+ "arguments": [],
+ "file": null,
+ "tags": []
+ }
+ ],
+ [
+ {
+ "type": "service",
+ "id": "definition_1"
+ },
+ {
+ "type": "service",
+ "id": "definition_2"
+ }
+ ],
+ [
+ {
+ "type": "service",
+ "id": "definition1"
+ },
+ "get"
+ ]
]
}
},
@@ -12,6 +12,18 @@
<argument>arg2</argument>
</definition>
</argument>
+ <argument type="collection">
+ <argument>foo</argument>
+ <argument type="service" id="definition2"/>
+ <argument>
+ <definition class="inline_service" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" file=""/>
+ </argument>
+ </argument>
+ <argument type="iterator">
+ <argument type="service" id="definition_1"/>
+ <argument type="service" id="definition_2"/>
+ </argument>
+ <argument type="closure-proxy" id="definition1" method="get"/>
</definition>
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
</container>
@@ -26,7 +26,43 @@
],
"file": null,
"tags": []
- }
+ },
+ [
+ "foo",
+ {
+ "type": "service",
+ "id": "definition2"
+ },
+ {
+ "class": "inline_service",
+ "public": true,
+ "synthetic": false,
+ "lazy": false,
+ "shared": true,
+ "abstract": false,
+ "autowire": false,
+ "arguments": [],
+ "file": null,
+ "tags": []
+ }
+ ],
+ [
+ {
+ "type": "service",
+ "id": "definition_1"
+ },
+ {
+ "type": "service",
+ "id": "definition_2"
+ }
+ ],
+ [
+ {
+ "type": "service",
+ "id": "definition1"
+ },
+ "get"
+ ]
],
"file": null,
"factory_class": "Full\\Qualified\\FactoryClass",
@@ -1,19 +1,22 @@
- ---------------- -----------------------------
-  Option   Value 
- ---------------- -----------------------------
- Service ID -
- Class Full\Qualified\Class1
- Tags -
- Public yes
- Synthetic no
- Lazy yes
- Shared yes
- Abstract yes
- Autowired no
- Factory Class Full\Qualified\FactoryClass
- Factory Method get
- Arguments Service(definition2)
- %parameter%
- Inlined Service
- ---------------- -----------------------------
+ ---------------- -------------------------------------------
+  Option   Value 
+ ---------------- -------------------------------------------
+ Service ID -
+ Class Full\Qualified\Class1
+ Tags -
+ Public yes
+ Synthetic no
+ Lazy yes
+ Shared yes
+ Abstract yes
+ Autowired no
+ Factory Class Full\Qualified\FactoryClass
+ Factory Method get
+ Arguments Service(definition2)
+ %parameter%
+ Inlined Service
+ Array
+ Iterator
+ ClosureProxy(Service(definition1)::get())
+ ---------------- -------------------------------------------
@@ -9,4 +9,16 @@
<argument>arg2</argument>
</definition>
</argument>
+ <argument type="collection">
+ <argument>foo</argument>
+ <argument type="service" id="definition2"/>
+ <argument>
+ <definition class="inline_service" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" file=""/>
+ </argument>
+ </argument>
+ <argument type="iterator">
+ <argument type="service" id="definition_1"/>
+ <argument type="service" id="definition_2"/>
+ </argument>
+ <argument type="closure-proxy" id="definition1" method="get"/>
</definition>

0 comments on commit a46e691

Please sign in to comment.