ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Symfony\Component\Yaml\Dumper Class Reference

Dumper dumps PHP variables to YAML strings. More...

+ Collaboration diagram for Symfony\Component\Yaml\Dumper:

Public Member Functions

 __construct ($indentation=4)
 
 setIndentation ($num)
 Sets the indentation. More...
 
 dump ($input, $inline=0, $indent=0, $flags=0)
 Dumps a PHP value to YAML. More...
 

Protected Attributes

 $indentation
 

Detailed Description

Dumper dumps PHP variables to YAML strings.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 19 of file Dumper.php.

Constructor & Destructor Documentation

◆ __construct()

Symfony\Component\Yaml\Dumper::__construct (   $indentation = 4)
Parameters
int$indentation

Definition at line 31 of file Dumper.php.

References Symfony\Component\Yaml\Dumper\$indentation.

32  {
33  if ($indentation < 1) {
34  throw new \InvalidArgumentException('The indentation must be greater than zero.');
35  }
36 
37  $this->indentation = $indentation;
38  }

Member Function Documentation

◆ dump()

Symfony\Component\Yaml\Dumper::dump (   $input,
  $inline = 0,
  $indent = 0,
  $flags = 0 
)

Dumps a PHP value to YAML.

Parameters
mixed$inputThe PHP value
int$inlineThe level where you switch to inline YAML
int$indentThe level of indentation (used internally)
int$flagsA bit field of Yaml::DUMP_* constants to customize the dumped YAML string
Returns
string The YAML representation of the PHP value

Definition at line 62 of file Dumper.php.

References $output, $row, Symfony\Component\Yaml\Inline\dump(), Symfony\Component\Yaml\Yaml\DUMP_EXCEPTION_ON_INVALID_TYPE, Symfony\Component\Yaml\Yaml\DUMP_MULTI_LINE_LITERAL_BLOCK, Symfony\Component\Yaml\Yaml\DUMP_OBJECT, and Symfony\Component\Yaml\Inline\isHash().

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  }
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
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
const DUMP_EXCEPTION_ON_INVALID_TYPE
Definition: Yaml.php:27
+ Here is the call graph for this function:

◆ setIndentation()

Symfony\Component\Yaml\Dumper::setIndentation (   $num)

Sets the indentation.

Parameters
int$numThe amount of spaces to use for indentation of nested nodes

Definition at line 45 of file Dumper.php.

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  }

Field Documentation

◆ $indentation

Symfony\Component\Yaml\Dumper::$indentation
protected

Definition at line 26 of file Dumper.php.

Referenced by Symfony\Component\Yaml\Dumper\__construct().


The documentation for this class was generated from the following file: