From 2145f964a3e57a227fc37405a924f214fa0bb616 Mon Sep 17 00:00:00 2001 From: Inal DJAFAR Date: Mon, 3 Mar 2014 23:11:16 +0100 Subject: [PATCH 1/2] [FrameworkBundle] Add parameter descriptors --- .../Console/Descriptor/Descriptor.php | 8 ++++++ .../Console/Descriptor/JsonDescriptor.php | 10 +++++++ .../Console/Descriptor/MarkdownDescriptor.php | 8 ++++++ .../Console/Descriptor/TextDescriptor.php | 8 ++++++ .../Console/Descriptor/XmlDescriptor.php | 28 +++++++++++++++++++ 5 files changed, 62 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php index e85317113a320..7f1c81835dc54 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php @@ -179,6 +179,14 @@ abstract protected function describeContainerDefinition(Definition $definition, */ abstract protected function describeContainerAlias(Alias $alias, array $options = array()); + /** + * Describes a container parameter. + * + * @param parameter + * @param array $options + */ + abstract protected function describeContainerParameter($parameter, array $options = array()); + /** * Formats a value as string. * diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index b5c4908c66a85..470114d1ef53b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -134,6 +134,16 @@ protected function describeContainerAlias(Alias $alias, array $options = array() $this->writeData($this->getContainerAliasData($alias), $options); } + /** + * {@inheritdoc} + */ + protected function describeContainerParameter($parameter, array $options = array()) + { + $key = isset($options['parameter']) ? $options['parameter'] : ''; + + $this->writeData(array($key => $this->formatParameter($parameter)), $options); + } + /** * Writes data as json. * diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php index 23a9a85719118..fc7bac755393f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php @@ -207,6 +207,14 @@ protected function describeContainerAlias(Alias $alias, array $options = array() $this->write(isset($options['id']) ? sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output) : $output); } + /** + * {@inheritdoc} + */ + protected function describeContainerParameter($parameter, array $options = array()) + { + $this->write(isset($options['parameter']) ? sprintf("%s\n%s\n%s", $options['parameter'], str_repeat('~', strlen($options['parameter'])), $this->formatParameter($parameter)): $parameter); + } + private function formatRouterConfig(array $array) { if (!count($array)) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index d34d42ef8a524..67cb356bc39ba 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -276,6 +276,14 @@ protected function describeContainerAlias(Alias $alias, array $options = array() $this->writeText(sprintf('This service is an alias for the service %s', (string) $alias), $options); } + /** + * {@inheritdoc} + */ + protected function describeContainerParameter($parameter, array $options = array()) + { + $this->writeText($this->formatParameter($parameter), $options); + } + /** * @param array $array * diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index b10f2816a0462..7ca7e03f86363 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -91,6 +91,14 @@ protected function describeContainerAlias(Alias $alias, array $options = array() $this->writeDocument($this->getContainerAliasDocument($alias, isset($options['id']) ? $options['id'] : null)); } + /** + * {@inheritdoc} + */ + protected function describeContainerParameter($parameter, array $options = array()) + { + $this->writeDocument($this->getContainerParameterDocument($parameter, $options)); + } + /** * Writes DOM document. * @@ -365,4 +373,24 @@ private function getContainerAliasDocument(Alias $alias, $id = null) return $dom; } + + /** + * @param $parameter + * @param array $options + * + * @return \DOMDocument + */ + private function getContainerParameterDocument($parameter, $options = array()) + { + $dom = new \DOMDocument('1.0', 'UTF-8'); + $dom->appendChild($parameterXML = $dom->createElement('parameter')); + + if (isset( $options['parameter'])) { + $parameterXML->setAttribute('key', $options['parameter']); + } + + $parameterXML->appendChild(new \DOMText($this->formatParameter($parameter))); + + return $dom; + } } From fd200d591a23a9d224c8ae4b6a8e1eafffe549e8 Mon Sep 17 00:00:00 2001 From: Inal DJAFAR Date: Tue, 4 Mar 2014 01:01:26 +0100 Subject: [PATCH 2/2] [FrameworkBundle][Test] Add parameter descriptor tests --- .../Console/Descriptor/Descriptor.php | 11 ----------- .../Console/Descriptor/MarkdownDescriptor.php | 2 +- .../Console/Descriptor/XmlDescriptor.php | 2 +- .../Console/Descriptor/AbstractDescriptorTest.php | 15 +++++++++++++++ .../Tests/Console/Descriptor/ObjectsProvider.php | 10 ++++++++++ .../Tests/Fixtures/Descriptor/parameter.json | 3 +++ .../Tests/Fixtures/Descriptor/parameter.md | 4 ++++ .../Tests/Fixtures/Descriptor/parameter.txt | 1 + .../Tests/Fixtures/Descriptor/parameter.xml | 2 ++ 9 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.json create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.md create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.txt create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.xml diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php index 7f1c81835dc54..1f225a3f470f4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php @@ -114,17 +114,6 @@ abstract protected function describeRouteCollection(RouteCollection $routes, arr */ abstract protected function describeRoute(Route $route, array $options = array()); - /** - * Describes a specific container parameter. - * - * @param mixed $parameterValue - * @param array $options - */ - protected function describeContainerParameter($parameterValue, array $options = array()) - { - $this->write($this->formatParameter($parameterValue)); - } - /** * Describes container parameters. * diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php index fc7bac755393f..6f4fb7683184b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php @@ -212,7 +212,7 @@ protected function describeContainerAlias(Alias $alias, array $options = array() */ protected function describeContainerParameter($parameter, array $options = array()) { - $this->write(isset($options['parameter']) ? sprintf("%s\n%s\n%s", $options['parameter'], str_repeat('~', strlen($options['parameter'])), $this->formatParameter($parameter)): $parameter); + $this->write(isset($options['parameter']) ? sprintf("%s\n%s\n\n%s", $options['parameter'], str_repeat('=', strlen($options['parameter'])), $this->formatParameter($parameter)): $parameter); } private function formatRouterConfig(array $array) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index 7ca7e03f86363..545bc843db3d7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -385,7 +385,7 @@ private function getContainerParameterDocument($parameter, $options = array()) $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($parameterXML = $dom->createElement('parameter')); - if (isset( $options['parameter'])) { + if (isset($options['parameter'])) { $parameterXML->setAttribute('key', $options['parameter']); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php index a8e64e3797ff5..1b4c8d084a0a1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php @@ -87,6 +87,21 @@ public function getDescribeContainerAliasTestData() return $this->getDescriptionTestData(ObjectsProvider::getContainerAliases()); } + /** @dataProvider getDescribeContainerParameterTestData */ + public function testDescribeContainerParameter($parameter, $expectedDescription, array $options) + { + $this->assertDescription($expectedDescription, $parameter, $options); + } + + public function getDescribeContainerParameterTestData() + { + $data = $this->getDescriptionTestData(ObjectsProvider::getContainerParameter()); + + array_push($data[0], array('parameter' => 'database_name')); + + return $data; + } + abstract protected function getDescriptor(); abstract protected function getFormat(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php index e6a2617a6031b..1d18431c9ea45 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php @@ -66,6 +66,16 @@ public static function getContainerParameters() ); } + public static function getContainerParameter() + { + $builder = new ContainerBuilder(); + $builder->setParameter('database_name', 'symfony'); + + return array( + 'parameter' => $builder + ); + } + public static function getContainerBuilders() { $builder1 = new ContainerBuilder(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.json new file mode 100644 index 0000000000000..069fdbc5d396f --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.json @@ -0,0 +1,3 @@ +{ + "database_name": "symfony" +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.md new file mode 100644 index 0000000000000..4c67978f68347 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.md @@ -0,0 +1,4 @@ +database_name +============= + +symfony diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.txt new file mode 100644 index 0000000000000..a1435083911ce --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.txt @@ -0,0 +1 @@ +symfony diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.xml new file mode 100644 index 0000000000000..8465522c1bc2a --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.xml @@ -0,0 +1,2 @@ + +symfony