[Config] tweaked dumper to indent multi-line info
This commit is contained in:
parent
83fc5ed98f
commit
609636e95e
@ -115,10 +115,12 @@ class ReferenceDumper
|
||||
$default = (string) $default != '' ? ' '.$default : '';
|
||||
$comments = count($comments) ? '# '.implode(', ', $comments) : '';
|
||||
|
||||
$text = sprintf('%-20s %s %s', $node->getName().':', $default, $comments);
|
||||
$text = rtrim(sprintf('%-20s %s %s', $node->getName() . ':', $default, $comments), ' ');
|
||||
|
||||
if ($info = $node->getInfo()) {
|
||||
$this->writeLine('');
|
||||
// indenting multi-line info
|
||||
$info = str_replace("\n", sprintf("\n%" . $depth * 4 . "s# ", ' '), $info);
|
||||
$this->writeLine('# '.$info, $depth * 4);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Definition;
|
||||
|
||||
use Symfony\Component\Config\Definition\ReferenceDumper;
|
||||
use Symfony\Component\Config\Tests\Fixtures\Configuration\ExampleConfiguration;
|
||||
|
||||
class ReferenceDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testDumper()
|
||||
{
|
||||
$configuration = new ExampleConfiguration();
|
||||
|
||||
$dumper = new ReferenceDumper();
|
||||
$this->assertEquals($this->getConfigurationAsString(), $dumper->dump($configuration));
|
||||
}
|
||||
|
||||
private function getConfigurationAsString()
|
||||
{
|
||||
return <<<EOL
|
||||
root:
|
||||
boolean: true
|
||||
scalar_empty: ~
|
||||
scalar_null: ~
|
||||
scalar_true: true
|
||||
scalar_false: false
|
||||
scalar_default: default
|
||||
scalar_array_empty: []
|
||||
scalar_array_defaults:
|
||||
|
||||
# Defaults:
|
||||
- elem1
|
||||
- elem2
|
||||
|
||||
# some info
|
||||
array:
|
||||
child1: ~
|
||||
child2: ~
|
||||
|
||||
# this is a long
|
||||
# multi-line info text
|
||||
# which should be indented
|
||||
child3: ~ # Example: example setting
|
||||
array_prototype:
|
||||
parameters:
|
||||
|
||||
# Prototype
|
||||
name:
|
||||
value: ~ # Required
|
||||
|
||||
EOL;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Fixtures\Configuration;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
class ExampleConfiguration implements ConfigurationInterface
|
||||
{
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('root');
|
||||
|
||||
$rootNode
|
||||
->children()
|
||||
->booleanNode('boolean')->defaultTrue()->end()
|
||||
->scalarNode('scalar_empty')->end()
|
||||
->scalarNode('scalar_null')->defaultNull()->end()
|
||||
->scalarNode('scalar_true')->defaultTrue()->end()
|
||||
->scalarNode('scalar_false')->defaultFalse()->end()
|
||||
->scalarNode('scalar_default')->defaultValue('default')->end()
|
||||
->scalarNode('scalar_array_empty')->defaultValue(array())->end()
|
||||
->scalarNode('scalar_array_defaults')->defaultValue(array('elem1', 'elem2'))->end()
|
||||
->arrayNode('array')
|
||||
->info('some info')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->scalarNode('child1')->end()
|
||||
->scalarNode('child2')->end()
|
||||
->scalarNode('child3')
|
||||
->info(
|
||||
"this is a long\n".
|
||||
"multi-line info text\n".
|
||||
"which should be indented"
|
||||
)
|
||||
->example('example setting')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('array_prototype')
|
||||
->children()
|
||||
->arrayNode('parameters')
|
||||
->useAttributeAsKey('name')
|
||||
->prototype('array')
|
||||
->children()
|
||||
->scalarNode('value')->isRequired()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user