Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 54 lines (46 sloc) 1.639 kb
88d5c1b @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
1 <?php
2
3 namespace Symfony\Component\Yaml;
4
5 /*
6 * This file is part of the Symfony package.
7 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12
13 /**
14 * Dumper dumps PHP variables to YAML strings.
15 *
16 * @author Fabien Potencier <fabien.potencier@symfony-project.com>
17 */
18 class Dumper
19 {
20 /**
21 * Dumps a PHP value to YAML.
22 *
23 * @param mixed $input The PHP value
24 * @param integer $inline The level where you switch to inline YAML
25 * @param integer $indent The level o indentation indentation (used internally)
26 *
27 * @return string The YAML representation of the PHP value
28 */
29 public function dump($input, $inline = 0, $indent = 0)
30 {
31 $output = '';
32 $prefix = $indent ? str_repeat(' ', $indent) : '';
33
34 if ($inline <= 0 || !is_array($input) || empty($input)) {
35 $output .= $prefix.Inline::dump($input);
36 } else {
37 $isAHash = array_keys($input) !== range(0, count($input) - 1);
38
39 foreach ($input as $key => $value) {
40 $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
41
42 $output .= sprintf('%s%s%s%s',
43 $prefix,
44 $isAHash ? Inline::dump($key).':' : '-',
45 $willBeInlined ? ' ' : "\n",
46 $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + 2)
47 ).($willBeInlined ? "\n" : '');
48 }
49 }
50
51 return $output;
52 }
53 }
Something went wrong with that request. Please try again.