comparison vendor/symfony/yaml/Dumper.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 1fec387a4317
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
39 39
40 /** 40 /**
41 * Sets the indentation. 41 * Sets the indentation.
42 * 42 *
43 * @param int $num The amount of spaces to use for indentation of nested nodes 43 * @param int $num The amount of spaces to use for indentation of nested nodes
44 *
45 * @deprecated since version 3.1, to be removed in 4.0. Pass the indentation to the constructor instead.
44 */ 46 */
45 public function setIndentation($num) 47 public function setIndentation($num)
46 { 48 {
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); 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);
48 50
79 } 81 }
80 } 82 }
81 83
82 $output = ''; 84 $output = '';
83 $prefix = $indent ? str_repeat(' ', $indent) : ''; 85 $prefix = $indent ? str_repeat(' ', $indent) : '';
86 $dumpObjectAsInlineMap = true;
84 87
85 if ($inline <= 0 || !is_array($input) || empty($input)) { 88 if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($input instanceof \ArrayObject || $input instanceof \stdClass)) {
89 $dumpObjectAsInlineMap = empty((array) $input);
90 }
91
92 if ($inline <= 0 || (!is_array($input) && $dumpObjectAsInlineMap) || empty($input)) {
86 $output .= $prefix.Inline::dump($input, $flags); 93 $output .= $prefix.Inline::dump($input, $flags);
87 } else { 94 } else {
88 $isAHash = Inline::isHash($input); 95 $dumpAsMap = Inline::isHash($input);
89 96
90 foreach ($input as $key => $value) { 97 foreach ($input as $key => $value) {
91 if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n")) { 98 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).':' : '-', ''); 99 $output .= sprintf("%s%s%s |\n", $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '');
93 100
94 foreach (preg_split('/\n|\r\n/', $value) as $row) { 101 foreach (preg_split('/\n|\r\n/', $value) as $row) {
95 $output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row); 102 $output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row);
96 } 103 }
97 104
98 continue; 105 continue;
99 } 106 }
100 107
101 $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value); 108 $dumpObjectAsInlineMap = true;
109
110 if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \ArrayObject || $value instanceof \stdClass)) {
111 $dumpObjectAsInlineMap = empty((array) $value);
112 }
113
114 $willBeInlined = $inline - 1 <= 0 || !is_array($value) && $dumpObjectAsInlineMap || empty($value);
102 115
103 $output .= sprintf('%s%s%s%s', 116 $output .= sprintf('%s%s%s%s',
104 $prefix, 117 $prefix,
105 $isAHash ? Inline::dump($key, $flags).':' : '-', 118 $dumpAsMap ? Inline::dump($key, $flags).':' : '-',
106 $willBeInlined ? ' ' : "\n", 119 $willBeInlined ? ' ' : "\n",
107 $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $flags) 120 $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $flags)
108 ).($willBeInlined ? "\n" : ''); 121 ).($willBeInlined ? "\n" : '');
109 } 122 }
110 } 123 }