diff --git a/src/Symfony/Component/Yaml/Dumper.php b/src/Symfony/Component/Yaml/Dumper.php index 9829a49c93..5b0baa5271 100644 --- a/src/Symfony/Component/Yaml/Dumper.php +++ b/src/Symfony/Component/Yaml/Dumper.php @@ -18,6 +18,23 @@ namespace Symfony\Component\Yaml; */ class Dumper { + /** + * The amount of spaces to use for indentation of nested nodes. + * + * @var integer + */ + protected $indentation = 2; + + /** + * Sets the indentation. + * + * @param integer $num The amount of spaces to use for intendation of nested nodes. + */ + public function setIndentation($num) + { + $this->indentation = $num; + } + /** * Dumps a PHP value to YAML. * @@ -46,7 +63,7 @@ class Dumper $prefix, $isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport).':' : '-', $willBeInlined ? ' ' : "\n", - $this->dump($value, $inline - 1, $exceptionOnInvalidType, $objectSupport, $willBeInlined ? 0 : $indent + 2) + $this->dump($value, $inline - 1, $exceptionOnInvalidType, $objectSupport, $willBeInlined ? 0 : $indent + $this->indentation) ).($willBeInlined ? "\n" : ''); } } diff --git a/src/Symfony/Component/Yaml/Yaml.php b/src/Symfony/Component/Yaml/Yaml.php index ae175f1b0e..205d866466 100644 --- a/src/Symfony/Component/Yaml/Yaml.php +++ b/src/Symfony/Component/Yaml/Yaml.php @@ -137,6 +137,7 @@ class Yaml * * @param array $array PHP array * @param integer $inline The level where you switch to inline YAML + * @param integer $indent The amount of spaces to use for indentation of nested nodes. * @param Boolean $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise * @param Boolean $objectSupport true if object support is enabled, false otherwise * @@ -144,9 +145,10 @@ class Yaml * * @api */ - public static function dump($array, $inline = 2, $exceptionOnInvalidType = false, $objectSupport = false) + public static function dump($array, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false) { $yaml = new Dumper(); + $yaml->setIndentation($indent); return $yaml->dump($array, $inline, $exceptionOnInvalidType, $objectSupport); }