comparison vendor/symfony/yaml/Dumper.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 7a779792577d
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
13 13
14 /** 14 /**
15 * Dumper dumps PHP variables to YAML strings. 15 * Dumper dumps PHP variables to YAML strings.
16 * 16 *
17 * @author Fabien Potencier <fabien@symfony.com> 17 * @author Fabien Potencier <fabien@symfony.com>
18 *
19 * @final since version 3.4
18 */ 20 */
19 class Dumper 21 class Dumper
20 { 22 {
21 /** 23 /**
22 * The amount of spaces to use for indentation of nested nodes. 24 * The amount of spaces to use for indentation of nested nodes.
44 * 46 *
45 * @deprecated since version 3.1, to be removed in 4.0. Pass the indentation to the constructor instead. 47 * @deprecated since version 3.1, to be removed in 4.0. Pass the indentation to the constructor instead.
46 */ 48 */
47 public function setIndentation($num) 49 public function setIndentation($num)
48 { 50 {
49 @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); 51 @trigger_error('The '.__METHOD__.' method is deprecated since Symfony 3.1 and will be removed in 4.0. Pass the indentation to the constructor instead.', E_USER_DEPRECATED);
50 52
51 $this->indentation = (int) $num; 53 $this->indentation = (int) $num;
52 } 54 }
53 55
54 /** 56 /**
62 * @return string The YAML representation of the PHP value 64 * @return string The YAML representation of the PHP value
63 */ 65 */
64 public function dump($input, $inline = 0, $indent = 0, $flags = 0) 66 public function dump($input, $inline = 0, $indent = 0, $flags = 0)
65 { 67 {
66 if (is_bool($flags)) { 68 if (is_bool($flags)) {
67 @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); 69 @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
68 70
69 if ($flags) { 71 if ($flags) {
70 $flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE; 72 $flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE;
71 } else { 73 } else {
72 $flags = 0; 74 $flags = 0;
73 } 75 }
74 } 76 }
75 77
76 if (func_num_args() >= 5) { 78 if (func_num_args() >= 5) {
77 @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); 79 @trigger_error('Passing a boolean flag to toggle object support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
78 80
79 if (func_get_arg(4)) { 81 if (func_get_arg(4)) {
80 $flags |= Yaml::DUMP_OBJECT; 82 $flags |= Yaml::DUMP_OBJECT;
81 } 83 }
82 } 84 }
93 $output .= $prefix.Inline::dump($input, $flags); 95 $output .= $prefix.Inline::dump($input, $flags);
94 } else { 96 } else {
95 $dumpAsMap = Inline::isHash($input); 97 $dumpAsMap = Inline::isHash($input);
96 98
97 foreach ($input as $key => $value) { 99 foreach ($input as $key => $value) {
98 if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n")) { 100 if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r\n")) {
99 $output .= sprintf("%s%s%s |\n", $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', ''); 101 // If the first line starts with a space character, the spec requires a blockIndicationIndicator
102 // http://www.yaml.org/spec/1.2/spec.html#id2793979
103 $blockIndentationIndicator = (' ' === substr($value, 0, 1)) ? (string) $this->indentation : '';
104 $output .= sprintf("%s%s%s |%s\n", $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '', $blockIndentationIndicator);
100 105
101 foreach (preg_split('/\n|\r\n/', $value) as $row) { 106 foreach (preg_split('/\n|\r\n/', $value) as $row) {
102 $output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row); 107 $output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row);
103 } 108 }
104 109