1 | <?php |
||
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 | ]; |
||
78 | |||
79 | /** @var string Full path to project web root directory */ |
||
80 | public static $webRoot; |
||
81 | |||
82 | /** @var string Full path to project root directory */ |
||
83 | public static $projectRoot; |
||
84 | |||
85 | /** @var string Full path to project cache root directory */ |
||
86 | public static $cacheRoot; |
||
87 | |||
88 | /** @var array Cached assets */ |
||
89 | protected $cache = []; |
||
90 | |||
91 | /** @var array Collection of assets */ |
||
92 | protected $assets = []; |
||
93 | |||
94 | /** @var FileManagerInterface */ |
||
95 | protected $fileManager; |
||
96 | |||
97 | /** |
||
98 | * Resource constructor. |
||
99 | * |
||
100 | * @param FileManagerInterface $fileManager File managing class |
||
101 | */ |
||
102 | 2 | public function __construct(FileManagerInterface $fileManager) |
|
106 | |||
107 | /** |
||
108 | * Recursively process asset |
||
109 | * @param array $dependencies Collection of assets for compilation |
||
110 | */ |
||
111 | 2 | protected function processAsset($dependencies) |
|
135 | |||
136 | /** |
||
137 | * Create static assets. |
||
138 | * |
||
139 | * @param string[] $paths Collection of paths for gathering assets |
||
140 | * |
||
141 | * @return string[] Cached assets full paths collection |
||
142 | */ |
||
143 | 2 | public function manage(array $paths) |
|
164 | |||
165 | /** |
||
166 | * Get asset cached path with extension conversion. |
||
167 | * |
||
168 | * @param string $asset Asset full path |
||
169 | * |
||
170 | * @return string Full path to cached asset |
||
171 | */ |
||
172 | 2 | protected function getAssetProcessedPath($asset) |
|
181 | |||
182 | /** |
||
183 | * Get asset final type. |
||
184 | * |
||
185 | * @param string $asset Full asset path |
||
186 | * |
||
187 | * @return string Asset final type |
||
188 | */ |
||
189 | 2 | public function convertType($asset) |
|
198 | |||
199 | /** |
||
200 | * Define if asset is not valid. |
||
201 | * |
||
202 | * @param string $asset Full path to asset |
||
203 | * |
||
204 | * @param string $cachedAsset Full path to cached asset |
||
205 | * |
||
206 | * @return bool True if cached asset is valid |
||
207 | */ |
||
208 | 2 | protected function isValid($asset, $cachedAsset) |
|
214 | } |
||
215 |