Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 71 lines (62 sloc) 1.984 kb
88d5c1b8 » fabpot
2010-08-20 renamed Symfony\Components to Symfony\Component
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
1d318206 » blue-eyes
2011-01-15 normalized license messages in PHP files
5 *
687f8a73 » fabpot
2011-03-06 replaced symfony-project.org by symfony.com
6 * (c) Fabien Potencier <fabien@symfony.com>
88d5c1b8 » fabpot
2010-08-20 renamed Symfony\Components to Symfony\Component
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
1d318206 » blue-eyes
2011-01-15 normalized license messages in PHP files
12 namespace Symfony\Component\Yaml;
13
88d5c1b8 » fabpot
2010-08-20 renamed Symfony\Components to Symfony\Component
14 /**
15 * Dumper dumps PHP variables to YAML strings.
16 *
687f8a73 » fabpot
2011-03-06 replaced symfony-project.org by symfony.com
17 * @author Fabien Potencier <fabien@symfony.com>
88d5c1b8 » fabpot
2010-08-20 renamed Symfony\Components to Symfony\Component
18 */
19 class Dumper
20 {
21 /**
a1297556 » sun
2012-08-05 Added Yaml\Dumper::setIndentation() method to allow a custom indentat…
22 * The amount of spaces to use for indentation of nested nodes.
23 *
24 * @var integer
25 */
26 protected $indentation = 4;
27
28 /**
29 * Sets the indentation.
30 *
31 * @param integer $num The amount of spaces to use for intendation of nested nodes.
32 */
33 public function setIndentation($num)
34 {
6b3eb66a » sun
2012-08-07 Force the value of Dumper::setIndentation($num) to be of type integer.
35 $this->indentation = (int) $num;
a1297556 » sun
2012-08-05 Added Yaml\Dumper::setIndentation() method to allow a custom indentat…
36 }
37
38 /**
88d5c1b8 » fabpot
2010-08-20 renamed Symfony\Components to Symfony\Component
39 * Dumps a PHP value to YAML.
40 *
e84e6373 » fabpot
2012-05-15 fixed phpdoc @param alignment
41 * @param mixed $input The PHP value
42 * @param integer $inline The level where you switch to inline YAML
43 * @param integer $indent The level of indentation (used internally)
88d5c1b8 » fabpot
2010-08-20 renamed Symfony\Components to Symfony\Component
44 *
45 * @return string The YAML representation of the PHP value
46 */
47 public function dump($input, $inline = 0, $indent = 0)
48 {
49 $output = '';
50 $prefix = $indent ? str_repeat(' ', $indent) : '';
51
52 if ($inline <= 0 || !is_array($input) || empty($input)) {
53 $output .= $prefix.Inline::dump($input);
54 } else {
55 $isAHash = array_keys($input) !== range(0, count($input) - 1);
56
57 foreach ($input as $key => $value) {
58 $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
59
60 $output .= sprintf('%s%s%s%s',
61 $prefix,
62 $isAHash ? Inline::dump($key).':' : '-',
63 $willBeInlined ? ' ' : "\n",
a1297556 » sun
2012-08-05 Added Yaml\Dumper::setIndentation() method to allow a custom indentat…
64 $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation)
88d5c1b8 » fabpot
2010-08-20 renamed Symfony\Components to Symfony\Component
65 ).($willBeInlined ? "\n" : '');
66 }
67 }
68
69 return $output;
70 }
71 }
Something went wrong with that request. Please try again.