@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | private static function buildNodeList(NodeList $node, &$parent) |
| 45 | 45 | { |
| 46 | - if ($node->type & (Y::RAW | Y::LITTERALS)) { |
|
| 46 | + if ($node->type & (Y::RAW|Y::LITTERALS)) { |
|
| 47 | 47 | return self::buildLitteral($node, $node->type); |
| 48 | 48 | } |
| 49 | 49 | $p = $parent; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | case Y::MAPPING: // fall through |
| 52 | 52 | // case Y::SET_KEY: // fall through |
| 53 | 53 | case Y::SET: $p = new \StdClass; var_dump('in set'); break; |
| 54 | - case Y::SEQUENCE: $p = [];break; |
|
| 54 | + case Y::SEQUENCE: $p = []; break; |
|
| 55 | 55 | // case Y::KEY: $p = $parent;break; |
| 56 | 56 | } |
| 57 | 57 | $out = null; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | private static function buildNode(Node $node, &$parent) |
| 80 | 80 | { |
| 81 | 81 | extract((array) $node, EXTR_REFS); |
| 82 | - if ($type & (Y::REF_DEF | Y::REF_CALL)) { |
|
| 82 | + if ($type&(Y::REF_DEF|Y::REF_CALL)) { |
|
| 83 | 83 | if (is_object($value)) { |
| 84 | 84 | $tmp = self::build($value, $parent) ?? $parent; |
| 85 | 85 | } else { |
@@ -200,15 +200,15 @@ discard block |
||
| 200 | 200 | { |
| 201 | 201 | self::$_root = new YamlObject(); |
| 202 | 202 | $childTypes = $list->getTypes(); |
| 203 | - $isaMapping = (bool) (Y::KEY | Y::MAPPING) & $childTypes; |
|
| 203 | + $isaMapping = (bool) (Y::KEY|Y::MAPPING)&$childTypes; |
|
| 204 | 204 | $isaSequence = (bool) Y::ITEM & $childTypes; |
| 205 | 205 | $isaSet = (bool) Y::SET_VALUE & $childTypes; |
| 206 | 206 | if ($isaMapping && $isaSequence) { |
| 207 | 207 | throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key)); |
| 208 | 208 | } else { |
| 209 | 209 | switch (true) { |
| 210 | - case $isaSequence: $list->type = Y::SEQUENCE;break; |
|
| 211 | - case $isaSet: $list->type = Y::SET;break; |
|
| 210 | + case $isaSequence: $list->type = Y::SEQUENCE; break; |
|
| 211 | + case $isaSet: $list->type = Y::SET; break; |
|
| 212 | 212 | default: $list->type = Y::MAPPING; |
| 213 | 213 | } |
| 214 | 214 | } |
@@ -243,22 +243,22 @@ discard block |
||
| 243 | 243 | $lines[] = self::buildLitteral($child->value, $type); |
| 244 | 244 | } else { |
| 245 | 245 | $prefix = ''; |
| 246 | - if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
| 246 | + if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
| 247 | 247 | $prefix = "\n"; |
| 248 | 248 | } |
| 249 | 249 | if (!($child->type & (Y::SCALAR|Y::BLANK))) { |
| 250 | 250 | switch ($child->type) { |
| 251 | - case Y::ITEM: $child->value = '- '.$child->value;break; |
|
| 252 | - case Y::COMMENT: $child->value = '# '.$child->value;break; |
|
| 251 | + case Y::ITEM: $child->value = '- '.$child->value; break; |
|
| 252 | + case Y::COMMENT: $child->value = '# '.$child->value; break; |
|
| 253 | 253 | default: die(Y::getName($child->type)); |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | $lines[] = $prefix.$child->value; |
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | - if ($type & Y::RAW) return implode('', $lines); |
|
| 260 | - if ($type & Y::LITT) return implode("\n", $lines); |
|
| 261 | - if ($type & Y::LITT_FOLDED) return implode(' ', $lines); |
|
| 259 | + if ($type&Y::RAW) return implode('', $lines); |
|
| 260 | + if ($type&Y::LITT) return implode("\n", $lines); |
|
| 261 | + if ($type&Y::LITT_FOLDED) return implode(' ', $lines); |
|
| 262 | 262 | return ''; |
| 263 | 263 | } |
| 264 | 264 | |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | private function buildSetKey(Node $node, &$parent) |
| 274 | 274 | { |
| 275 | 275 | $built = self::build($node->value, $parent); |
| 276 | - $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
|
| 276 | + $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built; |
|
| 277 | 277 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 278 | 278 | if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
| 279 | 279 | $parent->{trim($key, '\'" ')} = null; |
@@ -18,17 +18,17 @@ discard block |
||
| 18 | 18 | /* @var null|string */ |
| 19 | 19 | public $error; |
| 20 | 20 | |
| 21 | - public const EXCLUDE_DIRECTIVES = 1;//DONT include_directive |
|
| 22 | - public const IGNORE_COMMENTS = 2;//DONT include_comments |
|
| 23 | - public const NO_PARSING_EXCEPTIONS = 4;//THROW Exception on parsing Errors |
|
| 24 | - public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
|
| 21 | + public const EXCLUDE_DIRECTIVES = 1; //DONT include_directive |
|
| 22 | + public const IGNORE_COMMENTS = 2; //DONT include_comments |
|
| 23 | + public const NO_PARSING_EXCEPTIONS = 4; //THROW Exception on parsing Errors |
|
| 24 | + public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object |
|
| 25 | 25 | //privates |
| 26 | 26 | /* @var null|string */ |
| 27 | 27 | private $content; |
| 28 | 28 | /* @var null|string */ |
| 29 | 29 | private $filePath; |
| 30 | 30 | /* @var integer */ |
| 31 | - private $debug = 0;///TODO: determine levels |
|
| 31 | + private $debug = 0; ///TODO: determine levels |
|
| 32 | 32 | /* @var integer */ |
| 33 | 33 | private $options = 0; |
| 34 | 34 | //Exceptions messages |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $previous = $root = new Node(); |
| 91 | 91 | $emptyLines = []; |
| 92 | 92 | try { |
| 93 | - $gen = function () use($source) { |
|
| 93 | + $gen = function() use($source) { |
|
| 94 | 94 | foreach ($source as $key => $value) { |
| 95 | 95 | yield ++$key => $value; |
| 96 | 96 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | break; |
| 110 | 110 | case 0: $target = $previous->getParent(); |
| 111 | 111 | break; |
| 112 | - default: $target = $previous->type & Y::ITEM && $n->type != Y::SET_VALUE? $previous->getDeepestNode()->getParent($n->indent) : $previous; |
|
| 112 | + default: $target = $previous->type & Y::ITEM && $n->type != Y::SET_VALUE ? $previous->getDeepestNode()->getParent($n->indent) : $previous; |
|
| 113 | 113 | } |
| 114 | 114 | if ($this->onContextType($n, $target, $lineString)) continue; |
| 115 | 115 | $target->add($n); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function add(Node $child) |
| 88 | 88 | { |
| 89 | - if($this->type & (Y::SCALAR|Y::QUOTED)) { |
|
| 89 | + if ($this->type & (Y::SCALAR|Y::QUOTED)) { |
|
| 90 | 90 | $this->getParent()->add($child); |
| 91 | 91 | return; |
| 92 | 92 | } |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | if (in_array($first, ['{', '['])) return $this->onObject($nodeValue); |
| 172 | 172 | if (in_array($first, ['!', '&', '*'])) return $this->onNodeAction($nodeValue); |
| 173 | 173 | // Note : php don't like '?' as an array key -_- |
| 174 | - if($first === '?') return [Y::SET_KEY, empty(trim($v)) ? null : new Node(ltrim($v), $this->line)]; |
|
| 175 | - $characters = [ '#' => [Y::COMMENT, ltrim($v)], |
|
| 174 | + if ($first === '?') return [Y::SET_KEY, empty(trim($v)) ? null : new Node(ltrim($v), $this->line)]; |
|
| 175 | + $characters = ['#' => [Y::COMMENT, ltrim($v)], |
|
| 176 | 176 | "-" => $this->onHyphen($nodeValue), |
| 177 | 177 | '%' => [Y::DIRECTIVE, ltrim($v)], |
| 178 | 178 | ':' => [Y::SET_VALUE, empty(trim($v)) ? null : new Node(ltrim($v), $this->line)], |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | { |
| 292 | 292 | $v = &$this->value; |
| 293 | 293 | if (is_null($v)) return null; |
| 294 | - if ($this->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($v); |
|
| 295 | - if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
| 294 | + if ($this->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar($v); |
|
| 295 | + if ($this->type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
| 296 | 296 | $expected = [Y::JSON => json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR), |
| 297 | 297 | Y::QUOTED => substr($v, 1, -1), |
| 298 | 298 | Y::RAW => strval($v)]; |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | //TODO : this should handle references present inside the string |
| 355 | 355 | $out = new Compact(); |
| 356 | 356 | if ($type === Y::COMPACT_SEQUENCE) { |
| 357 | - $f = function ($e) { return self::getScalar(trim($e));}; |
|
| 357 | + $f = function($e) { return self::getScalar(trim($e)); }; |
|
| 358 | 358 | //TODO : that's not robust enough, improve it |
| 359 | 359 | foreach (array_map($f, explode(",", $mappingOrSeqString)) as $key => $value) { |
| 360 | 360 | $out[$key] = $value; |
@@ -6,14 +6,14 @@ |
||
| 6 | 6 | /** |
| 7 | 7 | * Display some use cases for Yaml library |
| 8 | 8 | */ |
| 9 | -const JSON_OPTIONS = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_PARTIAL_OUTPUT_ON_ERROR; |
|
| 9 | +const JSON_OPTIONS = JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_LINE_TERMINATORS|JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION|JSON_PARTIAL_OUTPUT_ON_ERROR; |
|
| 10 | 10 | |
| 11 | 11 | /* USE CASE 1 |
| 12 | 12 | * load and parse if file exists |
| 13 | 13 | */ |
| 14 | 14 | ini_set("auto_detect_line_endings", 1); |
| 15 | 15 | // $yaml = Y::parseFile('./tests/cases/parsing/blockChompingWithInsideBlank.yml', null, 0); //->parse(); |
| 16 | -$content = file_get_contents('./tests/cases/parsing/complex_mapping_in_item.yml');//var_dump($content); |
|
| 16 | +$content = file_get_contents('./tests/cases/parsing/complex_mapping_in_item.yml'); //var_dump($content); |
|
| 17 | 17 | $yaml = Y::parse($content, null, 2); //->parse(); |
| 18 | 18 | // $yaml = Y::parseFile('./references/Example 2.27.yml', null, 1); |
| 19 | 19 | var_dump($yaml); |