@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public static function fetch(string $pathOrUrl, callable $callback = null, string $cacheKeySuffix = '') |
56 | 56 | { |
57 | - $pathOrUrl = (string)Craft::parseEnv($pathOrUrl); |
|
57 | + $pathOrUrl = (string) Craft::parseEnv($pathOrUrl); |
|
58 | 58 | // Create the dependency tags |
59 | 59 | $dependency = new TagDependency([ |
60 | 60 | 'tags' => [ |
61 | - self::CACHE_TAG . $cacheKeySuffix, |
|
62 | - self::CACHE_TAG . $cacheKeySuffix . $pathOrUrl, |
|
61 | + self::CACHE_TAG.$cacheKeySuffix, |
|
62 | + self::CACHE_TAG.$cacheKeySuffix.$pathOrUrl, |
|
63 | 63 | ], |
64 | 64 | ]); |
65 | 65 | // If this is a file path such as for the `manifest.json`, add a FileDependency so it's cache bust if the file changes |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | // Get the result from the cache, or parse the file |
81 | 81 | $cache = Craft::$app->getCache(); |
82 | 82 | return $cache->getOrSet( |
83 | - self::CACHE_KEY . $cacheKeySuffix . $pathOrUrl, |
|
84 | - function () use ($pathOrUrl, $callback) { |
|
83 | + self::CACHE_KEY.$cacheKeySuffix.$pathOrUrl, |
|
84 | + function() use ($pathOrUrl, $callback) { |
|
85 | 85 | $contents = null; |
86 | 86 | $result = null; |
87 | 87 | if (UrlHelper::isAbsoluteUrl($pathOrUrl)) { |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public static function createUrl(string $url, string $path): string |
135 | 135 | { |
136 | - $url = (string)Craft::parseEnv($url); |
|
137 | - return rtrim($url, '/') . '/' . trim($path, '/'); |
|
136 | + $url = (string) Craft::parseEnv($url); |
|
137 | + return rtrim($url, '/').'/'.trim($path, '/'); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | $this->manifestShimsIncluded = true; |
212 | 212 | } |
213 | 213 | |
214 | - foreach(array_merge($tags, $legacyTags) as $tag) { |
|
214 | + foreach (array_merge($tags, $legacyTags) as $tag) { |
|
215 | 215 | if (!empty($tag)) { |
216 | 216 | $url = FileHelper::createUrl($this->serverPublic, $tag['url']); |
217 | 217 | switch ($tag['type']) { |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | $view->registerJsFile( |
300 | 300 | $url, |
301 | 301 | array_merge(['type' => 'module'], $scriptTagAttrs), |
302 | - md5($url . JsonHelper::encode($scriptTagAttrs)) |
|
302 | + md5($url.JsonHelper::encode($scriptTagAttrs)) |
|
303 | 303 | ); |
304 | 304 | } |
305 | 305 | |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | } |
336 | 336 | $this->manifestShimsIncluded = true; |
337 | 337 | } |
338 | - foreach(array_merge($tags, $legacyTags) as $tag) { |
|
338 | + foreach (array_merge($tags, $legacyTags) as $tag) { |
|
339 | 339 | if (!empty($tag)) { |
340 | 340 | $url = FileHelper::createUrl($this->serverPublic, $tag['url']); |
341 | 341 | switch ($tag['type']) { |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | $view->registerJsFile( |
344 | 344 | $url, |
345 | 345 | $tag['options'], |
346 | - md5($url . JsonHelper::encode($tag['options'])) |
|
346 | + md5($url.JsonHelper::encode($tag['options'])) |
|
347 | 347 | ); |
348 | 348 | break; |
349 | 349 | case 'css': |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | public function invalidateCaches() |
402 | 402 | { |
403 | 403 | $cache = Craft::$app->getCache(); |
404 | - TagDependency::invalidate($cache, FileHelper::CACHE_TAG . $this->cacheKeySuffix); |
|
404 | + TagDependency::invalidate($cache, FileHelper::CACHE_TAG.$this->cacheKeySuffix); |
|
405 | 405 | Craft::info('All Vite caches cleared', __METHOD__); |
406 | 406 | } |
407 | 407 |
@@ -215,13 +215,13 @@ discard block |
||
215 | 215 | if (!empty($tag)) { |
216 | 216 | $url = FileHelper::createUrl($this->serverPublic, $tag['url']); |
217 | 217 | switch ($tag['type']) { |
218 | - case 'import': |
|
219 | - $lines[] = HtmlHelper::tag('link', '', [ |
|
220 | - 'crossorigin' => $tag['crossorigin'], |
|
221 | - 'href' => $url, |
|
222 | - 'rel' => 'modulepreload', |
|
223 | - ]); |
|
224 | - break; |
|
218 | + case 'import': |
|
219 | + $lines[] = HtmlHelper::tag('link', '', [ |
|
220 | + 'crossorigin' => $tag['crossorigin'], |
|
221 | + 'href' => $url, |
|
222 | + 'rel' => 'modulepreload', |
|
223 | + ]); |
|
224 | + break; |
|
225 | 225 | case 'file': |
226 | 226 | $lines[] = HtmlHelper::jsFile($url, $tag['options']); |
227 | 227 | break; |
@@ -339,16 +339,16 @@ discard block |
||
339 | 339 | if (!empty($tag)) { |
340 | 340 | $url = FileHelper::createUrl($this->serverPublic, $tag['url']); |
341 | 341 | switch ($tag['type']) { |
342 | - case 'import': |
|
342 | + case 'import': |
|
343 | 343 | $view->registerLinkTag( |
344 | - [ |
|
345 | - 'crossorigin' => $tag['crossorigin'], |
|
346 | - 'href' => $url, |
|
347 | - 'rel' => 'modulepreload', |
|
348 | - ], |
|
349 | - md5($url) |
|
344 | + [ |
|
345 | + 'crossorigin' => $tag['crossorigin'], |
|
346 | + 'href' => $url, |
|
347 | + 'rel' => 'modulepreload', |
|
348 | + ], |
|
349 | + md5($url) |
|
350 | 350 | ); |
351 | - break; |
|
351 | + break; |
|
352 | 352 | case 'file': |
353 | 353 | $view->registerJsFile( |
354 | 354 | $url, |
@@ -152,15 +152,15 @@ discard block |
||
152 | 152 | 'options' => $tagOptions |
153 | 153 | ]; |
154 | 154 | // Include any imports |
155 | - $importFiles = []; |
|
156 | - self::extractImportFiles(self::$manifest, $manifestKey, $importFiles); |
|
157 | - foreach ($importFiles as $importFile) { |
|
158 | - $tags[] = [ |
|
159 | - 'crossorigin' => $tagOptions['crossorigin'] ?? true, |
|
160 | - 'type' => 'import', |
|
161 | - 'url' => $importFile, |
|
162 | - ]; |
|
163 | - } |
|
155 | + $importFiles = []; |
|
156 | + self::extractImportFiles(self::$manifest, $manifestKey, $importFiles); |
|
157 | + foreach ($importFiles as $importFile) { |
|
158 | + $tags[] = [ |
|
159 | + 'crossorigin' => $tagOptions['crossorigin'] ?? true, |
|
160 | + 'type' => 'import', |
|
161 | + 'url' => $importFile, |
|
162 | + ]; |
|
163 | + } |
|
164 | 164 | // Include any CSS tags |
165 | 165 | $cssFiles = []; |
166 | 166 | self::extractCssFiles(self::$manifest, $manifestKey, $cssFiles); |
@@ -178,32 +178,32 @@ discard block |
||
178 | 178 | return $tags; |
179 | 179 | } |
180 | 180 | |
181 | - /** |
|
182 | - * Extract any import files from entries recursively |
|
183 | - * |
|
184 | - * @param array $manifest |
|
185 | - * @param string $manifestKey |
|
186 | - * @param array $importFiles |
|
187 | - * |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - protected static function extractImportFiles(array $manifest, string $manifestKey, array &$importFiles): array |
|
191 | - { |
|
192 | - $entry = $manifest[$manifestKey] ?? null; |
|
193 | - if (!$entry) { |
|
194 | - return []; |
|
195 | - } |
|
196 | - |
|
197 | - $imports = $entry['imports'] ?? []; |
|
198 | - foreach($imports as $import) { |
|
199 | - $importFiles[] = $manifest[$import]['file']; |
|
200 | - self::extractImportFiles($manifest, $import, $importFiles); |
|
201 | - } |
|
202 | - |
|
203 | - return $importFiles; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
181 | + /** |
|
182 | + * Extract any import files from entries recursively |
|
183 | + * |
|
184 | + * @param array $manifest |
|
185 | + * @param string $manifestKey |
|
186 | + * @param array $importFiles |
|
187 | + * |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + protected static function extractImportFiles(array $manifest, string $manifestKey, array &$importFiles): array |
|
191 | + { |
|
192 | + $entry = $manifest[$manifestKey] ?? null; |
|
193 | + if (!$entry) { |
|
194 | + return []; |
|
195 | + } |
|
196 | + |
|
197 | + $imports = $entry['imports'] ?? []; |
|
198 | + foreach($imports as $import) { |
|
199 | + $importFiles[] = $manifest[$import]['file']; |
|
200 | + self::extractImportFiles($manifest, $import, $importFiles); |
|
201 | + } |
|
202 | + |
|
203 | + return $importFiles; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | 207 | * Extract any CSS files from entries recursively |
208 | 208 | * |
209 | 209 | * @param array $manifest |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | public static function fetchManifest(string $manifestPath) |
46 | 46 | { |
47 | 47 | // Grab the manifest |
48 | - $pathOrUrl = (string)Craft::parseEnv($manifestPath); |
|
48 | + $pathOrUrl = (string) Craft::parseEnv($manifestPath); |
|
49 | 49 | $manifest = FileHelper::fetch($pathOrUrl, [JsonHelper::class, 'decodeIfJson']); |
50 | 50 | // If no manifest file is found, log it |
51 | 51 | if ($manifest === null) { |
52 | - Craft::error('Manifest not found at ' . $manifestPath, __METHOD__); |
|
52 | + Craft::error('Manifest not found at '.$manifestPath, __METHOD__); |
|
53 | 53 | } |
54 | 54 | // Ensure we're dealing with an array |
55 | - self::$manifest = (array)$manifest; |
|
55 | + self::$manifest = (array) $manifest; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | } |
196 | 196 | |
197 | 197 | $imports = $entry['imports'] ?? []; |
198 | - foreach($imports as $import) { |
|
198 | + foreach ($imports as $import) { |
|
199 | 199 | $importFiles[] = $manifest[$import]['file']; |
200 | 200 | self::extractImportFiles($manifest, $import, $importFiles); |
201 | 201 | } |