Skip to content

HTTPS clone URL

Subversion checkout URL

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