diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php index 95c932466249..547c17b2f7e3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php @@ -54,7 +54,7 @@ public function describe(OutputInterface $output, $object, array $options = arra $this->describeContainerTags($object, $options); break; case $object instanceof ContainerBuilder && isset($options['id']): - $this->describeContainerService($this->resolveServiceDefinition($object, $options['id']), $options); + $this->describeContainerService($this->resolveServiceDefinition($object, $options['id']), $options, $object); break; case $object instanceof ContainerBuilder && isset($options['parameter']): $this->describeContainerParameter($object->resolveEnvPlaceholders($object->getParameter($options['parameter'])), $options); @@ -140,8 +140,9 @@ abstract protected function describeContainerTags(ContainerBuilder $builder, arr * * @param Definition|Alias|object $service * @param array $options + * @param ContainerBuilder|null $builder */ - abstract protected function describeContainerService($service, array $options = array()); + abstract protected function describeContainerService($service, array $options = array(), ContainerBuilder $builder = null); /** * Describes container services. @@ -165,10 +166,11 @@ abstract protected function describeContainerDefinition(Definition $definition, /** * Describes a service alias. * - * @param Alias $alias - * @param array $options + * @param Alias $alias + * @param array $options + * @param ContainerBuilder|null $builder */ - abstract protected function describeContainerAlias(Alias $alias, array $options = array()); + abstract protected function describeContainerAlias(Alias $alias, array $options = array(), ContainerBuilder $builder = null); /** * Describes a container parameter. diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index 99adb3831b77..07f2300725af 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -77,14 +77,14 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio /** * {@inheritdoc} */ - protected function describeContainerService($service, array $options = array()) + protected function describeContainerService($service, array $options = array(), ContainerBuilder $builder = null) { if (!isset($options['id'])) { throw new \InvalidArgumentException('An "id" option must be provided.'); } if ($service instanceof Alias) { - $this->writeData($this->getContainerAliasData($service), $options); + $this->describeContainerAlias($service, $options, $builder); } elseif ($service instanceof Definition) { $this->writeData($this->getContainerDefinitionData($service), $options); } else { @@ -129,9 +129,16 @@ protected function describeContainerDefinition(Definition $definition, array $op /** * {@inheritdoc} */ - protected function describeContainerAlias(Alias $alias, array $options = array()) + protected function describeContainerAlias(Alias $alias, array $options = array(), ContainerBuilder $builder = null) { - $this->writeData($this->getContainerAliasData($alias), $options); + if (!$builder) { + return $this->writeData($this->getContainerAliasData($alias), $options); + } + + $this->writeData( + array($this->getContainerAliasData($alias), $this->getContainerDefinitionData($builder->getDefinition((string) $alias))), + array_merge($options, array('id' => (string) $alias)) + ); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php index 5c91fa3bf9ad..d911b5a7683a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php @@ -97,7 +97,7 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio /** * {@inheritdoc} */ - protected function describeContainerService($service, array $options = array()) + protected function describeContainerService($service, array $options = array(), ContainerBuilder $builder = null) { if (!isset($options['id'])) { throw new \InvalidArgumentException('An "id" option must be provided.'); @@ -106,7 +106,7 @@ protected function describeContainerService($service, array $options = array()) $childOptions = array('id' => $options['id'], 'as_array' => true); if ($service instanceof Alias) { - $this->describeContainerAlias($service, $childOptions); + $this->describeContainerAlias($service, $childOptions, $builder); } elseif ($service instanceof Definition) { $this->describeContainerDefinition($service, $childOptions); } else { @@ -236,12 +236,23 @@ protected function describeContainerDefinition(Definition $definition, array $op /** * {@inheritdoc} */ - protected function describeContainerAlias(Alias $alias, array $options = array()) + protected function describeContainerAlias(Alias $alias, array $options = array(), ContainerBuilder $builder = null) { $output = '- Service: `'.$alias.'`' ."\n".'- Public: '.($alias->isPublic() ? 'yes' : 'no'); - $this->write(isset($options['id']) ? sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output) : $output); + if (!isset($options['id'])) { + return $this->write($output); + } + + $this->write(sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output)); + + if (!$builder) { + return; + } + + $this->write("\n"); + $this->describeContainerDefinition($builder->getDefinition((string) $alias), array_merge($options, array('id' => (string) $alias))); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index a2c8a314e330..8ca63c07b359 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -139,14 +139,14 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio /** * {@inheritdoc} */ - protected function describeContainerService($service, array $options = array()) + protected function describeContainerService($service, array $options = array(), ContainerBuilder $builder = null) { if (!isset($options['id'])) { throw new \InvalidArgumentException('An "id" option must be provided.'); } if ($service instanceof Alias) { - $this->describeContainerAlias($service, $options); + $this->describeContainerAlias($service, $options, $builder); } elseif ($service instanceof Definition) { $this->describeContainerDefinition($service, $options); } else { @@ -333,9 +333,15 @@ protected function describeContainerDefinition(Definition $definition, array $op /** * {@inheritdoc} */ - protected function describeContainerAlias(Alias $alias, array $options = array()) + protected function describeContainerAlias(Alias $alias, array $options = array(), ContainerBuilder $builder = null) { $options['output']->comment(sprintf('This service is an alias for the service %s', (string) $alias)); + + if (!$builder) { + return; + } + + return $this->describeContainerDefinition($builder->getDefinition((string) $alias), array_merge($options, array('id' => (string) $alias))); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index 7d7d5f0956ed..0af77eb1b8dc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -62,13 +62,13 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio /** * {@inheritdoc} */ - protected function describeContainerService($service, array $options = array()) + protected function describeContainerService($service, array $options = array(), ContainerBuilder $builder = null) { if (!isset($options['id'])) { throw new \InvalidArgumentException('An "id" option must be provided.'); } - $this->writeDocument($this->getContainerServiceDocument($service, $options['id'])); + $this->writeDocument($this->getContainerServiceDocument($service, $options['id'], $builder)); } /** @@ -90,9 +90,18 @@ protected function describeContainerDefinition(Definition $definition, array $op /** * {@inheritdoc} */ - protected function describeContainerAlias(Alias $alias, array $options = array()) + protected function describeContainerAlias(Alias $alias, array $options = array(), ContainerBuilder $builder = null) { - $this->writeDocument($this->getContainerAliasDocument($alias, isset($options['id']) ? $options['id'] : null)); + $dom = new \DOMDocument('1.0', 'UTF-8'); + $dom->appendChild($dom->importNode($this->getContainerAliasDocument($alias, isset($options['id']) ? $options['id'] : null)->childNodes->item(0), true)); + + if (!$builder) { + return $this->writeDocument($dom); + } + + $dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($builder->getDefinition((string) $alias), (string) $alias)->childNodes->item(0), true)); + + $this->writeDocument($dom); } /** @@ -261,17 +270,21 @@ private function getContainerTagsDocument(ContainerBuilder $builder, $showPrivat } /** - * @param mixed $service - * @param string $id + * @param mixed $service + * @param string $id + * @param ContainerBuilder|null $builder * * @return \DOMDocument */ - private function getContainerServiceDocument($service, $id) + private function getContainerServiceDocument($service, $id, ContainerBuilder $builder = null) { $dom = new \DOMDocument('1.0', 'UTF-8'); if ($service instanceof Alias) { $dom->appendChild($dom->importNode($this->getContainerAliasDocument($service, $id)->childNodes->item(0), true)); + if ($builder) { + $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)); } else { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php index 78a770da85a0..a1c82fe1580e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php @@ -90,6 +90,35 @@ public function getDescribeContainerAliasTestData() return $this->getDescriptionTestData(ObjectsProvider::getContainerAliases()); } + /** @dataProvider getDescribeContainerDefinitionWhichIsAnAliasTestData */ + public function testDescribeContainerDefinitionWhichIsAnAlias(Alias $alias, $expectedDescription, ContainerBuilder $builder, $options = array()) + { + $this->assertDescription($expectedDescription, $builder, $options); + } + + public function getDescribeContainerDefinitionWhichIsAnAliasTestData() + { + $builder = current(ObjectsProvider::getContainerBuilders()); + $builder->setDefinition('service_1', $builder->getDefinition('definition_1')); + $builder->setDefinition('service_2', $builder->getDefinition('definition_2')); + + $aliases = ObjectsProvider::getContainerAliases(); + $aliasesWithDefinitions = array(); + foreach ($aliases as $name => $alias) { + $aliasesWithDefinitions[str_replace('alias_', 'alias_with_definition_', $name)] = $alias; + } + + $i = 0; + $data = $this->getDescriptionTestData($aliasesWithDefinitions); + foreach ($aliases as $name => $alias) { + $data[$i][] = $builder; + $data[$i][] = array('id' => $name); + ++$i; + } + + return $data; + } + /** @dataProvider getDescribeContainerParameterTestData */ public function testDescribeContainerParameter($parameter, $expectedDescription, array $options) { @@ -146,7 +175,7 @@ private function assertDescription($expectedDescription, $describedObject, array if ('json' === $this->getFormat()) { $this->assertEquals(json_decode($expectedDescription), json_decode($output->fetch())); } else { - $this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL, "\n", $output->fetch()))); + $this->assertEquals(trim(preg_replace('/[\s\t\r]+/', ' ', $expectedDescription)), trim(preg_replace('/[\s\t\r]+/', ' ', str_replace(PHP_EOL, "\n", $output->fetch())))); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.json new file mode 100644 index 000000000000..9efbde5a8638 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.json @@ -0,0 +1,20 @@ +[ + { + "service": "service_1", + "public": true + }, + { + "class": "Full\\Qualified\\Class1", + "public": true, + "synthetic": false, + "lazy": true, + "shared": true, + "abstract": true, + "autowire": false, + "autowiring_types": [], + "file": null, + "factory_class": "Full\\Qualified\\FactoryClass", + "factory_method": "get", + "tags": [] + } +] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.md new file mode 100644 index 000000000000..55331b39dc95 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.md @@ -0,0 +1,18 @@ +alias_1 +~~~~~~~ + +- Service: `service_1` +- Public: yes + +service_1 +~~~~~~~~~ + +- Class: `Full\Qualified\Class1` +- Public: yes +- Synthetic: no +- Lazy: yes +- Shared: yes +- Abstract: yes +- Autowired: no +- Factory Class: `Full\Qualified\FactoryClass` +- Factory Method: `get` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.txt new file mode 100644 index 000000000000..52d2520a8771 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.txt @@ -0,0 +1,21 @@ + // This service is an alias for the service service_1 + +Information for Service "service_1" +=================================== + + ------------------ ----------------------------- +  Option   Value  + ------------------ ----------------------------- + Service ID service_1 + Class Full\Qualified\Class1 + Tags - + Public yes + Synthetic no + Lazy yes + Shared yes + Abstract yes + Autowired no + Autowiring Types - + Factory Class Full\Qualified\FactoryClass + Factory Method get + ------------------ ----------------------------- \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.xml new file mode 100644 index 000000000000..5515332b0875 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.json new file mode 100644 index 000000000000..9f89e47dc266 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.json @@ -0,0 +1,41 @@ +[ + { + "service": "service_2", + "public": false + }, + { + "class": "Full\\Qualified\\Class2", + "public": false, + "synthetic": true, + "lazy": false, + "shared": true, + "abstract": false, + "autowire": false, + "autowiring_types": [], + "file": "\/path\/to\/file", + "factory_service": "factory.service", + "factory_method": "get", + "calls": [ + "setMailer" + ], + "tags": [ + { + "name": "tag1", + "parameters": { + "attr1": "val1", + "attr2": "val2" + } + }, + { + "name": "tag1", + "parameters": { + "attr3": "val3" + } + }, + { + "name": "tag2", + "parameters": [] + } + ] + } +] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.md new file mode 100644 index 000000000000..12624134f60a --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.md @@ -0,0 +1,26 @@ +alias_2 +~~~~~~~ + +- Service: `service_2` +- Public: no + +service_2 +~~~~~~~~~ + +- Class: `Full\Qualified\Class2` +- Public: no +- Synthetic: yes +- Lazy: no +- Shared: yes +- Abstract: no +- Autowired: no +- File: `/path/to/file` +- Factory Service: `factory.service` +- Factory Method: `get` +- Call: `setMailer` +- Tag: `tag1` + - Attr1: val1 + - Attr2: val2 +- Tag: `tag1` + - Attr3: val3 +- Tag: `tag2` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.txt new file mode 100644 index 000000000000..f386f4540e5d --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.txt @@ -0,0 +1,25 @@ + // This service is an alias for the service service_2 + +Information for Service "service_2" +=================================== + + ------------------ --------------------------------- +  Option   Value  + ------------------ --------------------------------- + Service ID service_2 + Class Full\Qualified\Class2 + Tags tag1 (attr1: val1, attr2: val2) + tag1 (attr3: val3) + tag2 + Calls setMailer + Public no + Synthetic yes + Lazy no + Shared yes + Abstract no + Autowired no + Autowiring Types - + Required File /path/to/file + Factory Service factory.service + Factory Method get + ------------------ --------------------------------- \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.xml new file mode 100644 index 000000000000..c549e50e5976 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.xml @@ -0,0 +1,18 @@ + + + + + + + + + + val1 + val2 + + + val3 + + + +