1 | <?php |
||
29 | class Stitcher |
||
30 | { |
||
31 | /** |
||
32 | * @var ContainerBuilder |
||
33 | */ |
||
34 | protected static $container; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected static $configDefaults = [ |
||
40 | 'directories.src' => './src', |
||
41 | 'directories.public' => './public', |
||
42 | 'directories.cache' => './.cache', |
||
43 | 'meta' => [], |
||
44 | 'minify' => false, |
||
45 | 'engines.template' => 'smarty', |
||
46 | 'engines.image' => 'gd', |
||
47 | 'engines.optimizer' => true, |
||
48 | 'engines.async' => true, |
||
49 | 'caches.image' => true, |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * A collection of promises representing Stitcher's state. |
||
54 | * |
||
55 | * @var Promise[] |
||
56 | */ |
||
57 | private $promises = []; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | private $srcDir; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | private $publicDir; |
||
68 | |||
69 | /** |
||
70 | * @var string |
||
71 | */ |
||
72 | private $templateDir; |
||
73 | |||
74 | /** |
||
75 | * @see \Brendt\Stitcher\Stitcher::create() |
||
76 | * |
||
77 | * @param string $srcDir |
||
78 | * @param string $publicDir |
||
79 | * @param string $templateDir |
||
80 | */ |
||
81 | private function __construct(?string $srcDir = './src', ?string $publicDir = './public', ?string $templateDir = './src/template') { |
||
86 | |||
87 | /** |
||
88 | * Static constructor |
||
89 | * |
||
90 | * @param string $configPath |
||
91 | * @param array $defaultConfig |
||
92 | * |
||
93 | * @return Stitcher |
||
94 | * |
||
95 | */ |
||
96 | public static function create(string $configPath = './config.yml', array $defaultConfig = []) : Stitcher { |
||
141 | |||
142 | /** |
||
143 | * @param string $id |
||
144 | * |
||
145 | * @return mixed |
||
146 | */ |
||
147 | public static function get(string $id) { |
||
150 | |||
151 | /** |
||
152 | * @param string $key |
||
153 | * |
||
154 | * @return mixed |
||
155 | */ |
||
156 | public static function getParameter(string $key) { |
||
159 | |||
160 | /** |
||
161 | * The core stitcher function. This function will compile the configured site and return an array of parsed |
||
162 | * data. |
||
163 | * |
||
164 | * Compiling a site is done in the following steps. |
||
165 | * |
||
166 | * - Load the site configuration @see \Brendt\Stitcher\Stitcher::loadSite() |
||
167 | * - Load all available templates @see \Brendt\Stitcher\Stitcher::loadTemplates() |
||
168 | * - Loop over all pages and transform every page with the configured adapters (in any are set) @see |
||
169 | * \Brendt\Stitcher\Stitcher::parseAdapters() |
||
170 | * - Loop over all transformed pages and parse the variables which weren't parsed by the page's adapters. @see |
||
171 | * \Brendt\Stitcher\Stitcher::parseVariables() |
||
172 | * - Add all variables to the template engine and render the HTML for each page. |
||
173 | * |
||
174 | * This function takes two optional parameters which are used to render pages on the fly when using the |
||
175 | * developer controller. The first one, `routes` will take a string or array of routes which should be rendered, |
||
176 | * instead of all available routes. The second one, `filterValue` is used to provide a filter when the |
||
177 | * CollectionAdapter is used, and only one entry page should be rendered. |
||
178 | * |
||
179 | * @param string|array $routes |
||
180 | * @param string $filterValue |
||
181 | * |
||
182 | * @return array |
||
183 | * @throws TemplateNotFoundException |
||
184 | * |
||
185 | * @see \Brendt\Stitcher\Stitcher::save() |
||
186 | * @see \Brendt\Stitcher\Controller\DevController::run() |
||
187 | * @see \Brendt\Stitcher\Adapter\CollectionAdapter::transform() |
||
188 | */ |
||
189 | public function stitch($routes = [], string $filterValue = null) { |
||
224 | |||
225 | /** |
||
226 | * Load a site from YAML configuration files in the `directories.src`/site directory. |
||
227 | * All YAML files are loaded and parsed into Page objects and added to a Site collection. |
||
228 | * |
||
229 | * @param array $routes |
||
230 | * |
||
231 | * @return Site |
||
232 | * @throws InvalidSiteException |
||
233 | * @see \Brendt\Stitcher\Site\Page |
||
234 | * @see \Brendt\Stitcher\Site\Site |
||
235 | */ |
||
236 | public function loadSite(array $routes = []) : Site { |
||
260 | |||
261 | /** |
||
262 | * Load all templates from either the `directories.template` directory. Depending on the configured template |
||
263 | * engine, set with `engines.template`; .html or .tpl files will be loaded. |
||
264 | * |
||
265 | * @return SplFileInfo[] |
||
266 | */ |
||
267 | public function loadTemplates() { |
||
284 | |||
285 | /** |
||
286 | * This function takes a page and optional entry id. The page's adapters will be loaded and looped. |
||
287 | * An adapter will transform a page's original configuration and variables to one or more pages. |
||
288 | * An entry id can be provided as a filter. This filter can be used in an adapter to skip rendering unnecessary |
||
289 | * pages. The filter parameter is used to render pages on the fly when using the developer controller. |
||
290 | * |
||
291 | * @param Page $page |
||
292 | * @param string $entryId |
||
293 | * |
||
294 | * @return Page[] |
||
295 | * |
||
296 | * @see \Brendt\Stitcher\Adapter\Adapter::transform() |
||
297 | * @see \Brendt\Stitcher\Controller\DevController::run() |
||
298 | */ |
||
299 | public function parseAdapters(Page $page, $entryId = null) { |
||
319 | |||
320 | /** |
||
321 | * This function takes a Page object and parse its variables using a Parser. It will only parse variables which |
||
322 | * weren't parsed already by an adapter. |
||
323 | * |
||
324 | * @param Page $page |
||
325 | * |
||
326 | * @return Page |
||
327 | * |
||
328 | * @see \Brendt\Stitcher\Factory\ParserFactory |
||
329 | * @see \Brendt\Stitcher\Parser\Parser |
||
330 | * @see \Brendt\Stitcher\Site\Page::isParsedVariable() |
||
331 | */ |
||
332 | public function parseVariables(Page $page) { |
||
345 | |||
346 | /** |
||
347 | * This function will save a stitched output to HTML files in the `directories.public` directory. |
||
348 | * |
||
349 | * @param array $blanket |
||
350 | * |
||
351 | * @see \Brendt\Stitcher\Stitcher::stitch() |
||
352 | */ |
||
353 | public function save(array $blanket) { |
||
364 | |||
365 | /** |
||
366 | * This function will get the parser based on the value. This value is parsed by the parser, or returned if no |
||
367 | * suitable parser was found. |
||
368 | * |
||
369 | * @param $value |
||
370 | * |
||
371 | * @return mixed |
||
372 | * |
||
373 | * @see \Brendt\Stitcher\Factory\ParserFactory |
||
374 | */ |
||
375 | private function getData($value) { |
||
386 | |||
387 | /** |
||
388 | * @param Promise|null $promise |
||
389 | * |
||
390 | * @return Stitcher |
||
391 | */ |
||
392 | public function addPromise(?Promise $promise) : Stitcher { |
||
399 | |||
400 | /** |
||
401 | * @return Promise |
||
402 | */ |
||
403 | public function getPromise() : Promise { |
||
406 | |||
407 | /** |
||
408 | * @param callable $callback |
||
409 | */ |
||
410 | public function done(callable $callback) { |
||
415 | |||
416 | } |
||
417 | |||
419 |
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: