1 | <?php |
||
24 | class SiteParser |
||
25 | { |
||
26 | const EVENT_PARSER_INIT = 'parser.initialised'; |
||
27 | |||
28 | const EVENT_PAGE_PARSING = 'page.parsing'; |
||
29 | |||
30 | const EVENT_PAGE_PARSED = 'page.parsed'; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $filter; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $srcDir; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $templateDir; |
||
46 | |||
47 | /** |
||
48 | * @var ParserFactory |
||
49 | */ |
||
50 | private $parserFactory; |
||
51 | |||
52 | /** |
||
53 | * @var TemplateEngineFactory |
||
54 | */ |
||
55 | private $templateEngineFactory; |
||
56 | |||
57 | /** |
||
58 | * @var AdapterFactory |
||
59 | */ |
||
60 | private $adapterFactory; |
||
61 | |||
62 | /** |
||
63 | * @var HeaderCompilerFactory |
||
64 | */ |
||
65 | private $headerCompilerFactory; |
||
66 | |||
67 | /** |
||
68 | * @var array |
||
69 | */ |
||
70 | private $metaConfig; |
||
71 | |||
72 | /** |
||
73 | * @var TemplatePlugin |
||
74 | */ |
||
75 | private $templatePlugin; |
||
76 | |||
77 | /** |
||
78 | * @var HeaderCompiler|null |
||
79 | */ |
||
80 | private $headerCompiler; |
||
81 | |||
82 | /** |
||
83 | * @var TemplateEngine |
||
84 | */ |
||
85 | private $templateEngine; |
||
86 | |||
87 | /** |
||
88 | * @var SplFileInfo[] |
||
89 | */ |
||
90 | private $templates; |
||
91 | |||
92 | /** |
||
93 | * @var MetaCompiler |
||
94 | */ |
||
95 | private $metaCompiler; |
||
96 | |||
97 | /** |
||
98 | * @var EventDispatcher |
||
99 | */ |
||
100 | private $eventDispatcher; |
||
101 | |||
102 | /** |
||
103 | * SiteParser constructor. |
||
104 | * |
||
105 | * @param string $srcDir |
||
106 | * @param string $templateDir |
||
107 | * @param TemplatePlugin $templatePlugin |
||
108 | * @param ParserFactory $parserFactory |
||
109 | * @param TemplateEngineFactory $templateEngineFactory |
||
110 | * @param AdapterFactory $adapterFactory |
||
111 | * @param HeaderCompilerFactory $headerCompilerFactory |
||
112 | * @param MetaCompiler $metaCompiler |
||
113 | * @param EventDispatcher $eventDispatcher |
||
114 | * @param array $metaConfig |
||
115 | */ |
||
116 | public function __construct( |
||
143 | |||
144 | /** |
||
145 | * Load a site from YAML configuration files in the `directories.src`/site directory. |
||
146 | * All YAML files are loaded and parsed into Page objects and added to a Site collection. |
||
147 | * |
||
148 | * @param array $routes |
||
149 | * |
||
150 | * @return Site |
||
151 | * @throws InvalidSiteException |
||
152 | * @see \Brendt\Stitcher\Site\Page |
||
153 | * @see \Brendt\Stitcher\Site\Site |
||
154 | */ |
||
155 | public function loadSite(array $routes = []) : Site { |
||
179 | |||
180 | /** |
||
181 | * Load all templates from either the `directories.template` directory. Depending on the configured template |
||
182 | * engine, set with `engines.template`; .html or .tpl files will be loaded. |
||
183 | * |
||
184 | * @return SplFileInfo[] |
||
185 | */ |
||
186 | public function loadTemplates() { |
||
200 | |||
201 | /** |
||
202 | * Parse a path into usable data. |
||
203 | * |
||
204 | * @param array $routes |
||
205 | * @param string $filterValue |
||
206 | * |
||
207 | * @return array|mixed |
||
208 | * @throws TemplateNotFoundException |
||
209 | */ |
||
210 | public function parse($routes = [], string $filterValue = null) : array { |
||
241 | |||
242 | /** |
||
243 | * @param Page $page |
||
244 | * |
||
245 | * @return string |
||
246 | */ |
||
247 | public function parsePage(Page $page) : string { |
||
265 | |||
266 | /** |
||
267 | * This function takes a page and optional entry id. The page's adapters will be loaded and looped. |
||
268 | * An adapter will transform a page's original configuration and variables to one or more pages. |
||
269 | * An entry id can be provided as a filter. This filter can be used in an adapter to skip rendering unnecessary |
||
270 | * pages. The filter parameter is used to render pages on the fly when using the developer controller. |
||
271 | * |
||
272 | * @param Page $page |
||
273 | * @param string $entryId |
||
274 | * |
||
275 | * @return Page[] |
||
276 | * |
||
277 | * @see \Brendt\Stitcher\Adapter\Adapter::transform() |
||
278 | * @see \Brendt\Stitcher\Application\DevController::run() |
||
279 | */ |
||
280 | public function parseAdapters(Page $page, $entryId = null) { |
||
299 | |||
300 | /** |
||
301 | * This function takes a Page object and parse its variables using a Parser. It will only parse variables which |
||
302 | * weren't parsed already by an adapter. |
||
303 | * |
||
304 | * @param Page $page |
||
305 | * |
||
306 | * @return Page |
||
307 | * |
||
308 | * @see \Brendt\Stitcher\Factory\ParserFactory |
||
309 | * @see \Brendt\Stitcher\Parser\Parser |
||
310 | * @see \Brendt\Stitcher\Site\Page::isParsedVariable() |
||
311 | */ |
||
312 | public function parseVariables(Page $page) { |
||
325 | |||
326 | /** |
||
327 | * @param string $filter |
||
328 | * |
||
329 | * @return SiteParser |
||
330 | */ |
||
331 | public function setFilter(string $filter) : SiteParser { |
||
336 | |||
337 | /** |
||
338 | * This function will get the parser based on the value. This value is parsed by the parser, or returned if no |
||
339 | * suitable parser was found. |
||
340 | * |
||
341 | * @param $value |
||
342 | * |
||
343 | * @return mixed |
||
344 | * |
||
345 | * @see \Brendt\Stitcher\Factory\ParserFactory |
||
346 | */ |
||
347 | private function getData($value) { |
||
356 | |||
357 | private function createMeta() : Meta { |
||
362 | } |
||
363 |