1 | <?php |
||
23 | class Stitcher |
||
24 | { |
||
25 | /** |
||
26 | * @var ContainerBuilder |
||
27 | */ |
||
28 | protected static $container; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | protected static $configDefaults = [ |
||
34 | 'directories.src' => './src', |
||
35 | 'directories.public' => './public', |
||
36 | 'directories.cache' => './.cache', |
||
37 | 'meta' => [], |
||
38 | 'minify' => false, |
||
39 | 'engines.template' => 'smarty', |
||
40 | 'engines.image' => 'gd', |
||
41 | 'engines.optimizer' => true, |
||
42 | 'engines.async' => true, |
||
43 | 'caches.image' => true, |
||
44 | 'optimizer.options' => [], |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * A collection of promises representing Stitcher's state. |
||
49 | * |
||
50 | * @var Promise[] |
||
51 | */ |
||
52 | private $promises = []; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | private $srcDir; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | private $publicDir; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | private $templateDir; |
||
68 | |||
69 | /** |
||
70 | * @var SiteParser |
||
71 | */ |
||
72 | private $siteParser; |
||
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 { |
||
137 | |||
138 | /** |
||
139 | * @param string $id |
||
140 | * |
||
141 | * @return mixed |
||
142 | */ |
||
143 | public static function get(string $id) { |
||
146 | |||
147 | /** |
||
148 | * @param string $key |
||
149 | * |
||
150 | * @return mixed |
||
151 | */ |
||
152 | public static function getParameter(string $key) { |
||
155 | |||
156 | /** |
||
157 | * The core stitcher function. This function will compile the configured site and return an array of parsed |
||
158 | * data. |
||
159 | * |
||
160 | * Compiling a site is done in the following steps. |
||
161 | * |
||
162 | * - Load the site configuration @see \Brendt\Stitcher\Stitcher::loadSite() |
||
163 | * - Load all available templates @see \Brendt\Stitcher\Stitcher::loadTemplates() |
||
164 | * - Loop over all pages and transform every page with the configured adapters (in any are set) @see |
||
165 | * \Brendt\Stitcher\Stitcher::parseAdapters() |
||
166 | * - Loop over all transformed pages and parse the variables which weren't parsed by the page's adapters. @see |
||
167 | * \Brendt\Stitcher\Stitcher::parseVariables() |
||
168 | * - Add all variables to the template engine and render the HTML for each page. |
||
169 | * |
||
170 | * This function takes two optional parameters which are used to render pages on the fly when using the |
||
171 | * developer controller. The first one, `routes` will take a string or array of routes which should be rendered, |
||
172 | * instead of all available routes. The second one, `filterValue` is used to provide a filter when the |
||
173 | * CollectionAdapter is used, and only one entry page should be rendered. |
||
174 | * |
||
175 | * @param string|array $routes |
||
176 | * @param string $filterValue |
||
177 | * |
||
178 | * @return array |
||
179 | * @throws TemplateNotFoundException |
||
180 | * |
||
181 | * @see \Brendt\Stitcher\Stitcher::save() |
||
182 | * @see \Brendt\Stitcher\Controller\DevController::run() |
||
183 | * @see \Brendt\Stitcher\Adapter\CollectionAdapter::transform() |
||
184 | */ |
||
185 | public function stitch($routes = [], string $filterValue = null) : array { |
||
191 | |||
192 | /** |
||
193 | * @param array $routes |
||
194 | * |
||
195 | * @return Site |
||
196 | */ |
||
197 | public function loadSite(array $routes = []) : Site { |
||
203 | |||
204 | /** |
||
205 | * This function will save a stitched output to HTML files in the `directories.public` directory. |
||
206 | * |
||
207 | * @param array $blanket |
||
208 | * |
||
209 | * @see \Brendt\Stitcher\Stitcher::stitch() |
||
210 | */ |
||
211 | public function save(array $blanket) { |
||
222 | |||
223 | // /** |
||
224 | // * @param Promise|null $promise |
||
225 | // * |
||
226 | // * @return Stitcher |
||
227 | // */ |
||
228 | // public function addPromise(?Promise $promise) : Stitcher { |
||
229 | // if ($promise) { |
||
230 | // $this->promises[] = $promise; |
||
231 | // } |
||
232 | // |
||
233 | // return $this; |
||
234 | // } |
||
235 | |||
236 | // /** |
||
237 | // * @return Promise |
||
238 | // */ |
||
239 | // public function getPromise() : Promise { |
||
240 | // return \Amp\all($this->promises); |
||
241 | // } |
||
242 | |||
243 | // /** |
||
244 | // * @param callable $callback |
||
245 | // */ |
||
246 | // public function done(callable $callback) { |
||
247 | // $donePromise = $this->getPromise(); |
||
248 | // |
||
249 | // $donePromise->when($callback); |
||
250 | // } |
||
251 | |||
252 | } |
||
253 | |||
255 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.