1 | <?php |
||
26 | class Stitcher { |
||
27 | |||
28 | /** |
||
29 | * A collection of all templates available when rendering a Stitcher application. |
||
30 | * |
||
31 | * @var SplFileInfo[] |
||
32 | */ |
||
33 | protected $templates; |
||
34 | |||
35 | /** |
||
36 | * The template engine which is configured via `engines.template`. |
||
37 | * |
||
38 | * @var TemplateEngine |
||
39 | */ |
||
40 | private $templateEngine; |
||
41 | |||
42 | /** |
||
43 | * Stitcher constructor. |
||
44 | */ |
||
45 | public function __construct() { |
||
51 | |||
52 | /** |
||
53 | * The core stitcher function. This function will compile the configured site and return an array of parsed |
||
54 | * data. |
||
55 | * |
||
56 | * Compiling a site is done in the following steps. |
||
57 | * |
||
58 | * - Load the site configuration @see \Brendt\Stitcher\Stitcher::loadSite() |
||
59 | * - Load all available templates @see \Brendt\Stitcher\Stitcher::loadTemplates() |
||
60 | * - Loop over all pages and transform every page with the configured adapters (in any are set) @see |
||
61 | * \Brendt\Stitcher\Stitcher::parseAdapters() |
||
62 | * - Loop over all transformed pages and parse the variables which weren't parsed by the page's adapters. @see |
||
63 | * \Brendt\Stitcher\Stitcher::parseVariables() |
||
64 | * - Add all variables to the template engine and render the HTML for each page. |
||
65 | * |
||
66 | * This function takes two optional parameters which are used to render pages on the fly when using the |
||
67 | * developer controller. The first one, `routes` will take a string or array of routes which should be rendered, |
||
68 | * instead of all available routes. The second one, `filterValue` is used to provide a filter when the |
||
69 | * CollectionAdapter is used, and only one entry page should be rendered. |
||
70 | * |
||
71 | * @param string|array $routes |
||
72 | * @param string $filterValue |
||
73 | * |
||
74 | * @return array |
||
75 | * @throws TemplateNotFoundException |
||
76 | * |
||
77 | * @see \Brendt\Stitcher\Stitcher::save() |
||
78 | * @see \Brendt\Stitcher\Controller\DevController::run() |
||
79 | * @see \Brendt\Stitcher\Adapter\CollectionAdapter::transform() |
||
80 | */ |
||
81 | public function stitch($routes = [], $filterValue = null) { |
||
124 | |||
125 | /** |
||
126 | * Load a site from YAML configuration files in the `directories.src`/site directory. |
||
127 | * All YAML files are loaded and parsed into Page objects and added to a Site collection. |
||
128 | * |
||
129 | * @return Site |
||
130 | * @throws InvalidSiteException |
||
131 | * |
||
132 | * @see \Brendt\Stitcher\Site\Page |
||
133 | * @see \Brendt\Stitcher\Site\Site |
||
134 | */ |
||
135 | public function loadSite() { |
||
159 | |||
160 | /** |
||
161 | * Load all templates from either the `directories.template` directory. Depending on the configured template |
||
162 | * engine, set with `engines.template`; .html or .tpl files will be loaded. |
||
163 | * |
||
164 | * @return SplFileInfo[] |
||
165 | */ |
||
166 | public function loadTemplates() { |
||
179 | |||
180 | /** |
||
181 | * This function takes a page and optional entry id. The page's adapters will be loaded and looped. |
||
182 | * An adapter will transform a page's original configuration and variables to one or more pages. |
||
183 | * An entry id can be provided as a filter. This filter can be used in an adapter to skip rendering unnecessary |
||
184 | * pages. The filter parameter is used to render pages on the fly when using the developer controller. |
||
185 | * |
||
186 | * @param Page $page |
||
187 | * @param string $entryId |
||
188 | * |
||
189 | * @return Page[] |
||
190 | * |
||
191 | * @see \Brendt\Stitcher\Adapter\Adapter::transform() |
||
192 | * @see \Brendt\Stitcher\Controller\DevController::run() |
||
193 | * |
||
194 | * @todo When a page has multiple adapters, this function won't correctly parse more than one. This is considered a |
||
195 | * bug, but not a major one because there are only two adapters at this moment, and they can not be used |
||
196 | * together anyway. |
||
197 | * |
||
198 | */ |
||
199 | public function parseAdapters(Page $page, $entryId = null) { |
||
220 | |||
221 | /** |
||
222 | * This function takes a Page object and parse its variables using a Parser. It will only parse variables which |
||
223 | * weren't parsed already by an adapter. |
||
224 | * |
||
225 | * @param Page $page |
||
226 | * |
||
227 | * @return Page |
||
228 | * |
||
229 | * @see \Brendt\Stitcher\Factory\ParserFactory |
||
230 | * @see \Brendt\Stitcher\Parser\Parser |
||
231 | * @see \Brendt\Stitcher\Site\Page::isParsedVariable() |
||
232 | */ |
||
233 | public function parseVariables(Page $page) { |
||
246 | |||
247 | /** |
||
248 | * This function will save a stitched output to HTML files in the `directories.public` directory. |
||
249 | * |
||
250 | * @param array $blanket |
||
251 | * |
||
252 | * @see \Brendt\Stitcher\Stitcher::stitch() |
||
253 | */ |
||
254 | public function save(array $blanket) { |
||
270 | |||
271 | /** |
||
272 | * This function will get the parser based on the value. This value is parsed by the parser, or returned if no |
||
273 | * suitable parser was found. |
||
274 | * |
||
275 | * @param $value |
||
276 | * |
||
277 | * @return mixed |
||
278 | * |
||
279 | * @see \Brendt\Stitcher\Factory\ParserFactory |
||
280 | */ |
||
281 | private function getData($value) { |
||
292 | |||
293 | } |
||
294 | |||
296 |