1 | <?php |
||
18 | abstract class MinifyComponent |
||
19 | { |
||
20 | |||
21 | const CACHE_TAG = 'minify-view-tag'; |
||
22 | |||
23 | /** |
||
24 | * @var View |
||
25 | */ |
||
26 | protected $view; |
||
27 | |||
28 | /** |
||
29 | * MinifyComponent constructor. |
||
30 | * @param View $view |
||
31 | */ |
||
32 | 9 | public function __construct(View $view) |
|
36 | |||
37 | abstract public function export(); |
||
38 | |||
39 | /** |
||
40 | * @param string $file |
||
41 | * @return string |
||
42 | */ |
||
43 | 8 | protected function getAbsoluteFilePath($file) |
|
50 | |||
51 | /** |
||
52 | * @param string $file |
||
53 | * @return string |
||
54 | */ |
||
55 | 8 | protected function cleanFileName($file) |
|
61 | |||
62 | /** |
||
63 | * @param string $file |
||
64 | * @param string $html |
||
65 | * @return bool |
||
66 | */ |
||
67 | 8 | protected function thisFileNeedMinify($file, $html) |
|
73 | |||
74 | /** |
||
75 | * @param string $url |
||
76 | * @param boolean $checkSlash |
||
77 | * @return bool |
||
78 | */ |
||
79 | protected function isUrl($url, $checkSlash = true) |
||
93 | |||
94 | /** |
||
95 | * @param string $string |
||
96 | * @return bool |
||
97 | */ |
||
98 | 8 | protected function isContainsConditionalComment($string) |
|
102 | |||
103 | /** |
||
104 | * @param string $file |
||
105 | * @return bool |
||
106 | */ |
||
107 | 8 | protected function isExcludedFile($file) |
|
122 | |||
123 | /** |
||
124 | * @param string $resultFile |
||
125 | * @return string |
||
126 | */ |
||
127 | 8 | protected function prepareResultFile($resultFile) |
|
142 | |||
143 | /** |
||
144 | * @param array $files |
||
145 | * @return string |
||
146 | */ |
||
147 | 8 | protected function _getSummaryFilesHash($files) |
|
148 | { |
||
149 | 8 | $result = ''; |
|
150 | |||
151 | 8 | foreach ($files as $file => $html) { |
|
152 | 8 | $path = $this->getAbsoluteFilePath($file); |
|
153 | |||
154 | 8 | if (!$this->thisFileNeedMinify($file, $html) || !file_exists($path)) { |
|
155 | continue; |
||
156 | } |
||
157 | |||
158 | 8 | switch ($this->view->fileCheckAlgorithm) { |
|
159 | default: |
||
160 | 8 | case 'filemtime': |
|
161 | 1 | $result .= filemtime($path) . $file; |
|
162 | 1 | break; |
|
163 | 7 | case 'sha1': // deprecated |
|
164 | 7 | case 'hash': |
|
165 | 7 | $result .= hash_file($this->view->currentHashAlgo, $path); |
|
166 | 8 | break; |
|
167 | } |
||
168 | } |
||
169 | |||
170 | 8 | return hash($this->view->currentHashAlgo, $result); |
|
171 | } |
||
172 | |||
173 | /** |
||
174 | * @param string $file |
||
175 | * @return string |
||
176 | */ |
||
177 | 8 | protected function buildCacheKey($file) |
|
181 | |||
182 | /** |
||
183 | * @param string $key |
||
184 | * @return string|false |
||
185 | */ |
||
186 | 8 | protected function getFromCache($key) |
|
194 | |||
195 | /** |
||
196 | * @param string $key |
||
197 | * @param string $content |
||
198 | * @return bool |
||
199 | */ |
||
200 | 8 | protected function saveToCache($key, $content) |
|
208 | } |
||
209 |