@@ -32,7 +32,7 @@ |
||
32 | 32 | } |
33 | 33 | $options = is_null($options) ? self::options : $options; |
34 | 34 | self::$result = new DLL; |
35 | - self::$result->setIteratorMode(DLL::IT_MODE_FIFO | DLL::IT_MODE_DELETE); |
|
35 | + self::$result->setIteratorMode(DLL::IT_MODE_FIFO|DLL::IT_MODE_DELETE); |
|
36 | 36 | if ($dataType instanceof YamlObject) { |
37 | 37 | return self::dumpYamlObject($dataType); |
38 | 38 | } elseif (is_array($dataType) && $dataType[0] instanceof YamlObject) { |
@@ -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); |
@@ -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\Loader; |
5 | 5 |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | //modify type according to child |
61 | 61 | if ($this->value instanceof DLL && !property_exists($this->value, "type")) { |
62 | 62 | switch ($child->type) { |
63 | - case T::KEY: $this->value->type = T::MAPPING;break; |
|
64 | - case T::ITEM: $this->value->type = T::SEQUENCE;break; |
|
65 | - case T::SCALAR: $this->value->type = $this->type;break; |
|
63 | + case T::KEY: $this->value->type = T::MAPPING; break; |
|
64 | + case T::ITEM: $this->value->type = T::SEQUENCE; break; |
|
65 | + case T::SCALAR: $this->value->type = $this->type; break; |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function parse(String $nodeString):Node |
82 | 82 | { |
83 | - $nodeValue = preg_replace("/^\t+/m", " ", $nodeString);//permissive to tabs but replacement |
|
83 | + $nodeValue = preg_replace("/^\t+/m", " ", $nodeString); //permissive to tabs but replacement |
|
84 | 84 | $this->indent = strspn($nodeValue, ' '); |
85 | 85 | $nodeValue = ltrim($nodeValue); |
86 | 86 | if ($nodeValue === '') { |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | case '#': return [T::COMMENT, ltrim($v)]; |
117 | 117 | case "-": return $this->_onMinus($nodeValue); |
118 | 118 | case '%': return [T::DIRECTIVE, ltrim($v)]; |
119 | - case '?': return [T::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
119 | + case '?': return [T::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
120 | 120 | case ':': return [T::SET_VALUE, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
121 | 121 | case '>': return [T::LITTERAL_FOLDED, null]; |
122 | 122 | case '|': return [T::LITTERAL, null]; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | if (!is_bool($hasComment)) { |
137 | 137 | $tmpNode = new Node(trim(substr($keyValue, 0, $hasComment)), $this->line); |
138 | 138 | if ($tmpNode->type !== T::PARTIAL) { |
139 | - $comment = new Node(trim(substr($keyValue, $hasComment+1)), $this->line); |
|
139 | + $comment = new Node(trim(substr($keyValue, $hasComment + 1)), $this->line); |
|
140 | 140 | $this->add($comment); |
141 | 141 | $n = $tmpNode; |
142 | 142 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $type = ['!' => T::TAG, '&' => T::REF_DEF, '*' => T::REF_CALL][$nodeValue[0]]; |
182 | 182 | $pos = strpos($v, ' '); |
183 | 183 | $this->name = is_bool($pos) ? $v : strstr($v, ' ', true); |
184 | - $n = is_bool($pos) ? null : (new Node(trim(substr($nodeValue, $pos+1)), $this->line))->setParent($this); |
|
184 | + $n = is_bool($pos) ? null : (new Node(trim(substr($nodeValue, $pos + 1)), $this->line))->setParent($this); |
|
185 | 185 | return [$type, $n]; |
186 | 186 | } |
187 | 187 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | case T::MAPPING_SHORT: return $this->getShortMapping(substr($this->value, 1, -1)); |
199 | 199 | //TODO : that's not robust enough, improve it |
200 | 200 | case T::SEQUENCE_SHORT: |
201 | - $f = function ($e) { return self::getScalar(trim($e));}; |
|
201 | + $f = function($e) { return self::getScalar(trim($e)); }; |
|
202 | 202 | return array_map($f, explode(",", substr($this->value, 1, -1))); |
203 | 203 | default: |
204 | 204 | trigger_error("Error can not get PHP type for ".T::getName($this->type), E_USER_WARNING); |
@@ -14,14 +14,14 @@ |
||
14 | 14 | |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - parent::__construct([], 1);//1 = Array indices can be accessed as properties in read/write. |
|
17 | + parent::__construct([], 1); //1 = Array indices can be accessed as properties in read/write. |
|
18 | 18 | $this->__yaml__object__api = new API(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public function __call($funcName, $arguments) |
22 | 22 | { |
23 | 23 | $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api)); |
24 | - $getName = function ($o) { return $o->name; }; |
|
24 | + $getName = function($o) { return $o->name; }; |
|
25 | 25 | $publicApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC)); |
26 | 26 | $privateApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PRIVATE)); |
27 | 27 | if (!in_array($funcName, $publicApi) && |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | $p = $parent; |
33 | 33 | switch ($type) { |
34 | 34 | case T::MAPPING: //fall through |
35 | - case T::SET: $p = new \StdClass;break; |
|
36 | - case T::SEQUENCE: $p = [];break; |
|
35 | + case T::SET: $p = new \StdClass; break; |
|
36 | + case T::SEQUENCE: $p = []; break; |
|
37 | 37 | // case T::KEY: $p = $parent;break; |
38 | 38 | } |
39 | 39 | $out = null; |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | private static function buildNode(Node $node, &$parent) |
54 | 54 | { |
55 | 55 | list($line, $type, $value) = [$node->line, $node->type, $node->value]; |
56 | - $name = property_exists($node, "name") ? $node->name : null; |
|
56 | + $name = property_exists($node, "name") ? $node->name : null; |
|
57 | 57 | switch ($type) { |
58 | - case T::COMMENT: self::$root->addComment($line, $value);return; |
|
59 | - case T::DIRECTIVE: return;//TODO |
|
60 | - case T::ITEM: self::buildItem($value, $parent);return; |
|
61 | - case T::KEY: self::buildKey($node, $parent);return; |
|
58 | + case T::COMMENT: self::$root->addComment($line, $value); return; |
|
59 | + case T::DIRECTIVE: return; //TODO |
|
60 | + case T::ITEM: self::buildItem($value, $parent); return; |
|
61 | + case T::KEY: self::buildKey($node, $parent); return; |
|
62 | 62 | case T::REF_DEF: //fall through |
63 | 63 | case T::REF_CALL: |
64 | 64 | $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue(); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $prop = array_keys(get_object_vars($parent)); |
75 | 75 | $key = end($prop); |
76 | 76 | if (property_exists($value, "type") && in_array($value->type, [T::ITEM, T::MAPPING])) { |
77 | - $p = $value->type === T::ITEM ? [] : new \StdClass; |
|
77 | + $p = $value->type === T::ITEM ? [] : new \StdClass; |
|
78 | 78 | self::build($value, $p); |
79 | 79 | } else { |
80 | 80 | $p = self::build($value, $parent->{$key}); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | return; |
84 | 84 | case T::TAG: |
85 | 85 | if ($parent === self::$root) { |
86 | - $parent->addTag($name);return; |
|
86 | + $parent->addTag($name); return; |
|
87 | 87 | } else { |
88 | 88 | if (in_array($name, ['!binary', '!str'])) { |
89 | 89 | if (is_object($value->value)) $value->value->type = T::RAW; |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key)); |
172 | 172 | } else { |
173 | 173 | switch (true) { |
174 | - case $isSequence: $list->type = T::SEQUENCE;break; |
|
175 | - case $isSet: $list->type = T::SET;break; |
|
174 | + case $isSequence: $list->type = T::SEQUENCE; break; |
|
175 | + case $isSet: $list->type = T::SET; break; |
|
176 | 176 | case $isMapping://fall through |
177 | 177 | default:$list->type = T::MAPPING; |
178 | 178 | } |
@@ -196,10 +196,10 @@ discard block |
||
196 | 196 | $children->rewind(); |
197 | 197 | $refIndent = $children->current()->indent; |
198 | 198 | $separator = $type === T::RAW ? '' : "\n"; |
199 | - $action = function ($c) { return $c->value; }; |
|
199 | + $action = function($c) { return $c->value; }; |
|
200 | 200 | if ($type === T::LITTERAL_FOLDED) { |
201 | 201 | $separator = ' '; |
202 | - $action = function ($c) use ($refIndent) { |
|
202 | + $action = function($c) use ($refIndent) { |
|
203 | 203 | return $c->indent > $refIndent || $c->type === T::EMPTY ? "\n".$c->value : $c->value; |
204 | 204 | }; |
205 | 205 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | |
4 | 4 | class Types |
5 | 5 | { |
6 | - const DIRECTIVE = 0; |
|
6 | + const DIRECTIVE = 0; |
|
7 | 7 | const DOC_START = 1; |
8 | 8 | const DOC_END = 2; |
9 | 9 | |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | const LITTERAL = 72; |
25 | 25 | const LITTERAL_FOLDED = 82; |
26 | 26 | |
27 | - const SCALAR = 102; |
|
27 | + const SCALAR = 102; |
|
28 | 28 | const TAG = 132; |
29 | 29 | const JSON = 142; |
30 | 30 |
@@ -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 |
@@ -9,14 +9,14 @@ discard block |
||
9 | 9 | { |
10 | 10 | public $errors = []; |
11 | 11 | //options |
12 | - public const EXCLUDE_DIRECTIVES = 0001;//DONT include_directive |
|
13 | - public const IGNORE_COMMENTS = 0010;//DONT include_comments |
|
14 | - public const EXCEPTIONS_PARSING = 0100;//THROW Exception on parsing Errors |
|
15 | - public const NO_OBJECT_FOR_DATE = 1000;//DONT import date strings as dateTime Object |
|
12 | + public const EXCLUDE_DIRECTIVES = 0001; //DONT include_directive |
|
13 | + public const IGNORE_COMMENTS = 0010; //DONT include_comments |
|
14 | + public const EXCEPTIONS_PARSING = 0100; //THROW Exception on parsing Errors |
|
15 | + public const NO_OBJECT_FOR_DATE = 1000; //DONT import date strings as dateTime Object |
|
16 | 16 | // |
17 | 17 | private $_content; |
18 | 18 | private $filePath; |
19 | - private $_debug = 0;//TODO: determine levels |
|
19 | + private $_debug = 0; //TODO: determine levels |
|
20 | 20 | private $_options = 0; |
21 | 21 | //Exceptions |
22 | 22 | const INVALID_VALUE = self::class.": at line %d"; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $specialTypes = [T::LITTERAL, T::LITTERAL_FOLDED, T::EMPTY]; |
75 | 75 | try { |
76 | 76 | foreach ($source as $lineNb => $lineString) { |
77 | - $n = new Node($lineString, $lineNb + 1);//TODO: useful???-> $this->_debug && var_dump($n); |
|
77 | + $n = new Node($lineString, $lineNb + 1); //TODO: useful???-> $this->_debug && var_dump($n); |
|
78 | 78 | $parent = $previous; |
79 | 79 | $deepest = $previous->getDeepestNode(); |
80 | 80 | if ($deepest->type === T::PARTIAL) { |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | switch ($deepest->type) { |
148 | 148 | case T::LITTERAL: |
149 | 149 | case T::LITTERAL_FOLDED: |
150 | - $n->value = trim($lineString);//fall through |
|
150 | + $n->value = trim($lineString); //fall through |
|
151 | 151 | case T::REF_DEF://fall through |
152 | 152 | case T::SET_VALUE://fall through |
153 | 153 | case T::TAG: |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | case T::EMPTY: |
157 | 157 | case T::SCALAR: |
158 | 158 | if ($n->type === T::SCALAR && |
159 | - !in_array($deepest->getParent()->type, T::$LITTERALS) ) { |
|
159 | + !in_array($deepest->getParent()->type, T::$LITTERALS)) { |
|
160 | 160 | $deepest->type = T::SCALAR; |
161 | 161 | $deepest->value .= "\n".$n->value; |
162 | 162 | return true; |