@@ -99,35 +99,35 @@ |
||
| 99 | 99 | if (Regex::isDate($v)) return Builder::$dateAsObject && !$onlyScalar ? date_create($v) : $v; |
| 100 | 100 | if (Regex::isNumber($v)) return self::getNumber($v); |
| 101 | 101 | $types = ['yes' => true, |
| 102 | - 'no' => false, |
|
| 103 | - 'true' => true, |
|
| 104 | - 'false' => false, |
|
| 105 | - 'null' => null, |
|
| 106 | - '.inf' => \INF, |
|
| 107 | - '-.inf' => -\INF, |
|
| 108 | - '.nan' => \NAN |
|
| 102 | + 'no' => false, |
|
| 103 | + 'true' => true, |
|
| 104 | + 'false' => false, |
|
| 105 | + 'null' => null, |
|
| 106 | + '.inf' => \INF, |
|
| 107 | + '-.inf' => -\INF, |
|
| 108 | + '.nan' => \NAN |
|
| 109 | 109 | ]; |
| 110 | 110 | return array_key_exists(strtolower($v), $types) ? $types[strtolower($v)] : self::replaceSequences($v); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | public static function replaceSequences($value='') |
| 114 | 114 | { |
| 115 | - $replaceUnicodeSeq = function ($matches) { |
|
| 115 | + $replaceUnicodeSeq = function ($matches) { |
|
| 116 | 116 | return json_decode('"'.$matches[1].'"'); |
| 117 | - }; |
|
| 118 | - $replaceNonPrintable = function ($matches) { |
|
| 117 | + }; |
|
| 118 | + $replaceNonPrintable = function ($matches) { |
|
| 119 | 119 | // var_dump($matches[1]); |
| 120 | 120 | return $matches[1].""; |
| 121 | - }; |
|
| 121 | + }; |
|
| 122 | 122 | // preg_match( "/[^\x{06F0}-\x{06F9}\x]+/u" , '۱۲۳۴۵۶۷۸۹۰' ); |
| 123 | - return preg_replace_callback_array( |
|
| 124 | - [ |
|
| 125 | - '/((?<![\\\\])\\\\x[0-9a-f]{2})/i' => $replaceUnicodeSeq, |
|
| 126 | - '/((?<![\\\\])\\\\u[0-9a-f]{4,})/i' => $replaceUnicodeSeq, |
|
| 127 | - '/(\\\\b|\\\\n|\\\\t|\\\\r)/' => $replaceNonPrintable |
|
| 128 | - ], |
|
| 129 | - $value |
|
| 130 | - ); |
|
| 123 | + return preg_replace_callback_array( |
|
| 124 | + [ |
|
| 125 | + '/((?<![\\\\])\\\\x[0-9a-f]{2})/i' => $replaceUnicodeSeq, |
|
| 126 | + '/((?<![\\\\])\\\\u[0-9a-f]{4,})/i' => $replaceUnicodeSeq, |
|
| 127 | + '/(\\\\b|\\\\n|\\\\t|\\\\r)/' => $replaceNonPrintable |
|
| 128 | + ], |
|
| 129 | + $value |
|
| 130 | + ); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | public function getTargetOnLessIndent(NodeGeneric &$node):NodeGeneric |
| 51 | 51 | { |
| 52 | - if ($node instanceof Scalar || $node instanceof Blank ) { |
|
| 52 | + if ($node instanceof Scalar || $node instanceof Blank) { |
|
| 53 | 53 | return $this->getParent(); |
| 54 | 54 | } else { |
| 55 | 55 | return $this->getParent($node->indent); |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | return array_key_exists(strtolower($v), $types) ? $types[strtolower($v)] : self::replaceSequences($v); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - public static function replaceSequences($value='') |
|
| 113 | + public static function replaceSequences($value = '') |
|
| 114 | 114 | { |
| 115 | - $replaceUnicodeSeq = function ($matches) { |
|
| 115 | + $replaceUnicodeSeq = function($matches) { |
|
| 116 | 116 | return json_decode('"'.$matches[1].'"'); |
| 117 | 117 | }; |
| 118 | - $replaceNonPrintable = function ($matches) { |
|
| 118 | + $replaceNonPrintable = function($matches) { |
|
| 119 | 119 | // var_dump($matches[1]); |
| 120 | 120 | return $matches[1].""; |
| 121 | 121 | }; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | $previousCompactMode = $this->dumper->_compactMode; |
| 104 | - $this->dumper->_compactMode = true; |
|
| 104 | + $this->dumper->_compactMode = true; |
|
| 105 | 105 | $result = $this->dumper->iteratorToString(new \ArrayIterator($source), $keyMask, ', ', $indent); |
| 106 | 106 | $this->dumper->_compactMode = $previousCompactMode; |
| 107 | 107 | return sprintf($structureFormat, $result); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | // Example 5.13. Escaped Characters |
| 124 | 124 | |
| 125 | 125 | $str = json_encode(ltrim($str)); |
| 126 | - return strspn(substr($str,1,-1), "-:?{}[]#,&*!>|'\"%") > 0 ? $str : trim($str, '"'); |
|
| 126 | + return strspn(substr($str, 1, -1), "-:?{}[]#,&*!>|'\"%") > 0 ? $str : trim($str, '"'); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | public function dumpTagged(Tagged $obj, int $indent):string |
@@ -22,8 +22,12 @@ |
||
| 22 | 22 | |
| 23 | 23 | public function dumpScalar($dataType):string |
| 24 | 24 | { |
| 25 | - if ($dataType === \INF) return '.inf'; |
|
| 26 | - if ($dataType === -\INF) return '-.inf'; |
|
| 25 | + if ($dataType === \INF) { |
|
| 26 | + return '.inf'; |
|
| 27 | + } |
|
| 28 | + if ($dataType === -\INF) { |
|
| 29 | + return '-.inf'; |
|
| 30 | + } |
|
| 27 | 31 | $precision = "%.".$this->dumper->floatPrecision."F"; |
| 28 | 32 | switch (gettype($dataType)) { |
| 29 | 33 | case 'boolean': return $dataType ? 'true' : 'false'; |
@@ -20,10 +20,10 @@ discard block |
||
| 20 | 20 | //public |
| 21 | 21 | /* @var null|string */ |
| 22 | 22 | public static $error; |
| 23 | - public const IGNORE_DIRECTIVES = 1;//DONT include_directive |
|
| 24 | - public const IGNORE_COMMENTS = 2;//DONT include_comments |
|
| 25 | - public const NO_PARSING_EXCEPTIONS = 4;//DONT throw Exception on parsing errors |
|
| 26 | - public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
|
| 23 | + public const IGNORE_DIRECTIVES = 1; //DONT include_directive |
|
| 24 | + public const IGNORE_COMMENTS = 2; //DONT include_comments |
|
| 25 | + public const NO_PARSING_EXCEPTIONS = 4; //DONT throw Exception on parsing errors |
|
| 26 | + public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object |
|
| 27 | 27 | |
| 28 | 28 | //private |
| 29 | 29 | /* @var null|array */ |
@@ -179,8 +179,8 @@ discard block |
||
| 179 | 179 | { |
| 180 | 180 | $deepest = $previous->getDeepestNode(); |
| 181 | 181 | if ($deepest instanceof Nodes\Partial) { |
| 182 | - return $deepest->specialProcess($current, $this->_blankBuffer); |
|
| 183 | - } elseif(!($current instanceof Nodes\Partial)) { |
|
| 182 | + return $deepest->specialProcess($current, $this->_blankBuffer); |
|
| 183 | + } elseif (!($current instanceof Nodes\Partial)) { |
|
| 184 | 184 | return $current->specialProcess($previous, $this->_blankBuffer); |
| 185 | 185 | } |
| 186 | 186 | return false; |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | $buffer->push($child); |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | - $documents[] = self::buildDocument($buffer, count($documents) +1); |
|
| 54 | + $documents[] = self::buildDocument($buffer, count($documents) + 1); |
|
| 55 | 55 | } catch (\Throwable $e) { |
| 56 | 56 | throw new \Exception($e->getMessage(), 1, $e); |
| 57 | 57 | } |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | public function dumpYamlObject(YamlObject $obj):string |
| 106 | 106 | { |
| 107 | 107 | if ($this->multipleDocs || $obj->hasDocStart() || $obj->isTagged()) { |
| 108 | - $this->multipleDocs = true; |
|
| 109 | - // && $this->$result instanceof DLL) $this->$result->push("---"); |
|
| 108 | + $this->multipleDocs = true; |
|
| 109 | + // && $this->$result instanceof DLL) $this->$result->push("---"); |
|
| 110 | 110 | } |
| 111 | 111 | // $this->insertComments($obj->getComment()); |
| 112 | 112 | if (count($obj) > 0) { |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | |
| 120 | 120 | public function iteratorToString(\Iterator $iterable, |
| 121 | - string $keyMask, string $itemSeparator, int $indent):string |
|
| 121 | + string $keyMask, string $itemSeparator, int $indent):string |
|
| 122 | 122 | { |
| 123 | 123 | $pairs = []; |
| 124 | 124 | $valueIndent = $indent + self::INDENT; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | private $handler; |
| 32 | 32 | |
| 33 | 33 | |
| 34 | - public function __construct($options=null) |
|
| 34 | + public function __construct($options = null) |
|
| 35 | 35 | { |
| 36 | 36 | $this->options = is_int($options) ? $options : self::OPTIONS; |
| 37 | 37 | $this->handler = new DumperHandlers($this); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | { |
| 51 | 51 | if (empty($dataType)) throw new \Exception(self::class.": No content to convert to Yaml"); |
| 52 | 52 | if (is_scalar($dataType)) { |
| 53 | - return "--- ".$this->handler->dumpScalar($dataType). self::LINEFEED ; |
|
| 53 | + return "--- ".$this->handler->dumpScalar($dataType).self::LINEFEED; |
|
| 54 | 54 | } |
| 55 | 55 | return $this->dump($dataType, 0); |
| 56 | 56 | } |
@@ -48,7 +48,9 @@ |
||
| 48 | 48 | */ |
| 49 | 49 | public function toString($dataType, int $options = null):string |
| 50 | 50 | { |
| 51 | - if (empty($dataType)) throw new \Exception(self::class.": No content to convert to Yaml"); |
|
| 51 | + if (empty($dataType)) { |
|
| 52 | + throw new \Exception(self::class.": No content to convert to Yaml"); |
|
| 53 | + } |
|
| 52 | 54 | if (is_scalar($dataType)) { |
| 53 | 55 | return "--- ".$this->handler->dumpScalar($dataType). self::LINEFEED ; |
| 54 | 56 | } |