ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Dumper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.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 
13 
19 class Dumper
20 {
26  protected $indentation;
27 
31  public function __construct($indentation = 4)
32  {
33  if ($indentation < 1) {
34  throw new \InvalidArgumentException('The indentation must be greater than zero.');
35  }
36 
37  $this->indentation = $indentation;
38  }
39 
45  public function setIndentation($num)
46  {
47  @trigger_error('The '.__METHOD__.' method is deprecated since version 3.1 and will be removed in 4.0. Pass the indentation to the constructor instead.', E_USER_DEPRECATED);
48 
49  $this->indentation = (int) $num;
50  }
51 
62  public function dump($input, $inline = 0, $indent = 0, $flags = 0)
63  {
64  if (is_bool($flags)) {
65  @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
66 
67  if ($flags) {
69  } else {
70  $flags = 0;
71  }
72  }
73 
74  if (func_num_args() >= 5) {
75  @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
76 
77  if (func_get_arg(4)) {
78  $flags |= Yaml::DUMP_OBJECT;
79  }
80  }
81 
82  $output = '';
83  $prefix = $indent ? str_repeat(' ', $indent) : '';
84 
85  if ($inline <= 0 || !is_array($input) || empty($input)) {
86  $output .= $prefix.Inline::dump($input, $flags);
87  } else {
88  $isAHash = Inline::isHash($input);
89 
90  foreach ($input as $key => $value) {
91  if ($inline > 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n")) {
92  $output .= sprintf("%s%s%s |\n", $prefix, $isAHash ? Inline::dump($key, $flags).':' : '-', '');
93 
94  foreach (preg_split('/\n|\r\n/', $value) as $row) {
95  $output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row);
96  }
97 
98  continue;
99  }
100 
101  $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
102 
103  $output .= sprintf('%s%s%s%s',
104  $prefix,
105  $isAHash ? Inline::dump($key, $flags).':' : '-',
106  $willBeInlined ? ' ' : "\n",
107  $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $flags)
108  ).($willBeInlined ? "\n" : '');
109  }
110  }
111 
112  return $output;
113  }
114 }
const DUMP_MULTI_LINE_LITERAL_BLOCK
Definition: Yaml.php:30
dump($input, $inline=0, $indent=0, $flags=0)
Dumps a PHP value to YAML.
Definition: Dumper.php:62
setIndentation($num)
Sets the indentation.
Definition: Dumper.php:45
static isHash(array $value)
Check if given array is hash or just normal indexed array.
Definition: Inline.php:226
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
static dump($value, $flags=0)
Dumps a given PHP variable to a YAML string.
Definition: Inline.php:128
__construct($indentation=4)
Definition: Dumper.php:31
Dumper dumps PHP variables to YAML strings.
Definition: Dumper.php:19
$key
Definition: croninfo.php:18
const DUMP_EXCEPTION_ON_INVALID_TYPE
Definition: Yaml.php:27