Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| AbstractPageParser | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Hyde\Framework\Contracts; |
| 4 | |
| 5 | use Hyde\Framework\Concerns\ValidatesExistence; |
| 6 | |
| 7 | /** |
| 8 | * Abstract base class for all page parsers. |
| 9 | * |
| 10 | * Page Parsers are responsible for parsing a source file into a Page object, |
| 11 | * and may also conduct pre-processing and/or data validation/assembly. |
| 12 | * |
| 13 | * Note that the Page Parsers do not compile any HTML or Markdown. |
| 14 | * |
| 15 | * To ensure that all page parsing jobs are handled consistently, |
| 16 | * all page parsers should extend this class. |
| 17 | */ |
| 18 | abstract class AbstractPageParser implements PageParserContract |
| 19 | { |
| 20 | use ValidatesExistence; |
| 21 | |
| 22 | /** |
| 23 | * @var string of the page to parse. |
| 24 | */ |
| 25 | protected string $slug; |
| 26 | |
| 27 | /** |
| 28 | * @var string the parser is for. |
| 29 | */ |
| 30 | protected string $pageModel = AbstractPage::class; |
| 31 | |
| 32 | /** |
| 33 | * Construct the class. |
| 34 | * |
| 35 | * @throws \Exception if the source file does not exist. |
| 36 | */ |
| 37 | public function __construct(string $slug) |
| 38 | { |
| 39 | $this->slug = $slug; |
| 40 | $this->validateExistence($this->pageModel, $slug); |
| 41 | $this->execute(); |
| 42 | } |
| 43 | } |