1 | <?php declare(strict_types=1); |
||
16 | class ResourceManager |
||
17 | { |
||
18 | /** Event for resources analyzing */ |
||
19 | const E_ANALYZE = 'resource.analyze'; |
||
20 | /** Event for resources compiling */ |
||
21 | const E_COMPILE = 'resource.compile'; |
||
22 | |||
23 | /** Assets types */ |
||
24 | const T_CSS = 'css'; |
||
25 | const T_LESS = 'less'; |
||
26 | const T_SCSS = 'scss'; |
||
27 | const T_SASS = 'sass'; |
||
28 | const T_JS = 'js'; |
||
29 | const T_TS = 'ts'; |
||
30 | const T_COFFEE = 'coffee'; |
||
31 | const T_JPG = 'jpg'; |
||
32 | const T_JPEG = 'jpeg'; |
||
33 | const T_PNG = 'png'; |
||
34 | const T_GIF = 'gif'; |
||
35 | const T_SVG = 'svg'; |
||
36 | const T_TTF = 'ttf'; |
||
37 | const T_WOFF = 'woff'; |
||
38 | const T_WOFF2 = 'woff2'; |
||
39 | const T_EOT = 'eot'; |
||
40 | |||
41 | /** Assets types collection */ |
||
42 | const TYPES = [ |
||
43 | self::T_CSS, |
||
44 | self::T_LESS, |
||
45 | self::T_SCSS, |
||
46 | self::T_SASS, |
||
47 | self::T_JS, |
||
48 | self::T_TS, |
||
49 | self::T_COFFEE, |
||
50 | /*self::T_JPG, |
||
51 | self::T_JPEG, |
||
52 | self::T_PNG, |
||
53 | self::T_GIF, |
||
54 | self::T_SVG, |
||
55 | self::T_TTF, |
||
56 | self::T_WOFF, |
||
57 | self::T_WOFF2, |
||
58 | self::T_EOT,*/ |
||
59 | ]; |
||
60 | |||
61 | /** Assets converter */ |
||
62 | const CONVERTER = [ |
||
63 | self::T_JS => self::T_JS, |
||
64 | self::T_TS => self::T_JS, |
||
65 | self::T_COFFEE => self::T_JS, |
||
66 | self::T_CSS => self::T_CSS, |
||
67 | self::T_LESS => self::T_CSS, |
||
68 | self::T_SCSS => self::T_CSS, |
||
69 | self::T_SASS => self::T_CSS, |
||
70 | ]; |
||
71 | |||
72 | /** Collection of excluding scanning folder patterns */ |
||
73 | public static $excludeFolders = [ |
||
74 | '*/cache/*', |
||
75 | '*/tests/*', |
||
76 | '*/vendor/*/vendor/*', |
||
77 | '*/node_modules/*' |
||
78 | ]; |
||
79 | |||
80 | /** @var string Full path to project web root directory */ |
||
81 | public static $webRoot; |
||
82 | |||
83 | /** @var string Full path to project root directory */ |
||
84 | public static $projectRoot; |
||
85 | |||
86 | /** @var string Full path to project cache root directory */ |
||
87 | public static $cacheRoot; |
||
88 | |||
89 | /** @var array Collection of assets */ |
||
90 | protected $assets = []; |
||
91 | |||
92 | /** @var FileManagerInterface */ |
||
93 | protected $fileManager; |
||
94 | |||
95 | /** |
||
96 | * Resource constructor. |
||
97 | * |
||
98 | * @param FileManagerInterface $fileManager File managing class |
||
99 | */ |
||
100 | 2 | public function __construct(FileManagerInterface $fileManager) |
|
104 | |||
105 | /** |
||
106 | * Recursively process asset |
||
107 | * @param array $dependencies Collection of assets for compilation |
||
108 | */ |
||
109 | 2 | protected function processAsset($dependencies) |
|
133 | |||
134 | /** |
||
135 | * Create static assets. |
||
136 | * |
||
137 | * @param string[] $paths Collection of paths for gathering assets |
||
138 | * |
||
139 | * @return string[] Cached assets full paths collection |
||
140 | */ |
||
141 | 2 | public function manage(array $paths) |
|
161 | |||
162 | /** |
||
163 | * Get asset cached path with extension conversion. |
||
164 | * |
||
165 | * @param string $asset Asset full path |
||
166 | * |
||
167 | * @return string Full path to cached asset |
||
168 | */ |
||
169 | 2 | protected function getAssetProcessedPath($asset) |
|
178 | |||
179 | /** |
||
180 | * Get asset final type. |
||
181 | * |
||
182 | * @param string $asset Full asset path |
||
183 | * |
||
184 | * @return string Asset final type |
||
185 | */ |
||
186 | 2 | public function convertType($asset) |
|
195 | |||
196 | /** |
||
197 | * Define if asset is not valid. |
||
198 | * |
||
199 | * @param string $asset Full path to asset |
||
200 | * |
||
201 | * @param string $cachedAsset Full path to cached asset |
||
202 | * |
||
203 | * @return bool True if cached asset is valid |
||
204 | */ |
||
205 | 2 | protected function isValid($asset, $cachedAsset) |
|
211 | } |
||
212 |