[SPIP] ~maj v3.0.14-->v3.0.17
[ptitvelo/web/www.git] / www / plugins-dist / textwheel / lib / yaml / sfYamlDumper.php
1 <?php
2
3 /*
4 * This file is part of the symfony package.
5 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 if (!defined('_ECRIRE_INC_VERSION')) return;
12
13 require_once(dirname(__FILE__).'/sfYamlInline.php');
14
15 /**
16 * sfYamlDumper dumps PHP variables to YAML strings.
17 *
18 * @package symfony
19 * @subpackage yaml
20 * @author Fabien Potencier <fabien.potencier@symfony-project.com>
21 * @version SVN: $Id: sfYamlDumper.class.php 10575 2008-08-01 13:08:42Z nicolas $
22 */
23 class sfYamlDumper
24 {
25 /**
26 * Dumps a PHP value to YAML.
27 *
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)
31 *
32 * @return string The YAML representation of the PHP value
33 */
34 public function dump($input, $inline = 0, $indent = 0)
35 {
36 $output = '';
37 $prefix = $indent ? str_repeat(' ', $indent) : '';
38
39 if ($inline <= 0 || !is_array($input) || empty($input))
40 {
41 $output .= $prefix.sfYamlInline::dump($input);
42 }
43 else
44 {
45 $isAHash = array_keys($input) !== range(0, count($input) - 1);
46
47 foreach ($input as $key => $value)
48 {
49 $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
50
51 $output .= sprintf('%s%s%s%s',
52 $prefix,
53 $isAHash ? sfYamlInline::dump($key).':' : '-',
54 $willBeInlined ? ' ' : "\n",
55 $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + 2)
56 ).($willBeInlined ? "\n" : '');
57 }
58 }
59
60 return $output;
61 }
62 }