@@ -16,7 +16,7 @@ |
||
| 16 | 16 | if (is_null($tagName)) { |
| 17 | 17 | throw new \Exception(self::class.": a tag MUST have a name", 1); |
| 18 | 18 | } |
| 19 | - $this->tagName = $tagName; |
|
| 19 | + $this->tagName = $tagName; |
|
| 20 | 20 | $this->value = $value; |
| 21 | 21 | } |
| 22 | 22 | |
@@ -14,10 +14,10 @@ discard block |
||
| 14 | 14 | const AN = "[\w ]+"; |
| 15 | 15 | const NUM = "-?[\d.e]+"; |
| 16 | 16 | const SIMPLE = "(?P<sv>".self::NULL."|". |
| 17 | - self::FALSE."|". |
|
| 18 | - self::TRUE."|". |
|
| 19 | - self::AN."|". |
|
| 20 | - self::NUM.")"; |
|
| 17 | + self::FALSE."|". |
|
| 18 | + self::TRUE."|". |
|
| 19 | + self::AN."|". |
|
| 20 | + self::NUM.")"; |
|
| 21 | 21 | private const seqForMap = "(?P<seq>\[(?:(?:(?P>sv)|(?P>seq)|(?P>map)),?\s*)+\])"; |
| 22 | 22 | private const mapForSeq = "(?P<map>{\s*(?:".self::AN."\s*:\s*(?:(?P>sv)|(?P>seq)|(?P>map)),?\s*)+})"; |
| 23 | 23 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $matchSpaced = preg_match($spaced, $v); |
| 42 | 42 | $matchIso = preg_match($iso8601, $v); |
| 43 | 43 | if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso)) |
| 44 | - throw new \Exception("Regex date error"); |
|
| 44 | + throw new \Exception("Regex date error"); |
|
| 45 | 45 | |
| 46 | 46 | return $matchDate || $matchCanonical || $matchSpaced || $matchIso; |
| 47 | 47 | } |
@@ -32,10 +32,10 @@ |
||
| 32 | 32 | { |
| 33 | 33 | $d = "\\d{4}([-\\/])\\d{2}\\1\\d{2}"; |
| 34 | 34 | $h = "\\d{2}(:)\\d{2}\\2\\d{2}"; |
| 35 | - $date = "/^$d$/";// 2002-12-14, 2002/12/14 |
|
| 36 | - $canonical = "/^$d(?:t| )$h\\.\\dz?$/im";// 2001-12-15T02:59:43.1Z |
|
| 37 | - $spaced = "/^$d(?:t| )$h\\.\\d{2} [-+]\\d$/im";// 2001-12-14 21:59:43.10 -5 |
|
| 38 | - $iso8601 = "/^$d(?:t| )$h\\.\\d{2}[-+]\\d{2}\\2\\d{2}/im";// 2001-12-14t21:59:43.10-05:00 |
|
| 35 | + $date = "/^$d$/"; // 2002-12-14, 2002/12/14 |
|
| 36 | + $canonical = "/^$d(?:t| )$h\\.\\dz?$/im"; // 2001-12-15T02:59:43.1Z |
|
| 37 | + $spaced = "/^$d(?:t| )$h\\.\\d{2} [-+]\\d$/im"; // 2001-12-14 21:59:43.10 -5 |
|
| 38 | + $iso8601 = "/^$d(?:t| )$h\\.\\d{2}[-+]\\d{2}\\2\\d{2}/im"; // 2001-12-14t21:59:43.10-05:00 |
|
| 39 | 39 | $matchDate = preg_match($date, $v); |
| 40 | 40 | $matchCanonical = preg_match($canonical, $v); |
| 41 | 41 | $matchSpaced = preg_match($spaced, $v); |
@@ -40,8 +40,9 @@ |
||
| 40 | 40 | $matchCanonical = preg_match($canonical, $v); |
| 41 | 41 | $matchSpaced = preg_match($spaced, $v); |
| 42 | 42 | $matchIso = preg_match($iso8601, $v); |
| 43 | - if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso)) |
|
| 44 | - throw new \Exception("Regex date error"); |
|
| 43 | + if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso)) { |
|
| 44 | + throw new \Exception("Regex date error"); |
|
| 45 | + } |
|
| 45 | 46 | |
| 46 | 47 | return $matchDate || $matchCanonical || $matchSpaced || $matchIso; |
| 47 | 48 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | public function __construct() |
| 22 | 22 | { |
| 23 | - parent::__construct([], 1);//1 = Array indices can be accessed as properties in read/write. |
|
| 23 | + parent::__construct([], 1); //1 = Array indices can be accessed as properties in read/write. |
|
| 24 | 24 | $this->__yaml__object__api = new API(); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function __call($funcName, $arguments) |
| 29 | 29 | { |
| 30 | 30 | $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api)); |
| 31 | - $getName = function ($o) { return $o->name; }; |
|
| 31 | + $getName = function($o) { return $o->name; }; |
|
| 32 | 32 | $publicApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC)); |
| 33 | 33 | $privateApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PRIVATE)); |
| 34 | 34 | if (!in_array($funcName, $publicApi) && !in_array($funcName, $privateApi)) { |
@@ -40,8 +40,12 @@ |
||
| 40 | 40 | { |
| 41 | 41 | $prop = get_object_vars($this); |
| 42 | 42 | unset($prop["__yaml__object__api"]); |
| 43 | - if (count($prop) > 0) return $prop; |
|
| 44 | - if (count($this) > 0) return iterator_to_array($this); |
|
| 43 | + if (count($prop) > 0) { |
|
| 44 | + return $prop; |
|
| 45 | + } |
|
| 46 | + if (count($this) > 0) { |
|
| 47 | + return iterator_to_array($this); |
|
| 48 | + } |
|
| 45 | 49 | return $this->__yaml__object__api->value; |
| 46 | 50 | } |
| 47 | 51 | } |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | namespace Dallgoot\Yaml; |
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | - * The returned object representing a YAML file content |
|
| 5 | + * The returned object representing a YAML file content |
|
| 6 | 6 | * @category tag in class comment |
| 7 | 7 | * @package tag in class comment |
| 8 | 8 | * @author tag in class comment |
@@ -288,13 +288,13 @@ |
||
| 288 | 288 | private static function getScalar(string $v) |
| 289 | 289 | { |
| 290 | 290 | $types = ['yes' => true, |
| 291 | - 'no' => false, |
|
| 292 | - 'true' => true, |
|
| 293 | - 'false' => false, |
|
| 294 | - 'null' => null, |
|
| 295 | - '.inf' => INF, |
|
| 296 | - '-.inf' => -INF, |
|
| 297 | - '.nan' => NAN |
|
| 291 | + 'no' => false, |
|
| 292 | + 'true' => true, |
|
| 293 | + 'false' => false, |
|
| 294 | + 'null' => null, |
|
| 295 | + '.inf' => INF, |
|
| 296 | + '-.inf' => -INF, |
|
| 297 | + '.nan' => NAN |
|
| 298 | 298 | ]; |
| 299 | 299 | if (isset($types[strtolower($v)])) return $types[strtolower($v)]; |
| 300 | 300 | if (R::isDate($v)) return date_create($v); |
@@ -55,7 +55,9 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function getParent(int $indent = null):Node |
| 57 | 57 | { |
| 58 | - if (!is_int($indent)) return $this->parent ?? $this; |
|
| 58 | + if (!is_int($indent)) { |
|
| 59 | + return $this->parent ?? $this; |
|
| 60 | + } |
|
| 59 | 61 | $cursor = $this; |
| 60 | 62 | while ($cursor instanceof Node && $cursor->indent >= $indent) { |
| 61 | 63 | $cursor = $cursor->parent; |
@@ -146,8 +148,12 @@ discard block |
||
| 146 | 148 | $type = R::isProperlyQuoted($nodeValue) ? Y\QUOTED : Y\PARTIAL; |
| 147 | 149 | return [$type, $nodeValue]; |
| 148 | 150 | } |
| 149 | - if (in_array($first, ['{', '['])) return $this->onObject($nodeValue); |
|
| 150 | - if (in_array($first, ['!', '&', '*'])) return $this->onNodeAction($nodeValue); |
|
| 151 | + if (in_array($first, ['{', '['])) { |
|
| 152 | + return $this->onObject($nodeValue); |
|
| 153 | + } |
|
| 154 | + if (in_array($first, ['!', '&', '*'])) { |
|
| 155 | + return $this->onNodeAction($nodeValue); |
|
| 156 | + } |
|
| 151 | 157 | switch ($first) { |
| 152 | 158 | case '#': return [Y\COMMENT, ltrim($v)]; |
| 153 | 159 | case "-": return $this->onHyphen($nodeValue); |
@@ -199,9 +205,15 @@ discard block |
||
| 199 | 205 | private function onObject($value):array |
| 200 | 206 | { |
| 201 | 207 | json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 202 | - if (json_last_error() === JSON_ERROR_NONE) return [Y\JSON, $value]; |
|
| 203 | - if (preg_match(R::MAPPING, $value)) return [Y\COMPACT_MAPPING, $value]; |
|
| 204 | - if (preg_match(R::SEQUENCE, $value)) return [Y\COMPACT_SEQUENCE, $value]; |
|
| 208 | + if (json_last_error() === JSON_ERROR_NONE) { |
|
| 209 | + return [Y\JSON, $value]; |
|
| 210 | + } |
|
| 211 | + if (preg_match(R::MAPPING, $value)) { |
|
| 212 | + return [Y\COMPACT_MAPPING, $value]; |
|
| 213 | + } |
|
| 214 | + if (preg_match(R::SEQUENCE, $value)) { |
|
| 215 | + return [Y\COMPACT_SEQUENCE, $value]; |
|
| 216 | + } |
|
| 205 | 217 | return [Y\PARTIAL, $value]; |
| 206 | 218 | } |
| 207 | 219 | |
@@ -216,7 +228,9 @@ discard block |
||
| 216 | 228 | { |
| 217 | 229 | if (substr($nodeValue, 0, 3) === '---') { |
| 218 | 230 | $rest = trim(substr($nodeValue, 3)); |
| 219 | - if (empty($rest)) return [Y\DOC_START, null]; |
|
| 231 | + if (empty($rest)) { |
|
| 232 | + return [Y\DOC_START, null]; |
|
| 233 | + } |
|
| 220 | 234 | $n = new Node($rest, $this->line); |
| 221 | 235 | $n->indent = $this->indent + 4; |
| 222 | 236 | return [Y\DOC_START, $n->setParent($this)]; |
@@ -259,9 +273,15 @@ discard block |
||
| 259 | 273 | public function getPhpValue() |
| 260 | 274 | { |
| 261 | 275 | $v = $this->value; |
| 262 | - if (is_null($v)) return null; |
|
| 263 | - if ($this->type & (Y\REF_CALL | Y\SCALAR)) return self::getScalar($v); |
|
| 264 | - if ($this->type & (Y\COMPACT_MAPPING | Y\COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
| 276 | + if (is_null($v)) { |
|
| 277 | + return null; |
|
| 278 | + } |
|
| 279 | + if ($this->type & (Y\REF_CALL | Y\SCALAR)) { |
|
| 280 | + return self::getScalar($v); |
|
| 281 | + } |
|
| 282 | + if ($this->type & (Y\COMPACT_MAPPING | Y\COMPACT_SEQUENCE)) { |
|
| 283 | + return self::getCompact(substr($v, 1, -1), $this->type); |
|
| 284 | + } |
|
| 265 | 285 | switch ($this->type) { |
| 266 | 286 | case Y\JSON: return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR); |
| 267 | 287 | case Y\QUOTED: return substr($v, 1, -1); |
@@ -290,9 +310,15 @@ discard block |
||
| 290 | 310 | '-.inf' => -INF, |
| 291 | 311 | '.nan' => NAN |
| 292 | 312 | ]; |
| 293 | - if (isset($types[strtolower($v)])) return $types[strtolower($v)]; |
|
| 294 | - if (R::isDate($v)) return date_create($v); |
|
| 295 | - if (R::isNumber($v)) return self::getNumber($v); |
|
| 313 | + if (isset($types[strtolower($v)])) { |
|
| 314 | + return $types[strtolower($v)]; |
|
| 315 | + } |
|
| 316 | + if (R::isDate($v)) { |
|
| 317 | + return date_create($v); |
|
| 318 | + } |
|
| 319 | + if (R::isNumber($v)) { |
|
| 320 | + return self::getNumber($v); |
|
| 321 | + } |
|
| 296 | 322 | return strval($v); |
| 297 | 323 | } |
| 298 | 324 | |
@@ -305,8 +331,12 @@ discard block |
||
| 305 | 331 | */ |
| 306 | 332 | private static function getNumber(string $v) |
| 307 | 333 | { |
| 308 | - if (preg_match("/^(0o\d+)$/i", $v)) return intval(base_convert($v, 8, 10)); |
|
| 309 | - if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10)); |
|
| 334 | + if (preg_match("/^(0o\d+)$/i", $v)) { |
|
| 335 | + return intval(base_convert($v, 8, 10)); |
|
| 336 | + } |
|
| 337 | + if (preg_match("/^(0x[\da-f]+)$/i", $v)) { |
|
| 338 | + return intval(base_convert($v, 16, 10)); |
|
| 339 | + } |
|
| 310 | 340 | // TODO: remove these if not needed |
| 311 | 341 | // if preg_match("/^([\d.]+e[-+]\d{1,2})$/", $v)://fall through |
| 312 | 342 | // if preg_match("/^([-+]?(?:\d+|\d*.\d+))$/", $v): |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | //modify type according to child |
| 95 | 95 | switch ($child->type) { |
| 96 | 96 | case Y\COMMENT: //fall through |
| 97 | - case Y\KEY: $this->value->type = Y\MAPPING;break; |
|
| 98 | - case Y\ITEM: $this->value->type = Y\SEQUENCE;break; |
|
| 97 | + case Y\KEY: $this->value->type = Y\MAPPING; break; |
|
| 98 | + case Y\ITEM: $this->value->type = Y\SEQUENCE; break; |
|
| 99 | 99 | } |
| 100 | 100 | $this->type & Y\LITTERALS && $this->value->type = $this->type; |
| 101 | 101 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | public function parse(string $nodeString):Node |
| 121 | 121 | { |
| 122 | - $nodeValue = preg_replace("/^\t+/m", " ", $nodeString);//permissive to tabs but replacement |
|
| 122 | + $nodeValue = preg_replace("/^\t+/m", " ", $nodeString); //permissive to tabs but replacement |
|
| 123 | 123 | $this->indent = strspn($nodeValue, ' '); |
| 124 | 124 | $nodeValue = ltrim($nodeValue); |
| 125 | 125 | if ($nodeValue === '') { |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | case '#': return [Y\COMMENT, ltrim($v)]; |
| 157 | 157 | case "-": return $this->onHyphen($nodeValue); |
| 158 | 158 | case '%': return [Y\DIRECTIVE, ltrim($v)]; |
| 159 | - case '?': return [Y\SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
| 159 | + case '?': return [Y\SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
| 160 | 160 | case ':': return [Y\SET_VALUE, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
| 161 | 161 | case '>': return [Y\LITT_FOLDED, null]; |
| 162 | 162 | case '|': return [Y\LITT, null]; |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | if (!is_bool($hasComment)) { |
| 182 | 182 | $tmpNode = new Node(trim(substr($value, 0, $hasComment)), $this->line); |
| 183 | 183 | if ($tmpNode->type !== Y\PARTIAL) { |
| 184 | - $comment = new Node(trim(substr($value, $hasComment+1)), $this->line); |
|
| 185 | - $comment->identifier = true;//to specify it is NOT a fullline comment |
|
| 184 | + $comment = new Node(trim(substr($value, $hasComment + 1)), $this->line); |
|
| 185 | + $comment->identifier = true; //to specify it is NOT a fullline comment |
|
| 186 | 186 | $this->add($comment); |
| 187 | 187 | $n = $tmpNode; |
| 188 | 188 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | $type = ['!' => Y\TAG, '&' => Y\REF_DEF, '*' => Y\REF_CALL][$nodeValue[0]]; |
| 251 | 251 | $pos = strpos($v, ' '); |
| 252 | 252 | $this->identifier = is_bool($pos) ? $v : strstr($v, ' ', true); |
| 253 | - $n = is_bool($pos) ? null : (new Node(trim(substr($nodeValue, $pos+1)), $this->line))->setParent($this); |
|
| 253 | + $n = is_bool($pos) ? null : (new Node(trim(substr($nodeValue, $pos + 1)), $this->line))->setParent($this); |
|
| 254 | 254 | return [$type, $n]; |
| 255 | 255 | } |
| 256 | 256 | |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | { |
| 265 | 265 | $v = $this->value; |
| 266 | 266 | if (is_null($v)) return null; |
| 267 | - if ($this->type & (Y\REF_CALL | Y\SCALAR)) return self::getScalar($v); |
|
| 268 | - if ($this->type & (Y\COMPACT_MAPPING | Y\COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
| 267 | + if ($this->type & (Y\REF_CALL|Y\SCALAR)) return self::getScalar($v); |
|
| 268 | + if ($this->type & (Y\COMPACT_MAPPING|Y\COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
| 269 | 269 | switch ($this->type) { |
| 270 | 270 | case Y\JSON: return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR); |
| 271 | 271 | case Y\QUOTED: return substr($v, 1, -1); |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | { |
| 322 | 322 | $out = new Compact(); |
| 323 | 323 | if ($type === Y\COMPACT_SEQUENCE) { |
| 324 | - $f = function ($e) { return self::getScalar(trim($e));}; |
|
| 324 | + $f = function($e) { return self::getScalar(trim($e)); }; |
|
| 325 | 325 | //TODO : that's not robust enough, improve it |
| 326 | 326 | foreach (array_map($f, explode(",", $mappingOrSeqString)) as $key => $value) { |
| 327 | 327 | $out[$key] = $value; |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -require_once __DIR__ . '/vendor/autoload.php'; |
|
| 2 | +require_once __DIR__.'/vendor/autoload.php'; |
|
| 3 | 3 | |
| 4 | 4 | use \Dallgoot\Yaml as Y; |
| 5 | 5 | |
@@ -27,8 +27,12 @@ |
||
| 27 | 27 | public function jsonSerialize() |
| 28 | 28 | { |
| 29 | 29 | $prop = get_object_vars($this); |
| 30 | - if (count($prop) > 0) return $prop; |
|
| 31 | - if (count($this) > 0) return iterator_to_array($this); |
|
| 30 | + if (count($prop) > 0) { |
|
| 31 | + return $prop; |
|
| 32 | + } |
|
| 33 | + if (count($this) > 0) { |
|
| 34 | + return iterator_to_array($this); |
|
| 35 | + } |
|
| 32 | 36 | } |
| 33 | 37 | |
| 34 | 38 | public static function wrap($arrayOrObject) |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | public static function getName($typeInteger) |
| 55 | 55 | { |
| 56 | 56 | if (is_null(self::$TYPE_NAMES)) { |
| 57 | - $f = function ($v) { return str_replace('Dallgoot\Yaml\\', '', $v);}; |
|
| 57 | + $f = function($v) { return str_replace('Dallgoot\Yaml\\', '', $v); }; |
|
| 58 | 58 | self::$TYPE_NAMES = array_map($f, array_flip(get_defined_constants(true)['user'])); |
| 59 | 59 | } |
| 60 | 60 | return self::$TYPE_NAMES[$typeInteger]; |
@@ -21,7 +21,9 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function __construct(int $options = null) |
| 23 | 23 | { |
| 24 | - if (is_int($options)) self::$options = $options; |
|
| 24 | + if (is_int($options)) { |
|
| 25 | + self::$options = $options; |
|
| 26 | + } |
|
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | /** |
@@ -36,7 +38,9 @@ discard block |
||
| 36 | 38 | */ |
| 37 | 39 | public static function toString($dataType, int $options = null):string |
| 38 | 40 | { |
| 39 | - if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml", 1); |
|
| 41 | + if (is_null($dataType)) { |
|
| 42 | + throw new \Exception(self::class.": No content to convert to Yaml", 1); |
|
| 43 | + } |
|
| 40 | 44 | self::$options = is_int($options) ? $options : self::OPTIONS; |
| 41 | 45 | self::$result = new DLL; |
| 42 | 46 | self::$result->setIteratorMode(DLL::IT_MODE_FIFO|DLL::IT_MODE_DELETE); |
@@ -74,8 +78,12 @@ discard block |
||
| 74 | 78 | if (is_scalar($dataType)) { |
| 75 | 79 | switch (gettype($dataType)) { |
| 76 | 80 | case 'boolean': return $dataType ? 'true' : 'false'; |
| 77 | - case 'float': if (is_infinite((float) $dataType)) return $dataType > 0 ? '.inf' : '-.inf'; |
|
| 78 | - case 'double': if (is_nan((float) $dataType)) return '.nan'; |
|
| 81 | + case 'float': if (is_infinite((float) $dataType)) { |
|
| 82 | + return $dataType > 0 ? '.inf' : '-.inf'; |
|
| 83 | + } |
|
| 84 | + case 'double': if (is_nan((float) $dataType)) { |
|
| 85 | + return '.nan'; |
|
| 86 | + } |
|
| 79 | 87 | default: |
| 80 | 88 | return $dataType; |
| 81 | 89 | } |
@@ -17,17 +17,17 @@ discard block |
||
| 17 | 17 | //public |
| 18 | 18 | public $errors = []; |
| 19 | 19 | |
| 20 | - public const EXCLUDE_DIRECTIVES = 1;//DONT include_directive |
|
| 21 | - public const IGNORE_COMMENTS = 2;//DONT include_comments |
|
| 22 | - public const NO_PARSING_EXCEPTIONS = 4;//THROW Exception on parsing Errors |
|
| 23 | - public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
|
| 20 | + public const EXCLUDE_DIRECTIVES = 1; //DONT include_directive |
|
| 21 | + public const IGNORE_COMMENTS = 2; //DONT include_comments |
|
| 22 | + public const NO_PARSING_EXCEPTIONS = 4; //THROW Exception on parsing Errors |
|
| 23 | + public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object |
|
| 24 | 24 | //privates |
| 25 | 25 | /* @var null|string */ |
| 26 | 26 | private $content; |
| 27 | 27 | /* @var null|string */ |
| 28 | 28 | private $filePath; |
| 29 | 29 | /* @var integer */ |
| 30 | - private $debug = 0;///TODO: determine levels |
|
| 30 | + private $debug = 0; ///TODO: determine levels |
|
| 31 | 31 | /* @var integer */ |
| 32 | 32 | private $options = 0; |
| 33 | 33 | //Exceptions messages |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | $emptyLines = []; |
| 114 | 114 | switch ($n->indent <=> $previous->indent) { |
| 115 | - case -1: $previous->getParent($n->indent)->add($n);break; |
|
| 116 | - case 0: $previous->getParent()->add($n);break; |
|
| 115 | + case -1: $previous->getParent($n->indent)->add($n); break; |
|
| 116 | + case 0: $previous->getParent()->add($n); break; |
|
| 117 | 117 | default: |
| 118 | 118 | if ($this->onDeepestType($n, $previous, $lineString)) continue 2; |
| 119 | 119 | $previous->add($n); |
@@ -84,9 +84,13 @@ discard block |
||
| 84 | 84 | public function parse($strContent = null) |
| 85 | 85 | { |
| 86 | 86 | $source = $this->content; |
| 87 | - if (is_null($source)) $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE); |
|
| 87 | + if (is_null($source)) { |
|
| 88 | + $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE); |
|
| 89 | + } |
|
| 88 | 90 | //TODO : be more permissive on $strContent values |
| 89 | - if (!is_array($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
|
| 91 | + if (!is_array($source)) { |
|
| 92 | + throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
|
| 93 | + } |
|
| 90 | 94 | $previous = $root = new Node(); |
| 91 | 95 | $emptyLines = []; |
| 92 | 96 | $specialTypes = Y\LITTERALS|Y\BLANK; |
@@ -115,7 +119,9 @@ discard block |
||
| 115 | 119 | case -1: $previous->getParent($n->indent)->add($n);break; |
| 116 | 120 | case 0: $previous->getParent()->add($n);break; |
| 117 | 121 | default: |
| 118 | - if ($this->onDeepestType($n, $previous, $lineString)) continue 2; |
|
| 122 | + if ($this->onDeepestType($n, $previous, $lineString)) { |
|
| 123 | + continue 2; |
|
| 124 | + } |
|
| 119 | 125 | $previous->add($n); |
| 120 | 126 | } |
| 121 | 127 | $previous = $n; |
@@ -155,8 +161,12 @@ discard block |
||
| 155 | 161 | } |
| 156 | 162 | } |
| 157 | 163 | if ($n->type & Y\BLANK) { |
| 158 | - if ($previous->type & Y\SCALAR) $emptyLines[] = $n->setParent($previous->getParent()); |
|
| 159 | - if ($deepest->type & Y\LITTERALS) $emptyLines[] = $n->setParent($deepest); |
|
| 164 | + if ($previous->type & Y\SCALAR) { |
|
| 165 | + $emptyLines[] = $n->setParent($previous->getParent()); |
|
| 166 | + } |
|
| 167 | + if ($deepest->type & Y\LITTERALS) { |
|
| 168 | + $emptyLines[] = $n->setParent($deepest); |
|
| 169 | + } |
|
| 160 | 170 | return true; |
| 161 | 171 | } |
| 162 | 172 | return false; |