Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e505ecd

Browse filesBrowse files
committed
feature #10370 [FrameworkBundle][Console] Add parameter descriptors (inalgnu)
This PR was squashed before being merged into the 2.5-dev branch (closes #10370). Discussion ---------- [FrameworkBundle][Console] Add parameter descriptors | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10345 | License | MIT | Doc PR | n/a I've added several descriptors for each format, henceforth : ``php app/console container:debug --parameter=database_name --format=txt`` will output: ``symfony`` ``php app/console container:debug --parameter=database_name --format=json`` will output: ```json { "database_name": "symfony" } ``` ``php app/console container:debug --parameter=database_name --format=xml`` will output : ```xml <?xml version="1.0" encoding="UTF-8"?> <parameter key="database_name">symfony</parameter> ``` and ``php app/console container:debug --parameter=database_name --format=md`` will output : ```md database_name ============= symfony ``` what do you think ? Commits ------- 6aa1050 Add parameter descriptors
2 parents 4a06daf + 6aa1050 commit e505ecd
Copy full SHA for e505ecd

File tree

Expand file treeCollapse file tree

11 files changed

+97
-11
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+97
-11
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php
+8-11Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,6 @@ abstract protected function describeRouteCollection(RouteCollection $routes, arr
114114
*/
115115
abstract protected function describeRoute(Route $route, array $options = array());
116116

117-
/**
118-
* Describes a specific container parameter.
119-
*
120-
* @param mixed $parameterValue
121-
* @param array $options
122-
*/
123-
protected function describeContainerParameter($parameterValue, array $options = array())
124-
{
125-
$this->write($this->formatParameter($parameterValue));
126-
}
127-
128117
/**
129118
* Describes container parameters.
130119
*
@@ -179,6 +168,14 @@ abstract protected function describeContainerDefinition(Definition $definition,
179168
*/
180169
abstract protected function describeContainerAlias(Alias $alias, array $options = array());
181170

171+
/**
172+
* Describes a container parameter.
173+
*
174+
* @param parameter
175+
* @param array $options
176+
*/
177+
abstract protected function describeContainerParameter($parameter, array $options = array());
178+
182179
/**
183180
* Formats a value as string.
184181
*

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ protected function describeContainerAlias(Alias $alias, array $options = array()
134134
$this->writeData($this->getContainerAliasData($alias), $options);
135135
}
136136

137+
/**
138+
* {@inheritdoc}
139+
*/
140+
protected function describeContainerParameter($parameter, array $options = array())
141+
{
142+
$key = isset($options['parameter']) ? $options['parameter'] : '';
143+
144+
$this->writeData(array($key => $this->formatParameter($parameter)), $options);
145+
}
146+
137147
/**
138148
* Writes data as json.
139149
*

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ protected function describeContainerAlias(Alias $alias, array $options = array()
207207
$this->write(isset($options['id']) ? sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output) : $output);
208208
}
209209

210+
/**
211+
* {@inheritdoc}
212+
*/
213+
protected function describeContainerParameter($parameter, array $options = array())
214+
{
215+
$this->write(isset($options['parameter']) ? sprintf("%s\n%s\n\n%s", $options['parameter'], str_repeat('=', strlen($options['parameter'])), $this->formatParameter($parameter)): $parameter);
216+
}
217+
210218
private function formatRouterConfig(array $array)
211219
{
212220
if (!count($array)) {

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ protected function describeContainerAlias(Alias $alias, array $options = array()
276276
$this->writeText(sprintf('This service is an alias for the service <info>%s</info>', (string) $alias), $options);
277277
}
278278

279+
/**
280+
* {@inheritdoc}
281+
*/
282+
protected function describeContainerParameter($parameter, array $options = array())
283+
{
284+
$this->writeText($this->formatParameter($parameter), $options);
285+
}
286+
279287
/**
280288
* @param array $array
281289
*

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ protected function describeContainerAlias(Alias $alias, array $options = array()
9191
$this->writeDocument($this->getContainerAliasDocument($alias, isset($options['id']) ? $options['id'] : null));
9292
}
9393

94+
/**
95+
* {@inheritdoc}
96+
*/
97+
protected function describeContainerParameter($parameter, array $options = array())
98+
{
99+
$this->writeDocument($this->getContainerParameterDocument($parameter, $options));
100+
}
101+
94102
/**
95103
* Writes DOM document.
96104
*
@@ -365,4 +373,24 @@ private function getContainerAliasDocument(Alias $alias, $id = null)
365373

366374
return $dom;
367375
}
376+
377+
/**
378+
* @param $parameter
379+
* @param array $options
380+
*
381+
* @return \DOMDocument
382+
*/
383+
private function getContainerParameterDocument($parameter, $options = array())
384+
{
385+
$dom = new \DOMDocument('1.0', 'UTF-8');
386+
$dom->appendChild($parameterXML = $dom->createElement('parameter'));
387+
388+
if (isset($options['parameter'])) {
389+
$parameterXML->setAttribute('key', $options['parameter']);
390+
}
391+
392+
$parameterXML->appendChild(new \DOMText($this->formatParameter($parameter)));
393+
394+
return $dom;
395+
}
368396
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ public function getDescribeContainerAliasTestData()
8787
return $this->getDescriptionTestData(ObjectsProvider::getContainerAliases());
8888
}
8989

90+
/** @dataProvider getDescribeContainerParameterTestData */
91+
public function testDescribeContainerParameter($parameter, $expectedDescription, array $options)
92+
{
93+
$this->assertDescription($expectedDescription, $parameter, $options);
94+
}
95+
96+
public function getDescribeContainerParameterTestData()
97+
{
98+
$data = $this->getDescriptionTestData(ObjectsProvider::getContainerParameter());
99+
100+
array_push($data[0], array('parameter' => 'database_name'));
101+
102+
return $data;
103+
}
104+
90105
abstract protected function getDescriptor();
91106
abstract protected function getFormat();
92107

‎src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ public static function getContainerParameters()
6666
);
6767
}
6868

69+
public static function getContainerParameter()
70+
{
71+
$builder = new ContainerBuilder();
72+
$builder->setParameter('database_name', 'symfony');
73+
74+
return array(
75+
'parameter' => $builder
76+
);
77+
}
78+
6979
public static function getContainerBuilders()
7080
{
7181
$builder1 = new ContainerBuilder();
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"database_name": "symfony"
3+
}
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
database_name
2+
=============
3+
4+
symfony
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
symfony
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<parameter key="database_name">symfony</parameter>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.