| Total Complexity | 35 |
| Total Lines | 167 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | final class Loader |
||
| 9 | { |
||
| 10 | //public |
||
| 11 | public $errors = []; |
||
| 12 | |||
| 13 | public const EXCLUDE_DIRECTIVES = 1;//DONT include_directive |
||
| 14 | public const IGNORE_COMMENTS = 2;//DONT include_comments |
||
| 15 | public const NO_PARSING_EXCEPTIONS = 4;//THROW Exception on parsing Errors |
||
| 16 | public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
||
| 17 | //privates |
||
| 18 | private $content;/* @var null|string */ |
||
| 19 | private $filePath;/* @var null|string */ |
||
| 20 | private $debug = 0;//TODO: determine levels |
||
| 21 | private $options = 0;/* @var int */ |
||
| 22 | //Exceptions messages |
||
| 23 | private const INVALID_VALUE = self::class.": at line %d"; |
||
| 24 | private const EXCEPTION_NO_FILE = self::class.": file '%s' does not exists (or path is incorrect?)"; |
||
| 25 | private const EXCEPTION_READ_ERROR = self::class.": file '%s' failed to be loaded (permission denied ?)"; |
||
| 26 | private const EXCEPTION_LINE_SPLIT = self::class.": content is not a string(maybe a file error?)"; |
||
| 27 | |||
| 28 | public function __construct($absolutePath = null, $options = null, $debug = 0) |
||
| 29 | { |
||
| 30 | $this->debug = is_int($debug) ? min($debug, 3) : 1; |
||
| 31 | $this->options = is_int($options) ? $options : $this->options; |
||
| 32 | if (is_string($absolutePath)) { |
||
| 33 | $this->load($absolutePath); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * load a file and save its content as $content |
||
| 39 | * |
||
| 40 | * @param string $absolutePath The absolute path of a file |
||
|
3 ignored issues
–
show
|
|||
| 41 | * |
||
| 42 | * @throws \Exception if file don't exist OR reading failed |
||
|
1 ignored issue
–
show
|
|||
| 43 | * |
||
| 44 | * @return self ( returns the same Loader ) |
||
|
1 ignored issue
–
show
|
|||
| 45 | */ |
||
| 46 | public function load(string $absolutePath):Loader |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Parse Yaml lines into an hierarchy of Node |
||
| 67 | * |
||
| 68 | * @param string $strContent The Yaml string or null to parse loaded content |
||
|
3 ignored issues
–
show
|
|||
| 69 | * @throws \Exception if content is not available as $strContent or as $this->content (from file) |
||
|
1 ignored issue
–
show
|
|||
| 70 | * @throws \ParseError if any error during parsing or building |
||
|
1 ignored issue
–
show
|
|||
| 71 | * |
||
| 72 | * @return array|YamlObject the hierarchy built an array of YamlObject or just YamlObject |
||
|
1 ignored issue
–
show
|
|||
| 73 | */ |
||
| 74 | public function parse($strContent = null) |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | private function onSpecialType(&$n, &$previous, &$emptyLines):bool |
||
| 147 | } |
||
| 148 | |||
| 149 | private function onDeepestType(&$n, &$previous, $lineString):bool |
||
| 177 |