Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 74 lines (64 sloc) 2.452 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 *
687f8a7 @fabpot replaced symfony-project.org by symfony.com
fabpot authored
6 * (c) Fabien Potencier <fabien@symfony.com>
88d5c1b @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
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 *
687f8a7 @fabpot replaced symfony-project.org by symfony.com
fabpot authored
17 * @author Fabien Potencier <fabien@symfony.com>
88d5c1b @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
18 */
19 class Dumper
20 {
21 /**
a129755 @sun Added Yaml\Dumper::setIndentation() method to allow a custom indentat…
sun authored
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 *
c91b7a6 @pborreli Fixed typos
pborreli authored
31 * @param integer $num The amount of spaces to use for indentation of nested nodes.
a129755 @sun Added Yaml\Dumper::setIndentation() method to allow a custom indentat…
sun authored
32 */
33 public function setIndentation($num)
34 {
6b3eb66 @sun Force the value of Dumper::setIndentation($num) to be of type integer.
sun authored
35 $this->indentation = (int) $num;
a129755 @sun Added Yaml\Dumper::setIndentation() method to allow a custom indentat…
sun authored
36 }
37
38 /**
88d5c1b @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
39 * Dumps a PHP value to YAML.
40 *
9ac8f42 @fabpot added a way to enable/disable object support when parsing/dumping
fabpot authored
41 * @param mixed $input The PHP value
42 * @param integer $inline The level where you switch to inline YAML
67069f6 @fabpot [Yaml] fixed unneeded BC break
fabpot authored
43 * @param integer $indent The level of indentation (used internally)
9ac8f42 @fabpot added a way to enable/disable object support when parsing/dumping
fabpot authored
44 * @param Boolean $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
45 * @param Boolean $objectSupport true if object support is enabled, false otherwise
88d5c1b @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
46 *
47 * @return string The YAML representation of the PHP value
48 */
67069f6 @fabpot [Yaml] fixed unneeded BC break
fabpot authored
49 public function dump($input, $inline = 0, $indent = 0, $exceptionOnInvalidType = false, $objectSupport = false)
88d5c1b @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
50 {
51 $output = '';
52 $prefix = $indent ? str_repeat(' ', $indent) : '';
53
54 if ($inline <= 0 || !is_array($input) || empty($input)) {
9ac8f42 @fabpot added a way to enable/disable object support when parsing/dumping
fabpot authored
55 $output .= $prefix.Inline::dump($input, $exceptionOnInvalidType, $objectSupport);
88d5c1b @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
56 } else {
57 $isAHash = array_keys($input) !== range(0, count($input) - 1);
58
59 foreach ($input as $key => $value) {
60 $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
61
62 $output .= sprintf('%s%s%s%s',
63 $prefix,
9ac8f42 @fabpot added a way to enable/disable object support when parsing/dumping
fabpot authored
64 $isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport).':' : '-',
88d5c1b @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
65 $willBeInlined ? ' ' : "\n",
67069f6 @fabpot [Yaml] fixed unneeded BC break
fabpot authored
66 $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $exceptionOnInvalidType, $objectSupport)
88d5c1b @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
67 ).($willBeInlined ? "\n" : '');
68 }
69 }
70
71 return $output;
72 }
73 }
Something went wrong with that request. Please try again.