4 * This file is part of the symfony package.
5 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 require_once(dirname(__FILE__
).'/sfYamlInline.php');
14 * sfYamlDumper dumps PHP variables to YAML strings.
18 * @author Fabien Potencier <fabien.potencier@symfony-project.com>
19 * @version SVN: $Id: sfYamlDumper.class.php 10575 2008-08-01 13:08:42Z nicolas $
24 * Dumps a PHP value to YAML.
26 * @param mixed $input The PHP value
27 * @param integer $inline The level where you switch to inline YAML
28 * @param integer $indent The level o indentation indentation (used internally)
30 * @return string The YAML representation of the PHP value
32 public function dump($input, $inline = 0, $indent = 0)
35 $prefix = $indent ?
str_repeat(' ', $indent) : '';
37 if ($inline <= 0 ||
!is_array($input) ||
empty($input))
39 $output .= $prefix.sfYamlInline
::dump($input);
43 $isAHash = array_keys($input) !== range(0, count($input) - 1);
45 foreach ($input as $key => $value)
47 $willBeInlined = $inline - 1 <= 0 ||
!is_array($value) ||
empty($value);
49 $output .= sprintf('%s%s%s%s',
51 $isAHash ? sfYamlInline
::dump($key).':' : '-',
52 $willBeInlined ?
' ' : "\n",
53 $this->dump($value, $inline - 1, $willBeInlined ?
0 : $indent +
2)
54 ).($willBeInlined ?
"\n" : '');