diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index c9d0e419e290..47f08de6bcad 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -44,6 +44,7 @@ protected function configure() ->setDefinition(array( new InputArgument('name', InputArgument::OPTIONAL, 'A service name (foo)'), new InputOption('show-private', null, InputOption::VALUE_NONE, 'Used to show public *and* private services'), + new InputOption('show-arguments', null, InputOption::VALUE_NONE, 'Used to show arguments in services'), new InputOption('tag', null, InputOption::VALUE_REQUIRED, 'Shows all services with a specific tag'), new InputOption('tags', null, InputOption::VALUE_NONE, 'Displays tagged services for an application'), new InputOption('parameter', null, InputOption::VALUE_REQUIRED, 'Displays a specific parameter for an application'), @@ -118,6 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $helper = new DescriptorHelper(); $options['format'] = $input->getOption('format'); + $options['show_arguments'] = $input->getOption('show-arguments'); $options['raw_text'] = $input->getOption('raw'); $options['output'] = $io; $helper->describe($output, $object, $options); diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index 07f2300725af..fb4111c1c583 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -99,6 +99,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o { $serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds(); $showPrivate = isset($options['show_private']) && $options['show_private']; + $showArguments = isset($options['show_arguments']) && $options['show_arguments']; $data = array('definitions' => array(), 'aliases' => array(), 'services' => array()); foreach ($this->sortServiceIds($serviceIds) as $serviceId) { @@ -108,7 +109,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o $data['aliases'][$serviceId] = $this->getContainerAliasData($service); } elseif ($service instanceof Definition) { if (($showPrivate || $service->isPublic())) { - $data['definitions'][$serviceId] = $this->getContainerDefinitionData($service); + $data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, false, $showArguments); } } else { $data['services'][$serviceId] = get_class($service); @@ -208,7 +209,7 @@ protected function getRouteData(Route $route) * * @return array */ - private function getContainerDefinitionData(Definition $definition, $omitTags = false) + private function getContainerDefinitionData(Definition $definition, $omitTags = false, $showArguments = false) { $data = array( 'class' => (string) $definition->getClass(), @@ -232,6 +233,23 @@ 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['file'] = $definition->getFile(); if ($factory = $definition->getFactory()) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php index d911b5a7683a..3bc82e2d7cf3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php @@ -129,6 +129,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o $serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds(); $showPrivate = isset($options['show_private']) && $options['show_private']; + $showArguments = isset($options['show_arguments']) && $options['show_arguments']; $services = array('definitions' => array(), 'aliases' => array(), 'services' => array()); foreach ($this->sortServiceIds($serviceIds) as $serviceId) { @@ -149,7 +150,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o $this->write("\n\nDefinitions\n-----------\n"); foreach ($services['definitions'] as $id => $service) { $this->write("\n"); - $this->describeContainerDefinition($service, array('id' => $id)); + $this->describeContainerDefinition($service, array('id' => $id, 'show_arguments' => $showArguments)); } } @@ -195,6 +196,10 @@ protected function describeContainerDefinition(Definition $definition, array $op } } + if (isset($options['show_arguments']) && $options['show_arguments']) { + $output .= "\n".'- Arguments: '.($definition->getArguments() ? 'yes' : 'no'); + } + if ($definition->getFile()) { $output .= "\n".'- File: `'.$definition->getFile().'`'; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index 0af77eb1b8dc..82277757e04a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -76,7 +76,7 @@ protected function describeContainerService($service, array $options = array(), */ protected function describeContainerServices(ContainerBuilder $builder, array $options = array()) { - $this->writeDocument($this->getContainerServicesDocument($builder, isset($options['tag']) ? $options['tag'] : null, isset($options['show_private']) && $options['show_private'])); + $this->writeDocument($this->getContainerServicesDocument($builder, isset($options['tag']) ? $options['tag'] : null, isset($options['show_private']) && $options['show_private'], isset($options['show_arguments']) && $options['show_arguments'])); } /** @@ -273,10 +273,11 @@ private function getContainerTagsDocument(ContainerBuilder $builder, $showPrivat * @param mixed $service * @param string $id * @param ContainerBuilder|null $builder + * @param bool $showArguments * * @return \DOMDocument */ - private function getContainerServiceDocument($service, $id, ContainerBuilder $builder = null) + private function getContainerServiceDocument($service, $id, ContainerBuilder $builder = null, $showArguments = false) { $dom = new \DOMDocument('1.0', 'UTF-8'); @@ -286,7 +287,7 @@ private function getContainerServiceDocument($service, $id, ContainerBuilder $bu $dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($builder->getDefinition((string) $service), (string) $service)->childNodes->item(0), true)); } } elseif ($service instanceof Definition) { - $dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($service, $id)->childNodes->item(0), true)); + $dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($service, $id, false, $showArguments)->childNodes->item(0), true)); } else { $dom->appendChild($serviceXML = $dom->createElement('service')); $serviceXML->setAttribute('id', $id); @@ -300,10 +301,11 @@ private function getContainerServiceDocument($service, $id, ContainerBuilder $bu * @param ContainerBuilder $builder * @param string|null $tag * @param bool $showPrivate + * @param bool $showArguments * * @return \DOMDocument */ - private function getContainerServicesDocument(ContainerBuilder $builder, $tag = null, $showPrivate = false) + private function getContainerServicesDocument(ContainerBuilder $builder, $tag = null, $showPrivate = false, $showArguments = false) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($containerXML = $dom->createElement('container')); @@ -317,7 +319,7 @@ private function getContainerServicesDocument(ContainerBuilder $builder, $tag = continue; } - $serviceXML = $this->getContainerServiceDocument($service, $serviceId); + $serviceXML = $this->getContainerServiceDocument($service, $serviceId, null, $showArguments); $containerXML->appendChild($containerXML->ownerDocument->importNode($serviceXML->childNodes->item(0), true)); } @@ -331,7 +333,7 @@ private function getContainerServicesDocument(ContainerBuilder $builder, $tag = * * @return \DOMDocument */ - private function getContainerDefinitionDocument(Definition $definition, $id = null, $omitTags = false) + private function getContainerDefinitionDocument(Definition $definition, $id = null, $omitTags = false, $showArguments = false) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($serviceXML = $dom->createElement('definition')); @@ -382,6 +384,12 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu } } + if ($showArguments) { + foreach ($this->getArgumentNodes($definition->getArguments(), $dom) as $node) { + $serviceXML->appendChild($node); + } + } + if (!$omitTags) { $tags = $definition->getTags(); @@ -404,6 +412,43 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu return $dom; } + /** + * @param array $arguments + * + * @return \DOMNode[] + */ + private function getArgumentNodes(array $arguments, \DOMDocument $dom) + { + $nodes = array(); + + foreach ($arguments as $argumentKey => $argument) { + $argumentXML = $dom->createElement('argument'); + + if (is_string($argumentKey)) { + $argumentXML->setAttribute('key', $argumentKey); + } + + if ($argument instanceof Reference) { + $argumentXML->setAttribute('type', 'service'); + $argumentXML->setAttribute('id', (string) $argument); + } elseif ($argument instanceof Definition) { + $argumentXML->appendChild($dom->importNode($this->getContainerDefinitionDocument($argument, null, false, true)->childNodes->item(0), true)); + } elseif (is_array($argument)) { + $argumentXML->setAttribute('type', 'collection'); + + foreach ($this->getArgumentNodes($argument, $dom) as $childArgumenXML) { + $argumentXML->appendChild($childArgumenXML); + } + } else { + $argumentXML->appendChild(new \DOMText($argument)); + } + + $nodes[] = $argumentXML; + } + + return $nodes; + } + /** * @param Alias $alias * @param string|null $id diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php index a1c82fe1580e..f7218e1ec0e8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php @@ -197,6 +197,7 @@ private function getContainerBuilderDescriptionTestData(array $objects) 'public' => array('show_private' => false), 'tag1' => array('show_private' => true, 'tag' => 'tag1'), 'tags' => array('group_by' => 'tags', 'show_private' => true), + 'arguments' => array('show_private' => false, 'show_arguments' => true), ); $data = array(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php index 5244072ae85c..8da498b7e43b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php @@ -105,6 +105,9 @@ public static function getContainerDefinitions() ->setSynthetic(false) ->setLazy(true) ->setAbstract(true) + ->addArgument(new Reference('definition2')) + ->addArgument('%parameter%') + ->addArgument(new Definition('inline_service', array('arg1', 'arg2'))) ->setFactory(array('Full\\Qualified\\FactoryClass', 'get')), 'definition_2' => $definition2 ->setPublic(false) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json new file mode 100644 index 000000000000..ff2db6858d00 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json @@ -0,0 +1,56 @@ +{ + "definitions": { + "definition_1": { + "class": "Full\\Qualified\\Class1", + "public": true, + "synthetic": false, + "lazy": true, + "shared": true, + "abstract": true, + "file": null, + "factory_class": "Full\\Qualified\\FactoryClass", + "factory_method": "get", + "tags": [ + + ], + "autowire": false, + "autowiring_types": [], + "arguments": [ + { + "type": "service", + "id": "definition2" + }, + "%parameter%", + { + "class": "inline_service", + "public": true, + "synthetic": false, + "lazy": false, + "shared": true, + "abstract": false, + "autowire": false, + "autowiring_types": [], + "arguments": [ + "arg1", + "arg2" + ], + "file": null, + "tags": [] + } + ] + } + }, + "aliases": { + "alias_1": { + "service": "service_1", + "public": true + }, + "alias_2": { + "service": "service_2", + "public": false + } + }, + "services": { + "service_container": "Symfony\\Component\\DependencyInjection\\ContainerBuilder" + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.md new file mode 100644 index 000000000000..b3792a8ad2b2 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.md @@ -0,0 +1,41 @@ +Public services +=============== + +Definitions +----------- + +definition_1 +~~~~~~~~~~~~ + +- Class: `Full\Qualified\Class1` +- Public: yes +- Synthetic: no +- Lazy: yes +- Shared: yes +- Abstract: yes +- Autowired: no +- Arguments: yes +- Factory Class: `Full\Qualified\FactoryClass` +- Factory Method: `get` + + +Aliases +------- + +alias_1 +~~~~~~~ + +- Service: `service_1` +- Public: yes + +alias_2 +~~~~~~~ + +- Service: `service_2` +- Public: no + + +Services +-------- + +- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.txt new file mode 100644 index 000000000000..0e42596b9923 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.txt @@ -0,0 +1,13 @@ + +Symfony Container Public Services +================================= + + ------------------- -------------------------------------------------------- +  Service ID   Class name  + ------------------- -------------------------------------------------------- + alias_1 alias for "service_1" + alias_2 alias for "service_2" + definition_1 Full\Qualified\Class1 + service_container Symfony\Component\DependencyInjection\ContainerBuilder + ------------------- -------------------------------------------------------- + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml new file mode 100644 index 000000000000..b1c4ddfd9031 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml @@ -0,0 +1,17 @@ + + + + + + + + %parameter% + + + arg1 + arg2 + + + + +