@@ -25,8 +25,12 @@ |
||
| 25 | 25 | public function jsonSerialize():array |
| 26 | 26 | { |
| 27 | 27 | $prop = get_object_vars($this); |
| 28 | - if (count($prop) > 0) return $prop; |
|
| 29 | - if (count($this) > 0) return iterator_to_array($this); |
|
| 28 | + if (count($prop) > 0) { |
|
| 29 | + return $prop; |
|
| 30 | + } |
|
| 31 | + if (count($this) > 0) { |
|
| 32 | + return iterator_to_array($this); |
|
| 33 | + } |
|
| 30 | 34 | } |
| 31 | 35 | |
| 32 | 36 | /** |
@@ -43,9 +43,9 @@ |
||
| 43 | 43 | public function __call($funcName, $arguments) |
| 44 | 44 | { |
| 45 | 45 | $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api)); |
| 46 | - $getName = function ($o) { return $o->name; }; |
|
| 46 | + $getName = function($o) { return $o->name; }; |
|
| 47 | 47 | $publicApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC)); |
| 48 | - if (!in_array($funcName, $publicApi) ) { |
|
| 48 | + if (!in_array($funcName, $publicApi)) { |
|
| 49 | 49 | throw new \BadMethodCallException(sprintf(self::UNDEFINED_METHOD, $funcName, implode(",", $publicApi)), 1); |
| 50 | 50 | } |
| 51 | 51 | return call_user_func_array([$this->__yaml__object__api, $funcName], $arguments); |
@@ -52,8 +52,12 @@ |
||
| 52 | 52 | { |
| 53 | 53 | $prop = get_object_vars($this); |
| 54 | 54 | unset($prop["__yaml__object__api"]); |
| 55 | - if (count($prop) > 0) return $prop; |
|
| 56 | - if (count($this) > 0) return iterator_to_array($this); |
|
| 55 | + if (count($prop) > 0) { |
|
| 56 | + return $prop; |
|
| 57 | + } |
|
| 58 | + if (count($this) > 0) { |
|
| 59 | + return iterator_to_array($this); |
|
| 60 | + } |
|
| 57 | 61 | return $this->__yaml__object__api->value ?? "Empty YamlObject"; |
| 58 | 62 | } |
| 59 | 63 | } |
@@ -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 | // $content = file_get_contents('./tests/cases/parsing/yaml_in_literal_folded.yml');//var_dump($content); |
| 16 | -$content = file_get_contents('./tests/cases/parsing/tags_in_mapping.yml');//var_dump($content); |
|
| 16 | +$content = file_get_contents('./tests/cases/parsing/tags_in_mapping.yml'); //var_dump($content); |
|
| 17 | 17 | $yaml = Y::parse($content, null, (int) $argv[1]); |
| 18 | 18 | // $yaml = Y::parseFile('./references/Example 2.27.yml', null, 1); |
| 19 | 19 | var_dump($yaml); |