1 | <?php |
||
16 | class Parser |
||
17 | { |
||
18 | // https://regex101.com/r/xH7cL3/1 |
||
19 | const PATTERN = '^\s*(?:<!--|---|\+++){1}[\n\r\s]*(.*?)[\n\r\s]*(?:-->|---|\+++){1}[\s\n\r]*(.*)$'; |
||
20 | /** |
||
21 | * @var SplFileInfo |
||
22 | */ |
||
23 | protected $file; |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $frontmatter; |
||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $body; |
||
32 | |||
33 | /** |
||
34 | * Constructor. |
||
35 | * |
||
36 | * @param SplFileInfo $file |
||
37 | */ |
||
38 | public function __construct(SplFileInfo $file) |
||
42 | |||
43 | /** |
||
44 | * Parse the contents of the file. |
||
45 | * |
||
46 | * Example: |
||
47 | * --- |
||
48 | * title: Title |
||
49 | * date: 2016-07-29 |
||
50 | * --- |
||
51 | * Lorem Ipsum. |
||
52 | * |
||
53 | * @throws \RuntimeException |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | public function parse() |
||
80 | |||
81 | /** |
||
82 | * Get frontmatter. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getFrontmatter() |
||
90 | |||
91 | /** |
||
92 | * Get body. |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getBody() |
||
100 | } |
||
101 |