@@ -19,17 +19,17 @@ discard block |
||
| 19 | 19 | /* @var null|string */ |
| 20 | 20 | public $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 |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $previous = $root = new Node(); |
| 92 | 92 | $emptyLines = []; |
| 93 | 93 | try { |
| 94 | - $gen = function () use($source) { |
|
| 94 | + $gen = function() use($source) { |
|
| 95 | 95 | foreach ($source as $key => $value) { |
| 96 | 96 | yield ++$key => $value; |
| 97 | 97 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $target->add($n); |
| 118 | 118 | $previous = $n; |
| 119 | 119 | } |
| 120 | - if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n",var_export($root, true); |
|
| 120 | + if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n", var_export($root, true); |
|
| 121 | 121 | $out = Builder::buildContent($root, $this->debug); |
| 122 | 122 | return $out; |
| 123 | 123 | } catch (\Error|\Exception|\ParseError $e) { |
@@ -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)) { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | $this->value->push($child); |
| 96 | 96 | //modify type according to child |
| 97 | - if ($child->type & (Y::COMMENT | Y::KEY)) $this->value->type = Y::MAPPING; |
|
| 97 | + if ($child->type & (Y::COMMENT|Y::KEY)) $this->value->type = Y::MAPPING; |
|
| 98 | 98 | if ($child->type & Y::ITEM) $this->value->type = Y::SEQUENCE; |
| 99 | 99 | if ($this->type & Y::LITTERALS) $this->value->type = $this->type; |
| 100 | 100 | } |
@@ -158,8 +158,8 @@ discard block |
||
| 158 | 158 | if (in_array($first, ['{', '['])) return $this->onObject($nodeValue); |
| 159 | 159 | if (in_array($first, ['!', '&', '*'])) return $this->onNodeAction($nodeValue); |
| 160 | 160 | // Note : php don't like '?' as an array key -_- |
| 161 | - if($first === '?') return [Y::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
| 162 | - $characters = [ '#' => [Y::COMMENT, ltrim($v)], |
|
| 161 | + if ($first === '?') return [Y::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
| 162 | + $characters = ['#' => [Y::COMMENT, ltrim($v)], |
|
| 163 | 163 | "-" => $this->onHyphen($nodeValue), |
| 164 | 164 | '%' => [Y::DIRECTIVE, ltrim($v)], |
| 165 | 165 | ':' => [Y::SET_VALUE, empty($v) ? null : new Node(ltrim($v), $this->line)], |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | { |
| 278 | 278 | $v = &$this->value; |
| 279 | 279 | if (is_null($v)) return null; |
| 280 | - if ($this->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($v); |
|
| 281 | - if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
| 280 | + if ($this->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar($v); |
|
| 281 | + if ($this->type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
| 282 | 282 | $expected = [Y::JSON => json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR), |
| 283 | 283 | Y::QUOTED => substr($v, 1, -1), |
| 284 | 284 | Y::RAW => strval($v)]; |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | //TODO : this should handle references present inside the string |
| 341 | 341 | $out = new Compact(); |
| 342 | 342 | if ($type === Y::COMPACT_SEQUENCE) { |
| 343 | - $f = function ($e) { return self::getScalar(trim($e));}; |
|
| 343 | + $f = function($e) { return self::getScalar(trim($e)); }; |
|
| 344 | 344 | //TODO : that's not robust enough, improve it |
| 345 | 345 | foreach (array_map($f, explode(",", $mappingOrSeqString)) as $key => $value) { |
| 346 | 346 | $out[$key] = $value; |
@@ -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 | // case Y::KEY: $p = $parent;break; |
| 55 | 55 | } |
| 56 | 56 | $out = null; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | private static function buildNode(Node $node, &$parent) |
| 79 | 79 | { |
| 80 | 80 | extract((array) $node, EXTR_REFS); |
| 81 | - if ($type & (Y::REF_DEF | Y::REF_CALL)) { |
|
| 81 | + if ($type&(Y::REF_DEF|Y::REF_CALL)) { |
|
| 82 | 82 | if (is_object($value)) { |
| 83 | 83 | $tmp = self::build($value, $parent) ?? $parent; |
| 84 | 84 | } else { |
@@ -193,15 +193,15 @@ discard block |
||
| 193 | 193 | { |
| 194 | 194 | self::$_root = new YamlObject(); |
| 195 | 195 | $childTypes = $list->getTypes(); |
| 196 | - $isaMapping = (bool) (Y::KEY | Y::MAPPING) & $childTypes; |
|
| 196 | + $isaMapping = (bool) (Y::KEY|Y::MAPPING)&$childTypes; |
|
| 197 | 197 | $isaSequence = (bool) Y::ITEM & $childTypes; |
| 198 | 198 | $isaSet = (bool) Y::SET_VALUE & $childTypes; |
| 199 | 199 | if ($isaMapping && $isaSequence) { |
| 200 | 200 | throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key)); |
| 201 | 201 | } else { |
| 202 | 202 | switch (true) { |
| 203 | - case $isaSequence: $list->type = Y::SEQUENCE;break; |
|
| 204 | - case $isaSet: $list->type = Y::SET;break; |
|
| 203 | + case $isaSequence: $list->type = Y::SEQUENCE; break; |
|
| 204 | + case $isaSet: $list->type = Y::SET; break; |
|
| 205 | 205 | default: $list->type = Y::MAPPING; |
| 206 | 206 | } |
| 207 | 207 | } |
@@ -236,15 +236,15 @@ discard block |
||
| 236 | 236 | $lines[] = self::buildLitteral($child->value, $type); |
| 237 | 237 | } else { |
| 238 | 238 | $prefix = ''; |
| 239 | - if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
| 239 | + if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
| 240 | 240 | $prefix = "\n"; |
| 241 | 241 | } |
| 242 | 242 | $lines[] = $prefix.$child->value; |
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | - if ($type & Y::RAW) return implode('', $lines); |
|
| 246 | - if ($type & Y::LITT) return implode("\n", $lines); |
|
| 247 | - if ($type & Y::LITT_FOLDED) return implode(' ', $lines); |
|
| 245 | + if ($type&Y::RAW) return implode('', $lines); |
|
| 246 | + if ($type&Y::LITT) return implode("\n", $lines); |
|
| 247 | + if ($type&Y::LITT_FOLDED) return implode(' ', $lines); |
|
| 248 | 248 | return ''; |
| 249 | 249 | } |
| 250 | 250 | |