@@ -32,7 +32,7 @@ |
||
| 32 | 32 | public function __call($funcName, $arguments) |
| 33 | 33 | { |
| 34 | 34 | $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api)); |
| 35 | - $getName = function ($o) { return $o->name; }; |
|
| 35 | + $getName = function($o) { return $o->name; }; |
|
| 36 | 36 | $publicApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC)); |
| 37 | 37 | $privateApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PRIVATE)); |
| 38 | 38 | if (!in_array($funcName, $publicApi) && !in_array($funcName, $privateApi)) { |
@@ -159,10 +159,10 @@ |
||
| 159 | 159 | if (is_array($subject) || $subject instanceof \Countable) { |
| 160 | 160 | $max = count($subject); |
| 161 | 161 | $objectAsArray = is_array($subject) ? $subject : $subject->getArrayCopy(); |
| 162 | - if(array_keys($objectAsArray) !== range(0, $max)) { |
|
| 162 | + if (array_keys($objectAsArray) !== range(0, $max)) { |
|
| 163 | 163 | $pairs = $objectAsArray; |
| 164 | 164 | } else { |
| 165 | - $valuesList = array_map([self, 'dump'], $objectAsArray, array_fill( 0 , $max , $indent )); |
|
| 165 | + $valuesList = array_map([self, 'dump'], $objectAsArray, array_fill(0, $max, $indent)); |
|
| 166 | 166 | return '['.implode(', ', $valuesList).']'; |
| 167 | 167 | } |
| 168 | 168 | } else { |
@@ -43,14 +43,14 @@ 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; |
| 50 | 50 | switch ($node->type) { |
| 51 | 51 | case Y::MAPPING: // fall through |
| 52 | 52 | case Y::SET: $p = new \StdClass; break; |
| 53 | - case Y::SEQUENCE: $p = [];break; |
|
| 53 | + case Y::SEQUENCE: $p = []; break; |
|
| 54 | 54 | } |
| 55 | 55 | $out = null; |
| 56 | 56 | foreach ($node as $child) { |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | private static function buildNode(Node $node, &$parent) |
| 78 | 78 | { |
| 79 | 79 | extract((array) $node, EXTR_REFS); |
| 80 | - if ($type & (Y::REF_DEF | Y::REF_CALL)) { |
|
| 80 | + if ($type&(Y::REF_DEF|Y::REF_CALL)) { |
|
| 81 | 81 | if (is_object($value)) { |
| 82 | 82 | $tmp = self::build($value, $parent) ?? $parent; |
| 83 | 83 | } else { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | return self::$_root->getReference($identifier); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value); |
|
| 90 | + if ($type&Y::COMMENT) self::$_root->addComment($node->line, $node->value); |
|
| 91 | 91 | $typesActions = [Y::DIRECTIVE => 'buildDirective', |
| 92 | 92 | Y::ITEM => 'buildItem', |
| 93 | 93 | Y::KEY => 'buildKey', |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $target = $value->type & Y::ITEM ? [] : new \StdClass; |
| 126 | 126 | self::build($value, $target); |
| 127 | 127 | } elseif (is_object($value)) { |
| 128 | - if (is_null($value->type) && $value->getTypes() & Y::SCALAR && !($value->getTypes() & Y::COMMENT)) { |
|
| 128 | + if (is_null($value->type) && $value->getTypes()&Y::SCALAR && !($value->getTypes()&Y::COMMENT)) { |
|
| 129 | 129 | $target = self::buildLitteral($value, Y::LITT_FOLDED); |
| 130 | 130 | } else { |
| 131 | 131 | $target = self::build($value, $target); |
@@ -203,15 +203,15 @@ discard block |
||
| 203 | 203 | { |
| 204 | 204 | self::$_root = new YamlObject(); |
| 205 | 205 | $childTypes = $list->getTypes(); |
| 206 | - $isaMapping = (bool) (Y::KEY | Y::MAPPING) & $childTypes; |
|
| 206 | + $isaMapping = (bool) (Y::KEY|Y::MAPPING)&$childTypes; |
|
| 207 | 207 | $isaSequence = (bool) Y::ITEM & $childTypes; |
| 208 | 208 | $isaSet = (bool) Y::SET_VALUE & $childTypes; |
| 209 | 209 | if ($isaMapping && $isaSequence) { |
| 210 | 210 | throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key)); |
| 211 | 211 | } else { |
| 212 | 212 | switch (true) { |
| 213 | - case $isaSequence: $list->type = Y::SEQUENCE;break; |
|
| 214 | - case $isaSet: $list->type = Y::SET;break; |
|
| 213 | + case $isaSequence: $list->type = Y::SEQUENCE; break; |
|
| 214 | + case $isaSet: $list->type = Y::SET; break; |
|
| 215 | 215 | default: $list->type = Y::MAPPING; |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -262,13 +262,13 @@ discard block |
||
| 262 | 262 | $lines[] = self::buildLitteral($child->value, $type); |
| 263 | 263 | } else { |
| 264 | 264 | $prefix = ''; |
| 265 | - if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
| 265 | + if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
| 266 | 266 | $prefix = "\n"; |
| 267 | 267 | } |
| 268 | 268 | if (!($child->type & (Y::SCALAR|Y::BLANK))) { |
| 269 | 269 | switch ($child->type) { |
| 270 | - case Y::ITEM: $child->value = '- '.$child->value;break; |
|
| 271 | - case Y::COMMENT: $child->value = '# '.$child->value;break; |
|
| 270 | + case Y::ITEM: $child->value = '- '.$child->value; break; |
|
| 271 | + case Y::COMMENT: $child->value = '# '.$child->value; break; |
|
| 272 | 272 | default: //die(__METHOD__.Y::getName($child->type)); |
| 273 | 273 | } |
| 274 | 274 | } |
@@ -280,9 +280,9 @@ discard block |
||
| 280 | 280 | $lines[] = $prefix.$child->value; |
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | - if ($type & Y::RAW) return implode('', $lines); |
|
| 284 | - if ($type & Y::LITT) return implode("\n", $lines); |
|
| 285 | - if ($type & Y::LITT_FOLDED) return preg_replace(['/ +(\n)/','/(\n+) +/'], "$1", implode(' ', $lines)); |
|
| 283 | + if ($type&Y::RAW) return implode('', $lines); |
|
| 284 | + if ($type&Y::LITT) return implode("\n", $lines); |
|
| 285 | + if ($type&Y::LITT_FOLDED) return preg_replace(['/ +(\n)/', '/(\n+) +/'], "$1", implode(' ', $lines)); |
|
| 286 | 286 | return ''; |
| 287 | 287 | } |
| 288 | 288 | |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | private function buildSetKey(Node $node, &$parent) |
| 298 | 298 | { |
| 299 | 299 | $built = self::build($node->value, $parent); |
| 300 | - $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
|
| 300 | + $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built; |
|
| 301 | 301 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 302 | 302 | // if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
| 303 | 303 | $parent->{trim($key, '\'" ')} = null; |
@@ -19,17 +19,17 @@ discard block |
||
| 19 | 19 | /* @var null|string */ |
| 20 | 20 | public static $error; |
| 21 | 21 | |
| 22 | - public const EXCLUDE_DIRECTIVES = 1;//DONT include_directive |
|
| 23 | - public const IGNORE_COMMENTS = 2;//DONT include_comments |
|
| 24 | - public const NO_PARSING_EXCEPTIONS = 4;//THROW Exception on parsing Errors |
|
| 25 | - public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
|
| 22 | + public const EXCLUDE_DIRECTIVES = 1; //DONT include_directive |
|
| 23 | + public const IGNORE_COMMENTS = 2; //DONT include_comments |
|
| 24 | + public const NO_PARSING_EXCEPTIONS = 4; //THROW Exception on parsing Errors |
|
| 25 | + public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object |
|
| 26 | 26 | //privates |
| 27 | 27 | /* @var null|string */ |
| 28 | 28 | private $content; |
| 29 | 29 | /* @var null|string */ |
| 30 | 30 | private $filePath; |
| 31 | 31 | /* @var integer */ |
| 32 | - private $debug = 0;///TODO: determine levels |
|
| 32 | + private $debug = 0; ///TODO: determine levels |
|
| 33 | 33 | /* @var integer */ |
| 34 | 34 | private $options = 0; |
| 35 | 35 | //Exceptions messages |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | $previous = $root = new Node(); |
| 93 | 93 | $emptyLines = []; |
| 94 | 94 | try { //var_dump($source); |
| 95 | - $gen = function () use($source) { |
|
| 95 | + $gen = function() use($source) { |
|
| 96 | 96 | foreach ($source as $key => $value) { |
| 97 | 97 | yield ++$key => $value; |
| 98 | 98 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | case 0: |
| 120 | 120 | if ($n->type & Y::KEY && $n->indent === 0) { |
| 121 | 121 | $target = $root; |
| 122 | - } elseif($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) { |
|
| 122 | + } elseif ($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) { |
|
| 123 | 123 | $target = $deepest; |
| 124 | 124 | } else { |
| 125 | 125 | $target = $previous->getParent(); |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | return; |
| 187 | 187 | } |
| 188 | 188 | // Note : php don't like '?' as an array key -_-' |
| 189 | - if(in_array($first, ['?', ':'])) { |
|
| 189 | + if (in_array($first, ['?', ':'])) { |
|
| 190 | 190 | $this->type = $first === '?' ? Y::SET_KEY : Y::SET_VALUE; |
| 191 | 191 | if (!empty(trim($v))) { |
| 192 | 192 | $this->value = new NodeList; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $this->onHyphen($nodeValue); |
| 199 | 199 | return; |
| 200 | 200 | } |
| 201 | - $characters = [ '#' => [Y::COMMENT, ltrim($v)], |
|
| 201 | + $characters = ['#' => [Y::COMMENT, ltrim($v)], |
|
| 202 | 202 | '%' => [Y::DIRECTIVE, ltrim($v)], |
| 203 | 203 | '>' => [Y::LITT_FOLDED, null], |
| 204 | 204 | '|' => [Y::LITT, null] |
@@ -251,15 +251,15 @@ discard block |
||
| 251 | 251 | { |
| 252 | 252 | $this->value = $value; |
| 253 | 253 | json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 254 | - if (json_last_error() === JSON_ERROR_NONE){ |
|
| 254 | + if (json_last_error() === JSON_ERROR_NONE) { |
|
| 255 | 255 | $this->type = Y::JSON; |
| 256 | 256 | return; |
| 257 | 257 | } |
| 258 | - if (preg_match(R::MAPPING, $value)){ |
|
| 258 | + if (preg_match(R::MAPPING, $value)) { |
|
| 259 | 259 | $this->type = Y::COMPACT_MAPPING; |
| 260 | 260 | return; |
| 261 | 261 | } |
| 262 | - if (preg_match(R::SEQUENCE, $value)){ |
|
| 262 | + if (preg_match(R::SEQUENCE, $value)) { |
|
| 263 | 263 | $this->type = Y::COMPACT_SEQUENCE; |
| 264 | 264 | return; |
| 265 | 265 | } |
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | public static function get(Node $n) |
| 23 | 23 | { |
| 24 | 24 | if (is_null($n->value)) return null; |
| 25 | - if ($n->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($n->value); |
|
| 26 | - if ($n->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) |
|
| 25 | + if ($n->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar($n->value); |
|
| 26 | + if ($n->type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) |
|
| 27 | 27 | return self::getCompact(substr($n->value, 1, -1), $n->type); |
| 28 | 28 | $expected = [Y::JSON => json_decode($n->value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR), |
| 29 | 29 | Y::QUOTED => trim($n->value, "\"'"), |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | //TODO : this should handle references present inside the string |
| 82 | 82 | $out = new Compact(); |
| 83 | 83 | if ($type === Y::COMPACT_SEQUENCE) { |
| 84 | - $f = function ($e) { return self::getScalar(trim($e));}; |
|
| 84 | + $f = function($e) { return self::getScalar(trim($e)); }; |
|
| 85 | 85 | //TODO : that's not robust enough, improve it |
| 86 | 86 | foreach (array_map($f, explode(",", $mappingOrSeqString)) as $key => $value) { |
| 87 | 87 | $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/tags_in_compact.yml');//var_dump($content); |
|
| 16 | +$content = file_get_contents('./tests/cases/parsing/tags_in_compact.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); |