1 | <?php |
||
15 | class ResourceManager |
||
16 | { |
||
17 | /** Event for resources analyzing */ |
||
18 | const E_ANALYZE = 'resource.analyze'; |
||
19 | /** Event for resources compiling */ |
||
20 | const E_COMPILE = 'resource.compile'; |
||
21 | |||
22 | /** Assets types */ |
||
23 | const T_CSS = 'css'; |
||
24 | const T_LESS = 'less'; |
||
25 | const T_SCSS = 'scss'; |
||
26 | const T_SASS = 'sass'; |
||
27 | const T_JS = 'js'; |
||
28 | const T_TS = 'ts'; |
||
29 | const T_COFFEE = 'coffee'; |
||
30 | const T_JPG = 'jpg'; |
||
31 | const T_JPEG = 'jpeg'; |
||
32 | const T_PNG = 'png'; |
||
33 | const T_GIF = 'gif'; |
||
34 | const T_SVG = 'svg'; |
||
35 | const T_TTF = 'ttf'; |
||
36 | const T_WOFF = 'woff'; |
||
37 | const T_WOFF2 = 'woff2'; |
||
38 | const T_EOT = 'eot'; |
||
39 | |||
40 | /** Assets types collection */ |
||
41 | const TYPES = [ |
||
42 | self::T_CSS, |
||
43 | self::T_LESS, |
||
44 | self::T_SCSS, |
||
45 | self::T_SASS, |
||
46 | self::T_JS, |
||
47 | self::T_TS, |
||
48 | self::T_COFFEE, |
||
49 | self::T_JPG, |
||
50 | self::T_JPEG, |
||
51 | self::T_PNG, |
||
52 | self::T_GIF, |
||
53 | self::T_SVG, |
||
54 | self::T_TTF, |
||
55 | self::T_WOFF, |
||
56 | self::T_WOFF2, |
||
57 | self::T_EOT, |
||
58 | ]; |
||
59 | |||
60 | /** Assets converter */ |
||
61 | const CONVERTER = [ |
||
62 | self::T_JS => self::T_JS, |
||
63 | self::T_TS => self::T_JS, |
||
64 | self::T_COFFEE => self::T_JS, |
||
65 | self::T_CSS => self::T_CSS, |
||
66 | self::T_LESS => self::T_CSS, |
||
67 | self::T_SCSS => self::T_CSS, |
||
68 | self::T_SASS => self::T_CSS, |
||
69 | ]; |
||
70 | |||
71 | /** Collection of excluding scanning folder patterns */ |
||
72 | public static $excludeFolders = [ |
||
73 | '*/cache/*', |
||
74 | '*/tests/*', |
||
75 | '*/vendor/*/vendor/*' |
||
76 | ]; |
||
77 | |||
78 | /** @var string Full path to project web root directory */ |
||
79 | public static $webRoot; |
||
80 | |||
81 | /** @var string Full path to project root directory */ |
||
82 | public static $projectRoot; |
||
83 | |||
84 | /** @var string Full path to project cache root directory */ |
||
85 | public static $cacheRoot; |
||
86 | |||
87 | /** @var array Cached assets */ |
||
88 | protected $cache = []; |
||
89 | |||
90 | /** @var array Collection of assets */ |
||
91 | protected $assets = []; |
||
92 | |||
93 | /** |
||
94 | * Resource constructor. |
||
95 | * |
||
96 | * @param FileManagerInterface $fileManager File managing class |
||
97 | */ |
||
98 | 1 | public function __construct(FileManagerInterface $fileManager) |
|
102 | |||
103 | /** |
||
104 | * Create static assets. |
||
105 | * |
||
106 | * @param array $paths Collection of paths for gathering assets |
||
107 | * |
||
108 | * @return array Cached assets full paths collection |
||
109 | */ |
||
110 | 1 | public function manage(array $paths) |
|
138 | |||
139 | /** |
||
140 | * Analyze asset. |
||
141 | * |
||
142 | * @param string $asset Full path to asset |
||
143 | * |
||
144 | * @return string Analyzed asset content |
||
145 | */ |
||
146 | 1 | protected function analyzeAsset($asset) |
|
173 | |||
174 | /** |
||
175 | * Get asset cached path with extension conversion. |
||
176 | * |
||
177 | * @param string $asset Asset full path |
||
178 | * |
||
179 | * @return string Full path to cached asset |
||
180 | */ |
||
181 | 1 | protected function getAssetCachedPath($asset) |
|
190 | |||
191 | /** |
||
192 | * Get asset final type. |
||
193 | * |
||
194 | * @param string $asset Full asset path |
||
195 | * |
||
196 | * @return string Asset final type |
||
197 | */ |
||
198 | 1 | public function convertType($asset) |
|
207 | |||
208 | /** |
||
209 | * Define if asset is not valid. |
||
210 | * |
||
211 | * @param string $asset Full path to asset |
||
212 | * |
||
213 | * @param string $cachedAsset Full path to cached asset |
||
214 | * |
||
215 | * @return bool True if cached asset is valid |
||
216 | */ |
||
217 | 1 | protected function isValid($asset, $cachedAsset) |
|
223 | } |
||
224 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: