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 if (!defined('_ECRIRE_INC_VERSION')) return;
13 require_once(dirname(__FILE__
).'/sfYamlInline.php');
16 * sfYamlDumper dumps PHP variables to YAML strings.
20 * @author Fabien Potencier <fabien.potencier@symfony-project.com>
21 * @version SVN: $Id: sfYamlDumper.class.php 10575 2008-08-01 13:08:42Z nicolas $
26 * Dumps a PHP value to YAML.
28 * @param mixed $input The PHP value
29 * @param integer $inline The level where you switch to inline YAML
30 * @param integer $indent The level o indentation indentation (used internally)
32 * @return string The YAML representation of the PHP value
34 public function dump($input, $inline = 0, $indent = 0)
37 $prefix = $indent ?
str_repeat(' ', $indent) : '';
39 if ($inline <= 0 ||
!is_array($input) ||
empty($input))
41 $output .= $prefix.sfYamlInline
::dump($input);
45 $isAHash = array_keys($input) !== range(0, count($input) - 1);
47 foreach ($input as $key => $value)
49 $willBeInlined = $inline - 1 <= 0 ||
!is_array($value) ||
empty($value);
51 $output .= sprintf('%s%s%s%s',
53 $isAHash ? sfYamlInline
::dump($key).':' : '-',
54 $willBeInlined ?
' ' : "\n",
55 $this->dump($value, $inline - 1, $willBeInlined ?
0 : $indent +
2)
56 ).($willBeInlined ?
"\n" : '');