/[web]/fidd/lib/fabpot-yaml/lib/sfYamlDumper.php
ViewVC logotype

Contents of /fidd/lib/fabpot-yaml/lib/sfYamlDumper.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1081 - (show annotations) (download)
Mon May 14 09:16:32 2012 UTC (11 years, 11 months ago) by rda
File size: 1692 byte(s)
add library and var dir
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 require_once(dirname(__FILE__).'/sfYamlInline.php');
12
13 /**
14 * sfYamlDumper dumps PHP variables to YAML strings.
15 *
16 * @package symfony
17 * @subpackage yaml
18 * @author Fabien Potencier <fabien.potencier@symfony-project.com>
19 * @version SVN: $Id: sfYamlDumper.class.php 10575 2008-08-01 13:08:42Z nicolas $
20 */
21 class sfYamlDumper
22 {
23 /**
24 * Dumps a PHP value to YAML.
25 *
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)
29 *
30 * @return string The YAML representation of the PHP value
31 */
32 public function dump($input, $inline = 0, $indent = 0)
33 {
34 $output = '';
35 $prefix = $indent ? str_repeat(' ', $indent) : '';
36
37 if ($inline <= 0 || !is_array($input) || empty($input))
38 {
39 $output .= $prefix.sfYamlInline::dump($input);
40 }
41 else
42 {
43 $isAHash = array_keys($input) !== range(0, count($input) - 1);
44
45 foreach ($input as $key => $value)
46 {
47 $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
48
49 $output .= sprintf('%s%s%s%s',
50 $prefix,
51 $isAHash ? sfYamlInline::dump($key).':' : '-',
52 $willBeInlined ? ' ' : "\n",
53 $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + 2)
54 ).($willBeInlined ? "\n" : '');
55 }
56 }
57
58 return $output;
59 }
60 }

  ViewVC Help
Powered by ViewVC 1.1.30