1 | <?php |
||
29 | class Stitcher |
||
30 | { |
||
31 | /** |
||
32 | * A collection of promises representing Stitcher's state. |
||
33 | * |
||
34 | * @var Promise[] |
||
35 | */ |
||
36 | private $promises = []; |
||
37 | |||
38 | /** |
||
39 | * @var ContainerBuilder |
||
40 | */ |
||
41 | protected static $container; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | private $srcDir; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | private $publicDir; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | private $templateDir; |
||
57 | |||
58 | /** |
||
59 | * @see \Brendt\Stitcher\Stitcher::create() |
||
60 | * |
||
61 | * @param string $srcDir |
||
62 | * @param string $publicDir |
||
63 | * @param string $templateDir |
||
64 | */ |
||
65 | private function __construct(string $srcDir = './src', string $publicDir = './public', ?string $templateDir = './src') { |
||
70 | |||
71 | /** |
||
72 | * Static constructor |
||
73 | * |
||
74 | * @param string $configPath |
||
75 | * |
||
76 | * @return Stitcher |
||
77 | */ |
||
78 | public static function create($configPath = './config.yml') : Stitcher { |
||
107 | |||
108 | /** |
||
109 | * @param string $id |
||
110 | * |
||
111 | * @return mixed |
||
112 | */ |
||
113 | public static function get(string $id) { |
||
116 | |||
117 | /** |
||
118 | * The core stitcher function. This function will compile the configured site and return an array of parsed |
||
119 | * data. |
||
120 | * |
||
121 | * Compiling a site is done in the following steps. |
||
122 | * |
||
123 | * - Load the site configuration @see \Brendt\Stitcher\Stitcher::loadSite() |
||
124 | * - Load all available templates @see \Brendt\Stitcher\Stitcher::loadTemplates() |
||
125 | * - Loop over all pages and transform every page with the configured adapters (in any are set) @see |
||
126 | * \Brendt\Stitcher\Stitcher::parseAdapters() |
||
127 | * - Loop over all transformed pages and parse the variables which weren't parsed by the page's adapters. @see |
||
128 | * \Brendt\Stitcher\Stitcher::parseVariables() |
||
129 | * - Add all variables to the template engine and render the HTML for each page. |
||
130 | * |
||
131 | * This function takes two optional parameters which are used to render pages on the fly when using the |
||
132 | * developer controller. The first one, `routes` will take a string or array of routes which should be rendered, |
||
133 | * instead of all available routes. The second one, `filterValue` is used to provide a filter when the |
||
134 | * CollectionAdapter is used, and only one entry page should be rendered. |
||
135 | * |
||
136 | * @param string|array $routes |
||
137 | * @param string $filterValue |
||
138 | * |
||
139 | * @return array |
||
140 | * @throws TemplateNotFoundException |
||
141 | * |
||
142 | * @see \Brendt\Stitcher\Stitcher::save() |
||
143 | * @see \Brendt\Stitcher\Controller\DevController::run() |
||
144 | * @see \Brendt\Stitcher\Adapter\CollectionAdapter::transform() |
||
145 | */ |
||
146 | public function stitch(array $routes = [], string $filterValue = null) { |
||
193 | |||
194 | /** |
||
195 | * Load a site from YAML configuration files in the `directories.src`/site directory. |
||
196 | * All YAML files are loaded and parsed into Page objects and added to a Site collection. |
||
197 | * |
||
198 | * @return Site |
||
199 | * @throws InvalidSiteException |
||
200 | * |
||
201 | * @see \Brendt\Stitcher\Site\Page |
||
202 | * @see \Brendt\Stitcher\Site\Site |
||
203 | */ |
||
204 | public function loadSite() { |
||
228 | |||
229 | /** |
||
230 | * Load all templates from either the `directories.template` directory. Depending on the configured template |
||
231 | * engine, set with `engines.template`; .html or .tpl files will be loaded. |
||
232 | * |
||
233 | * @return SplFileInfo[] |
||
234 | */ |
||
235 | public function loadTemplates() { |
||
249 | |||
250 | /** |
||
251 | * This function takes a page and optional entry id. The page's adapters will be loaded and looped. |
||
252 | * An adapter will transform a page's original configuration and variables to one or more pages. |
||
253 | * An entry id can be provided as a filter. This filter can be used in an adapter to skip rendering unnecessary |
||
254 | * pages. The filter parameter is used to render pages on the fly when using the developer controller. |
||
255 | * |
||
256 | * @param Page $page |
||
257 | * @param string $entryId |
||
258 | * |
||
259 | * @return Page[] |
||
260 | * |
||
261 | * @see \Brendt\Stitcher\Adapter\Adapter::transform() |
||
262 | * @see \Brendt\Stitcher\Controller\DevController::run() |
||
263 | */ |
||
264 | public function parseAdapters(Page $page, $entryId = null) { |
||
284 | |||
285 | /** |
||
286 | * This function takes a Page object and parse its variables using a Parser. It will only parse variables which |
||
287 | * weren't parsed already by an adapter. |
||
288 | * |
||
289 | * @param Page $page |
||
290 | * |
||
291 | * @return Page |
||
292 | * |
||
293 | * @see \Brendt\Stitcher\Factory\ParserFactory |
||
294 | * @see \Brendt\Stitcher\Parser\Parser |
||
295 | * @see \Brendt\Stitcher\Site\Page::isParsedVariable() |
||
296 | */ |
||
297 | public function parseVariables(Page $page) { |
||
310 | |||
311 | /** |
||
312 | * This function will save a stitched output to HTML files in the `directories.public` directory. |
||
313 | * |
||
314 | * @param array $blanket |
||
315 | * |
||
316 | * @see \Brendt\Stitcher\Stitcher::stitch() |
||
317 | */ |
||
318 | public function save(array $blanket) { |
||
333 | |||
334 | /** |
||
335 | * This function will get the parser based on the value. This value is parsed by the parser, or returned if no |
||
336 | * suitable parser was found. |
||
337 | * |
||
338 | * @param $value |
||
339 | * |
||
340 | * @return mixed |
||
341 | * |
||
342 | * @see \Brendt\Stitcher\Factory\ParserFactory |
||
343 | */ |
||
344 | private function getData($value) { |
||
355 | |||
356 | /** |
||
357 | * @param Promise $promise |
||
358 | * |
||
359 | * @return Stitcher |
||
360 | */ |
||
361 | public function addPromise(?Promise $promise) : Stitcher { |
||
368 | |||
369 | /** |
||
370 | * @param callable $callback |
||
371 | */ |
||
372 | public function done(callable $callback) { |
||
377 | |||
378 | } |
||
379 | |||
381 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: