|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* BEdita, API-first content management framework |
|
6
|
|
|
* Copyright 2020 ChannelWeb Srl, Chialab Srl |
|
7
|
|
|
* |
|
8
|
|
|
* This file is part of BEdita: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Lesser General Public License as published |
|
10
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details. |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace BEdita\WebTools\Utility\Asset\Strategy; |
|
16
|
|
|
|
|
17
|
|
|
use BEdita\WebTools\Utility\Asset\AssetStrategy; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Entrypoints asset strategy. |
|
21
|
|
|
* This strategy is based on map produced by Webpack Encore and expects a JSON assets map like |
|
22
|
|
|
* |
|
23
|
|
|
* ``` |
|
24
|
|
|
* { |
|
25
|
|
|
* "entrypoints": { |
|
26
|
|
|
* "app": { |
|
27
|
|
|
* "js": [ |
|
28
|
|
|
* "/build/runtime.f011bcb1.js", |
|
29
|
|
|
* "/build/0.54651780.js", |
|
30
|
|
|
* "/build/app.82269f26.js" |
|
31
|
|
|
* ] |
|
32
|
|
|
* }, |
|
33
|
|
|
* "style": { |
|
34
|
|
|
* "js": [ |
|
35
|
|
|
* "/build/runtime.f011bcb1.js" |
|
36
|
|
|
* ], |
|
37
|
|
|
* "css": [ |
|
38
|
|
|
* "/build/style.12c5249c.css" |
|
39
|
|
|
* ] |
|
40
|
|
|
* } |
|
41
|
|
|
* } |
|
42
|
|
|
* } |
|
43
|
|
|
* ``` |
|
44
|
|
|
* |
|
45
|
|
|
* @see https://symfony.com/doc/current/frontend.html |
|
46
|
|
|
*/ |
|
47
|
|
|
class EntrypointsStrategy extends AssetStrategy |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* @inheritDoc |
|
51
|
|
|
*/ |
|
52
|
|
|
protected array $_defaultConfig = [ |
|
53
|
|
|
'manifestPath' => WWW_ROOT . 'build' . DS . 'entrypoints.json', |
|
54
|
|
|
]; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @inheritDoc |
|
58
|
|
|
*/ |
|
59
|
|
|
public function get(string $name, ?string $extension = null): array|string|null |
|
60
|
|
|
{ |
|
61
|
|
|
if (!empty($extension)) { |
|
62
|
|
|
return $this->assets['entrypoints'][$name][$extension] ?? null; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $this->assets['entrypoints'][$name] ?? null; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|