Total Complexity | 100 |
Total Lines | 647 |
Duplicated Lines | 0 % |
Changes | 19 | ||
Bugs | 3 | Features | 0 |
Complex classes like Asset often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Asset, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class Asset implements \ArrayAccess |
||
24 | { |
||
25 | /** @var Builder */ |
||
26 | protected $builder; |
||
27 | |||
28 | /** @var Config */ |
||
29 | protected $config; |
||
30 | |||
31 | /** @var array */ |
||
32 | protected $data = []; |
||
33 | |||
34 | /** @var bool */ |
||
35 | protected $optimized = false; |
||
36 | |||
37 | /** @var bool */ |
||
38 | protected $fingerprinted = false; |
||
39 | |||
40 | /** @var bool */ |
||
41 | protected $compiled = false; |
||
42 | |||
43 | /** @var bool */ |
||
44 | protected $minified = false; |
||
45 | |||
46 | /** @var bool */ |
||
47 | protected $ignore_missing = false; |
||
48 | |||
49 | /** |
||
50 | * Creates an Asset from file(s) path. |
||
51 | * |
||
52 | * $options[ |
||
53 | * 'fingerprint' => true, |
||
54 | * 'minify' => true, |
||
55 | * 'filename' => '', |
||
56 | * 'ignore_missing' => false, |
||
57 | * ]; |
||
58 | * |
||
59 | * @param Builder $builder |
||
60 | * @param string|array $paths |
||
61 | * @param array|null $options |
||
62 | */ |
||
63 | public function __construct(Builder $builder, $paths, array $options = null) |
||
64 | { |
||
65 | $this->builder = $builder; |
||
66 | $this->config = $builder->getConfig(); |
||
67 | $paths = is_array($paths) ? $paths : [$paths]; |
||
68 | array_walk($paths, function ($path) { |
||
69 | if (empty($path)) { |
||
70 | throw new Exception('The path parameter of "asset() can\'t be empty."'); |
||
71 | } |
||
72 | }); |
||
73 | $this->data = [ |
||
74 | 'file' => '', |
||
75 | 'filename' => '', |
||
76 | 'path_source' => '', |
||
77 | 'path' => '', |
||
78 | 'ext' => '', |
||
79 | 'type' => '', |
||
80 | 'subtype' => '', |
||
81 | 'size' => 0, |
||
82 | 'content_source' => '', |
||
83 | 'content' => '', |
||
84 | ]; |
||
85 | |||
86 | // handles options |
||
87 | $optimize = (bool) $this->config->get('assets.images.optimize.enabled'); |
||
88 | $fingerprint = (bool) $this->config->get('assets.fingerprint.enabled'); |
||
89 | $minify = (bool) $this->config->get('assets.minify.enabled'); |
||
90 | $filename = ''; |
||
91 | $ignore_missing = false; |
||
92 | extract(is_array($options) ? $options : [], EXTR_IF_EXISTS); |
||
93 | $this->ignore_missing = $ignore_missing; |
||
94 | |||
95 | // fill data array with file(s) informations |
||
96 | $cache = new Cache($this->builder, 'assets'); |
||
97 | $cacheKey = sprintf('%s.ser', implode('_', $paths)); |
||
98 | if (!$cache->has($cacheKey)) { |
||
99 | $pathsCount = count($paths); |
||
100 | $file = []; |
||
101 | for ($i = 0; $i < $pathsCount; $i++) { |
||
102 | // loads file(s) |
||
103 | $file[$i] = $this->loadFile($paths[$i], $ignore_missing); |
||
104 | // bundle: same type/ext only |
||
105 | if ($i > 0) { |
||
106 | if ($file[$i]['type'] != $file[$i - 1]['type']) { |
||
107 | throw new Exception(\sprintf('Asset bundle type error (%s != %s).', $file[$i]['type'], $file[$i - 1]['type'])); |
||
108 | } |
||
109 | if ($file[$i]['ext'] != $file[$i - 1]['ext']) { |
||
110 | throw new Exception(\sprintf('Asset bundle extension error (%s != %s).', $file[$i]['ext'], $file[$i - 1]['ext'])); |
||
111 | } |
||
112 | } |
||
113 | // missing allowed = empty path |
||
114 | if ($file[$i]['missing']) { |
||
115 | $this->data['path'] = ''; |
||
116 | |||
117 | continue; |
||
118 | } |
||
119 | // set data |
||
120 | if ($i == 0) { |
||
121 | $this->data['file'] = $file[$i]['filepath']; // should be an array of files in case of bundle? |
||
122 | $this->data['filename'] = $file[$i]['path']; |
||
123 | $this->data['path_source'] = $file[$i]['path']; |
||
124 | $this->data['path'] = $file[$i]['path']; |
||
125 | if (!empty($filename)) { |
||
126 | $this->data['path'] = '/'.ltrim($filename, '/'); |
||
127 | } |
||
128 | $this->data['ext'] = $file[$i]['ext']; |
||
129 | $this->data['type'] = $file[$i]['type']; |
||
130 | $this->data['subtype'] = $file[$i]['subtype']; |
||
131 | } |
||
132 | $this->data['size'] += $file[$i]['size']; |
||
133 | $this->data['content_source'] .= $file[$i]['content']; |
||
134 | $this->data['content'] .= $file[$i]['content']; |
||
135 | } |
||
136 | // bundle: define path |
||
137 | if ($pathsCount > 1) { |
||
138 | if (empty($filename)) { |
||
139 | switch ($this->data['ext']) { |
||
140 | case 'scss': |
||
141 | case 'css': |
||
142 | $this->data['path'] = '/styles.'.$file[0]['ext']; |
||
143 | break; |
||
144 | case 'js': |
||
145 | $this->data['path'] = '/scripts.'.$file[0]['ext']; |
||
146 | break; |
||
147 | default: |
||
148 | throw new Exception(\sprintf('Asset bundle supports "%s" files only.', 'scss, css and js')); |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | $cache->set($cacheKey, $this->data); |
||
153 | } |
||
154 | $this->data = $cache->get($cacheKey); |
||
155 | |||
156 | // optimizing |
||
157 | if ($optimize) { |
||
158 | $this->optimize(); |
||
159 | } |
||
160 | // fingerprinting |
||
161 | if ($fingerprint) { |
||
162 | $this->fingerprint(); |
||
163 | } |
||
164 | // compiling |
||
165 | if ((bool) $this->config->get('assets.compile.enabled')) { |
||
166 | $this->compile(); |
||
167 | } |
||
168 | // minifying |
||
169 | if ($minify) { |
||
170 | $this->minify(); |
||
171 | } |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Returns path. |
||
176 | */ |
||
177 | public function __toString(): string |
||
178 | { |
||
179 | try { |
||
180 | $this->save(); |
||
181 | } catch (Exception $e) { |
||
182 | $this->builder->getLogger()->error($e->getMessage()); |
||
183 | } |
||
184 | |||
185 | return $this->data['path']; |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Fingerprints a file. |
||
190 | */ |
||
191 | public function fingerprint(): self |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * Compiles a SCSS. |
||
211 | */ |
||
212 | public function compile(): self |
||
213 | { |
||
214 | if ($this->compiled) { |
||
215 | return $this; |
||
216 | } |
||
217 | |||
218 | if ($this->data['ext'] != 'scss') { |
||
219 | return $this; |
||
220 | } |
||
221 | |||
222 | $cache = new Cache($this->builder, 'assets'); |
||
223 | $cacheKey = $cache->createKeyFromAsset($this, 'compiled'); |
||
224 | if (!$cache->has($cacheKey)) { |
||
225 | $scssPhp = new Compiler(); |
||
226 | $importDir = []; |
||
227 | $importDir[] = Util::joinPath($this->config->getStaticPath()); |
||
228 | $importDir[] = Util::joinPath($this->config->getAssetsPath()); |
||
229 | $scssDir = $this->config->get('assets.compile.import') ?? []; |
||
230 | $themes = $this->config->getTheme() ?? []; |
||
231 | foreach ($scssDir as $dir) { |
||
232 | $importDir[] = Util::joinPath($this->config->getStaticPath(), $dir); |
||
233 | $importDir[] = Util::joinPath($this->config->getAssetsPath(), $dir); |
||
234 | $importDir[] = Util::joinPath(dirname($this->data['file']), $dir); |
||
235 | foreach ($themes as $theme) { |
||
236 | $importDir[] = Util::joinPath($this->config->getThemeDirPath($theme, "static/$dir")); |
||
237 | $importDir[] = Util::joinPath($this->config->getThemeDirPath($theme, "assets/$dir")); |
||
238 | } |
||
239 | } |
||
240 | $scssPhp->setImportPaths(array_unique($importDir)); |
||
241 | // source map |
||
242 | if ($this->builder->isDebug() && (bool) $this->config->get('assets.compile.sourcemap')) { |
||
243 | $importDir = []; |
||
244 | $assetDir = (string) $this->config->get('assets.dir'); |
||
245 | $assetDirPos = strrpos($this->data['file'], DIRECTORY_SEPARATOR.$assetDir.DIRECTORY_SEPARATOR); |
||
246 | $fileRelPath = substr($this->data['file'], $assetDirPos + 8); |
||
247 | $filePath = Util::joinFile($this->config->getOutputPath(), $fileRelPath); |
||
248 | $importDir[] = dirname($filePath); |
||
249 | foreach ($scssDir as $dir) { |
||
250 | $importDir[] = Util::joinFile($this->config->getOutputPath(), $dir); |
||
251 | } |
||
252 | $scssPhp->setImportPaths(array_unique($importDir)); |
||
253 | $scssPhp->setSourceMap(Compiler::SOURCE_MAP_INLINE); |
||
254 | $scssPhp->setSourceMapOptions([ |
||
255 | 'sourceMapBasepath' => Util::joinPath($this->config->getOutputPath()), |
||
256 | 'sourceRoot' => '/', |
||
257 | ]); |
||
258 | } |
||
259 | // output style |
||
260 | $outputStyles = ['expanded', 'compressed']; |
||
261 | $outputStyle = strtolower((string) $this->config->get('assets.compile.style')); |
||
262 | if (!in_array($outputStyle, $outputStyles)) { |
||
263 | throw new Exception(\sprintf('Scss output style "%s" doesn\'t exists.', $outputStyle)); |
||
264 | } |
||
265 | $scssPhp->setOutputStyle($outputStyle); |
||
266 | // variables |
||
267 | $variables = $this->config->get('assets.compile.variables') ?? []; |
||
268 | if (!empty($variables)) { |
||
269 | $variables = array_map('ScssPhp\ScssPhp\ValueConverter::parseValue', $variables); |
||
270 | $scssPhp->replaceVariables($variables); |
||
271 | } |
||
272 | // update data |
||
273 | $this->data['path'] = preg_replace('/sass|scss/m', 'css', $this->data['path']); |
||
274 | $this->data['ext'] = 'css'; |
||
275 | $this->data['content'] = $scssPhp->compileString($this->data['content'])->getCss(); |
||
276 | $this->compiled = true; |
||
277 | $cache->set($cacheKey, $this->data); |
||
278 | } |
||
279 | $this->data = $cache->get($cacheKey); |
||
280 | |||
281 | return $this; |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * Minifying a CSS or a JS. |
||
286 | */ |
||
287 | public function minify(): self |
||
288 | { |
||
289 | // disable minify to preserve inline source map |
||
290 | if ($this->builder->isDebug() && (bool) $this->config->get('assets.compile.sourcemap')) { |
||
291 | return $this; |
||
292 | } |
||
293 | |||
294 | if ($this->minified) { |
||
295 | return $this; |
||
296 | } |
||
297 | |||
298 | if ($this->data['ext'] == 'scss') { |
||
299 | $this->compile(); |
||
300 | } |
||
301 | |||
302 | if ($this->data['ext'] != 'css' && $this->data['ext'] != 'js') { |
||
303 | return $this; |
||
304 | } |
||
305 | |||
306 | if (substr($this->data['path'], -8) == '.min.css' || substr($this->data['path'], -7) == '.min.js') { |
||
307 | $this->minified; |
||
308 | |||
309 | return $this; |
||
310 | } |
||
311 | |||
312 | $cache = new Cache($this->builder, 'assets'); |
||
313 | $cacheKey = $cache->createKeyFromAsset($this, 'minified'); |
||
314 | if (!$cache->has($cacheKey)) { |
||
315 | switch ($this->data['ext']) { |
||
316 | case 'css': |
||
317 | $minifier = new Minify\CSS($this->data['content']); |
||
318 | break; |
||
319 | case 'js': |
||
320 | $minifier = new Minify\JS($this->data['content']); |
||
321 | break; |
||
322 | default: |
||
323 | throw new Exception(sprintf('Not able to minify "%s"', $this->data['path'])); |
||
324 | } |
||
325 | $this->data['path'] = preg_replace( |
||
326 | '/\.'.$this->data['ext'].'$/m', |
||
327 | '.min.'.$this->data['ext'], |
||
328 | $this->data['path'] |
||
329 | ); |
||
330 | $this->data['content'] = $minifier->minify(); |
||
331 | $this->minified = true; |
||
332 | $cache->set($cacheKey, $this->data); |
||
333 | } |
||
334 | $this->data = $cache->get($cacheKey); |
||
335 | |||
336 | return $this; |
||
337 | } |
||
338 | |||
339 | /** |
||
340 | * Optimizing an image. |
||
341 | */ |
||
342 | public function optimize(): self |
||
343 | { |
||
344 | if ($this->optimized) { |
||
345 | return $this; |
||
346 | } |
||
347 | |||
348 | if ($this->data['type'] != 'image') { |
||
349 | return $this; |
||
350 | } |
||
351 | |||
352 | $cache = new Cache($this->builder, 'assets'); |
||
353 | $cacheKey = $cache->createKeyFromAsset($this, 'optimized'); |
||
354 | if (!$cache->has($cacheKey)) { |
||
355 | $message = $this->data['file']; |
||
356 | $sizeBefore = filesize($this->data['file']); |
||
357 | Util\File::getFS()->copy($this->data['file'], Util::joinFile($this->config->getCachePath(), 'tmp', $this->data['filename'])); |
||
358 | Image::optimizer($this->config->get('assets.images.quality') ?? 85)->optimize( |
||
359 | $this->data['file'], |
||
360 | Util::joinFile($this->config->getCachePath(), 'tmp', $this->data['filename']) |
||
361 | ); |
||
362 | $sizeAfter = filesize(Util::joinFile($this->config->getCachePath(), 'tmp', $this->data['filename'])); |
||
363 | if ($sizeAfter < $sizeBefore) { |
||
364 | $message = \sprintf( |
||
365 | '%s (%s Ko -> %s Ko)', |
||
366 | $message, |
||
367 | ceil($sizeBefore / 1000), |
||
368 | ceil($sizeAfter / 1000) |
||
369 | ); |
||
370 | } |
||
371 | $this->data['content'] = Util\File::fileGetContents(Util::joinFile($this->config->getCachePath(), 'tmp', $this->data['filename'])); |
||
372 | Util\File::getFS()->remove(Util::joinFile($this->config->getCachePath(), 'tmp')); |
||
373 | $this->optimized = true; |
||
374 | $cache->set($cacheKey, $this->data); |
||
375 | $this->builder->getLogger()->debug(\sprintf('Optimize "%s"', $message)); |
||
376 | } |
||
377 | $this->data = $cache->get($cacheKey); |
||
378 | |||
379 | return $this; |
||
380 | } |
||
381 | |||
382 | /** |
||
383 | * Resizes an image. |
||
384 | */ |
||
385 | public function resize(int $size): self |
||
386 | { |
||
387 | if ($size >= $this->getWidth()) { |
||
388 | return $this; |
||
389 | } |
||
390 | |||
391 | $cache = new Cache($this->builder, 'assets'); |
||
392 | $cacheKey = $cache->createKeyFromAsset($this, "{$size}x"); |
||
393 | if (!$cache->has($cacheKey)) { |
||
394 | if ($this->data['type'] !== 'image') { |
||
395 | throw new Exception(sprintf('Not able to resize "%s"', $this->data['path'])); |
||
396 | } |
||
397 | if (!extension_loaded('gd')) { |
||
398 | throw new Exception('GD extension is required to use images resize.'); |
||
399 | } |
||
400 | |||
401 | try { |
||
402 | $img = ImageManager::make($this->data['content_source']); |
||
403 | $img->resize($size, null, function (\Intervention\Image\Constraint $constraint) { |
||
404 | $constraint->aspectRatio(); |
||
405 | $constraint->upsize(); |
||
406 | }); |
||
407 | } catch (\Exception $e) { |
||
408 | throw new Exception(sprintf('Not able to resize image "%s": %s', $this->data['path'], $e->getMessage())); |
||
409 | } |
||
410 | $this->data['path'] = '/'.Util::joinPath((string) $this->config->get('assets.target'), 'thumbnails', (string) $size, $this->data['path']); |
||
411 | |||
412 | try { |
||
413 | $this->data['content'] = (string) $img->encode($this->data['ext'], $this->config->get('assets.images.quality')); |
||
414 | } catch (\Exception $e) { |
||
415 | throw new Exception(sprintf('Not able to encode image "%s": %s', $this->data['path'], $e->getMessage())); |
||
416 | } |
||
417 | |||
418 | $cache->set($cacheKey, $this->data); |
||
419 | } |
||
420 | $this->data = $cache->get($cacheKey); |
||
421 | |||
422 | return $this; |
||
423 | } |
||
424 | |||
425 | /** |
||
426 | * Returns the data URL of an image. |
||
427 | */ |
||
428 | public function dataurl(): string |
||
429 | { |
||
430 | if ($this->data['type'] !== 'image') { |
||
431 | throw new Exception(sprintf('Can\'t get data URL of "%s"', $this->data['path'])); |
||
432 | } |
||
433 | |||
434 | return (string) ImageManager::make($this->data['content'])->encode('data-url', $this->config->get('assets.images.quality')); |
||
435 | } |
||
436 | |||
437 | /** |
||
438 | * Implements \ArrayAccess. |
||
439 | */ |
||
440 | public function offsetSet($offset, $value) |
||
441 | { |
||
442 | if (!is_null($offset)) { |
||
443 | $this->data[$offset] = $value; |
||
444 | } |
||
445 | } |
||
446 | |||
447 | /** |
||
448 | * Implements \ArrayAccess. |
||
449 | */ |
||
450 | public function offsetExists($offset) |
||
451 | { |
||
452 | return isset($this->data[$offset]); |
||
453 | } |
||
454 | |||
455 | /** |
||
456 | * Implements \ArrayAccess. |
||
457 | */ |
||
458 | public function offsetUnset($offset) |
||
459 | { |
||
460 | unset($this->data[$offset]); |
||
461 | } |
||
462 | |||
463 | /** |
||
464 | * Implements \ArrayAccess. |
||
465 | */ |
||
466 | public function offsetGet($offset) |
||
467 | { |
||
468 | return isset($this->data[$offset]) ? $this->data[$offset] : null; |
||
469 | } |
||
470 | |||
471 | /** |
||
472 | * Hashing content of an asset with the specified algo, sha384 by default. |
||
473 | * Used for SRI (Subresource Integrity). |
||
474 | * |
||
475 | * @see https://developer.mozilla.org/fr/docs/Web/Security/Subresource_Integrity |
||
476 | */ |
||
477 | public function getIntegrity(string $algo = 'sha384'): string |
||
478 | { |
||
479 | return \sprintf('%s-%s', $algo, base64_encode(hash($algo, $this->data['content'], true))); |
||
480 | } |
||
481 | |||
482 | /** |
||
483 | * Returns the width of an image. |
||
484 | * |
||
485 | * @return false|int |
||
486 | */ |
||
487 | public function getWidth() |
||
488 | { |
||
489 | if (false === $size = $this->getImageSize()) { |
||
490 | return false; |
||
491 | } |
||
492 | |||
493 | return $size[0]; |
||
494 | } |
||
495 | |||
496 | /** |
||
497 | * Returns the height of an image. |
||
498 | * |
||
499 | * @return false|int |
||
500 | */ |
||
501 | public function getHeight() |
||
502 | { |
||
503 | if (false === $size = $this->getImageSize()) { |
||
504 | return false; |
||
505 | } |
||
506 | |||
507 | return $size[1]; |
||
508 | } |
||
509 | |||
510 | /** |
||
511 | * Returns MP3 file infos. |
||
512 | * |
||
513 | * @see https://github.com/wapmorgan/Mp3Info |
||
514 | */ |
||
515 | public function getAudio(): Mp3Info |
||
516 | { |
||
517 | return new Mp3Info($this->data['file']); |
||
518 | } |
||
519 | |||
520 | /** |
||
521 | * Saves file. |
||
522 | * Note: a file from `static/` with the same name will NOT be overridden. |
||
523 | * |
||
524 | * @throws Exception |
||
525 | */ |
||
526 | public function save(): void |
||
527 | { |
||
528 | $filepath = Util::joinFile($this->config->getOutputPath(), $this->data['path']); |
||
529 | if (!$this->builder->getBuildOptions()['dry-run'] && !Util\File::getFS()->exists($filepath)) { |
||
530 | try { |
||
531 | Util\File::getFS()->dumpFile($filepath, $this->data['content']); |
||
532 | $this->builder->getLogger()->debug(\sprintf('Save asset "%s"', $this->data['path'])); |
||
533 | } catch (\Symfony\Component\Filesystem\Exception\IOException $e) { |
||
534 | if (!$this->ignore_missing) { |
||
535 | throw new Exception(\sprintf('Can\'t save asset "%s"', $this->data['path'])); |
||
536 | } |
||
537 | } |
||
538 | } |
||
539 | } |
||
540 | |||
541 | /** |
||
542 | * Load file data. |
||
543 | */ |
||
544 | private function loadFile(string $path, bool $ignore_missing = false): array |
||
587 | } |
||
588 | |||
589 | /** |
||
590 | * Try to find the file: |
||
591 | * 1. remote (if $path is a valid URL) |
||
592 | * 2. in static/ |
||
593 | * 3. in themes/<theme>/static/ |
||
594 | * Returns local file path or false if file don't exists. |
||
595 | * |
||
596 | * @return string|false |
||
597 | */ |
||
598 | private function findFile(string $path) |
||
599 | { |
||
600 | // in case of remote file: save it and returns cached file path |
||
601 | if (Util\Url::isUrl($path)) { |
||
602 | $url = $path; |
||
603 | $relativePath = Page::slugify(sprintf('%s%s-%s', parse_url($url, PHP_URL_HOST), parse_url($url, PHP_URL_PATH), parse_url($url, PHP_URL_QUERY))); |
||
604 | $filePath = Util::joinFile($this->config->getCacheAssetsPath(), $relativePath); |
||
605 | if (!file_exists($filePath)) { |
||
606 | if (!Util\Url::isRemoteFileExists($url)) { |
||
607 | return false; |
||
608 | } |
||
609 | if (false === $content = Util\File::fileGetContents($url, true)) { |
||
610 | return false; |
||
611 | } |
||
612 | if (strlen($content) <= 1) { |
||
613 | throw new Exception(sprintf('Asset at "%s" is empty.', $url)); |
||
614 | } |
||
615 | Util\File::getFS()->dumpFile($filePath, $content); |
||
616 | } |
||
617 | |||
618 | return $filePath; |
||
619 | } |
||
620 | |||
621 | // checks in assets/ |
||
622 | $filePath = Util::joinFile($this->config->getAssetsPath(), $path); |
||
623 | if (Util\File::getFS()->exists($filePath)) { |
||
624 | return $filePath; |
||
625 | } |
||
626 | |||
627 | // checks in each themes/<theme>/assets/ |
||
628 | foreach ($this->config->getTheme() as $theme) { |
||
629 | $filePath = Util::joinFile($this->config->getThemeDirPath($theme, 'assets'), $path); |
||
630 | if (Util\File::getFS()->exists($filePath)) { |
||
631 | return $filePath; |
||
632 | } |
||
633 | } |
||
634 | |||
635 | // checks in static/ |
||
636 | $filePath = Util::joinFile($this->config->getStaticPath(), $path); |
||
637 | if (Util\File::getFS()->exists($filePath)) { |
||
638 | return $filePath; |
||
639 | } |
||
640 | |||
641 | // checks in each themes/<theme>/static/ |
||
642 | foreach ($this->config->getTheme() as $theme) { |
||
643 | $filePath = Util::joinFile($this->config->getThemeDirPath($theme, 'static'), $path); |
||
644 | if (Util\File::getFS()->exists($filePath)) { |
||
645 | return $filePath; |
||
646 | } |
||
647 | } |
||
648 | |||
649 | return false; |
||
650 | } |
||
651 | |||
652 | /** |
||
653 | * Returns image size informations. |
||
654 | * |
||
655 | * @see https://www.php.net/manual/function.getimagesize.php |
||
656 | * |
||
657 | * @return false|array |
||
658 | */ |
||
659 | private function getImageSize() |
||
670 | } |
||
671 | } |
||
672 |