8000 [FrameworkBundle][Console] Fix descriptors to support IteratorArgument, ClosureProxy and arrays by ogizanagi · Pull Request #21499 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
9E88 "id": "definition_1"
},
{
"type": "service",
"id": "definition_2"
}
],
[
{
"type": "service",
"id": "definition1"
},
"get"
]
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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())
---------------- -------------------------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -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