@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - public function script(string $path, bool $asyncCss = true, array $scriptTagAttrs = [], array $cssTagAttrs = []): string |
|
111 | + public function script(string $path, bool $asyncCss = true, array $scriptTagAttrs = [ ], array $cssTagAttrs = [ ]): string |
|
112 | 112 | { |
113 | 113 | if ($this->devServerRunning()) { |
114 | 114 | return $this->devServerScript($path, $scriptTagAttrs); |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return string |
127 | 127 | */ |
128 | - public function devServerScript(string $path, array $scriptTagAttrs = []): string |
|
128 | + public function devServerScript(string $path, array $scriptTagAttrs = [ ]): string |
|
129 | 129 | { |
130 | - $lines = []; |
|
130 | + $lines = [ ]; |
|
131 | 131 | // Include the entry script |
132 | 132 | $url = $this->createUrl($this->devServerPublic, $path); |
133 | - $lines[] = HtmlHelper::jsFile($url, array_merge([ |
|
133 | + $lines[ ] = HtmlHelper::jsFile($url, array_merge([ |
|
134 | 134 | 'type' => 'module', |
135 | 135 | ], $scriptTagAttrs)); |
136 | 136 | |
@@ -147,25 +147,25 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @return string |
149 | 149 | */ |
150 | - public function manifestScript(string $path, bool $asyncCss = true, array $scriptTagAttrs = [], array $cssTagAttrs = []): string |
|
150 | + public function manifestScript(string $path, bool $asyncCss = true, array $scriptTagAttrs = [ ], array $cssTagAttrs = [ ]): string |
|
151 | 151 | { |
152 | - $lines = []; |
|
152 | + $lines = [ ]; |
|
153 | 153 | $tags = $this->manifestTags($path, $asyncCss, $scriptTagAttrs, $cssTagAttrs); |
154 | 154 | // Handle any legacy polyfills |
155 | 155 | if ($this->hasLegacyTags && !$this->legacyPolyfillIncluded) { |
156 | - $lines[] = HtmlHelper::script(self::SAFARI_NOMODULE_FIX, []); |
|
156 | + $lines[ ] = HtmlHelper::script(self::SAFARI_NOMODULE_FIX, [ ]); |
|
157 | 157 | $legacyPolyfillTags = $this->extractManifestTags(self::LEGACY_POLYFILLS, $asyncCss, $scriptTagAttrs, $cssTagAttrs, true); |
158 | 158 | $tags = array_merge($legacyPolyfillTags, $tags); |
159 | 159 | $this->legacyPolyfillIncluded = true; |
160 | 160 | } |
161 | - foreach($tags as $tag) { |
|
161 | + foreach ($tags as $tag) { |
|
162 | 162 | if (!empty($tag)) { |
163 | - switch ($tag['type']) { |
|
163 | + switch ($tag[ 'type' ]) { |
|
164 | 164 | case 'file': |
165 | - $lines[] = HtmlHelper::jsFile($tag['url'], $tag['options']); |
|
165 | + $lines[ ] = HtmlHelper::jsFile($tag[ 'url' ], $tag[ 'options' ]); |
|
166 | 166 | break; |
167 | 167 | case 'css': |
168 | - $lines[] = HtmlHelper::cssFile($tag['url'], $tag['options']); |
|
168 | + $lines[ ] = HtmlHelper::cssFile($tag[ 'url' ], $tag[ 'options' ]); |
|
169 | 169 | break; |
170 | 170 | default: |
171 | 171 | break; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return void |
189 | 189 | * @throws InvalidConfigException |
190 | 190 | */ |
191 | - public function register(string $path, bool $asyncCss = true, array $scriptTagAttrs = [], array $cssTagAttrs = []) |
|
191 | + public function register(string $path, bool $asyncCss = true, array $scriptTagAttrs = [ ], array $cssTagAttrs = [ ]) |
|
192 | 192 | { |
193 | 193 | if ($this->devServerRunning()) { |
194 | 194 | $this->devServerRegister($path, $scriptTagAttrs); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return void |
209 | 209 | */ |
210 | - public function devServerRegister(string $path, array $scriptTagAttrs = []) |
|
210 | + public function devServerRegister(string $path, array $scriptTagAttrs = [ ]) |
|
211 | 211 | { |
212 | 212 | $view = Craft::$app->getView(); |
213 | 213 | // Include the entry script |
@@ -229,30 +229,30 @@ discard block |
||
229 | 229 | * @return void |
230 | 230 | * @throws InvalidConfigException |
231 | 231 | */ |
232 | - public function manifestRegister(string $path, bool $asyncCss = true, array $scriptTagAttrs = [], array $cssTagAttrs = []) |
|
232 | + public function manifestRegister(string $path, bool $asyncCss = true, array $scriptTagAttrs = [ ], array $cssTagAttrs = [ ]) |
|
233 | 233 | { |
234 | 234 | $view = Craft::$app->getView(); |
235 | 235 | $tags = $this->manifestTags($path, $asyncCss, $scriptTagAttrs, $cssTagAttrs); |
236 | 236 | // Handle any legacy polyfills |
237 | 237 | if ($this->hasLegacyTags && !$this->legacyPolyfillIncluded) { |
238 | - $view->registerScript(self::SAFARI_NOMODULE_FIX, $view::POS_HEAD, [], 'SAFARI_NOMODULE_FIX'); |
|
238 | + $view->registerScript(self::SAFARI_NOMODULE_FIX, $view::POS_HEAD, [ ], 'SAFARI_NOMODULE_FIX'); |
|
239 | 239 | $legacyPolyfillTags = $this->extractManifestTags(self::LEGACY_POLYFILLS, $asyncCss, $scriptTagAttrs, $cssTagAttrs, true); |
240 | 240 | $tags = array_merge($legacyPolyfillTags, $tags); |
241 | 241 | $this->legacyPolyfillIncluded = true; |
242 | 242 | } |
243 | - foreach($tags as $tag) { |
|
243 | + foreach ($tags as $tag) { |
|
244 | 244 | if (!empty($tag)) { |
245 | - switch ($tag['type']) { |
|
245 | + switch ($tag[ 'type' ]) { |
|
246 | 246 | case 'file': |
247 | 247 | $view->registerScript( |
248 | 248 | '', |
249 | 249 | $view::POS_HEAD, |
250 | - array_merge(['src' => $tag['url']], $tag['options']), |
|
251 | - md5($tag['url'] . json_encode($tag['options'])) |
|
250 | + array_merge([ 'src' => $tag[ 'url' ] ], $tag[ 'options' ]), |
|
251 | + md5($tag[ 'url' ].json_encode($tag[ 'options' ])) |
|
252 | 252 | ); |
253 | 253 | break; |
254 | 254 | case 'css': |
255 | - $view->registerCssFile($tag['url'], $tag['options']); |
|
255 | + $view->registerCssFile($tag[ 'url' ], $tag[ 'options' ]); |
|
256 | 256 | break; |
257 | 257 | default: |
258 | 258 | break; |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | public function invalidateCaches() |
283 | 283 | { |
284 | 284 | $cache = Craft::$app->getCache(); |
285 | - TagDependency::invalidate($cache, self::CACHE_TAG . $this->cacheKeySuffix); |
|
285 | + TagDependency::invalidate($cache, self::CACHE_TAG.$this->cacheKeySuffix); |
|
286 | 286 | Craft::info('All Vite caches cleared', __METHOD__); |
287 | 287 | } |
288 | 288 | |
@@ -299,20 +299,20 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @return array |
301 | 301 | */ |
302 | - protected function manifestTags(string $path, bool $asyncCss = true, array $scriptTagAttrs = [], array $cssTagAttrs = []): array |
|
302 | + protected function manifestTags(string $path, bool $asyncCss = true, array $scriptTagAttrs = [ ], array $cssTagAttrs = [ ]): array |
|
303 | 303 | { |
304 | 304 | // Get the modern tags for this $path |
305 | 305 | $tags = $this->extractManifestTags($path, $asyncCss, $scriptTagAttrs, $cssTagAttrs, false); |
306 | 306 | // Look for a legacy version of this $path too |
307 | 307 | $parts = pathinfo($path); |
308 | - $legacyPath = $parts['dirname'] |
|
308 | + $legacyPath = $parts[ 'dirname' ] |
|
309 | 309 | . '/' |
310 | - . $parts['filename'] |
|
310 | + . $parts[ 'filename' ] |
|
311 | 311 | . self::LEGACY_EXTENSION |
312 | - . $parts['extension']; |
|
312 | + . $parts[ 'extension' ]; |
|
313 | 313 | $legacyTags = $this->extractManifestTags($legacyPath, $asyncCss, $scriptTagAttrs, $cssTagAttrs, true); |
314 | 314 | // Set a flag to indicate the some legacy gets were found |
315 | - $legacyPolyfillTags = []; |
|
315 | + $legacyPolyfillTags = [ ]; |
|
316 | 316 | if (!empty($legacyTags)) { |
317 | 317 | $this->hasLegacyTags = true; |
318 | 318 | } |
@@ -334,20 +334,20 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @return array |
336 | 336 | */ |
337 | - protected function extractManifestTags(string $path, bool $asyncCss = true, array $scriptTagAttrs = [], array $cssTagAttrs = [], $legacy = false): array |
|
337 | + protected function extractManifestTags(string $path, bool $asyncCss = true, array $scriptTagAttrs = [ ], array $cssTagAttrs = [ ], $legacy = false): array |
|
338 | 338 | { |
339 | - $tags = []; |
|
339 | + $tags = [ ]; |
|
340 | 340 | // Grab the manifest |
341 | - $pathOrUrl = (string)Craft::parseEnv($this->manifestPath); |
|
342 | - $manifest = $this->fetchFile($pathOrUrl, [JsonHelper::class, 'decodeIfJson']); |
|
341 | + $pathOrUrl = (string) Craft::parseEnv($this->manifestPath); |
|
342 | + $manifest = $this->fetchFile($pathOrUrl, [ JsonHelper::class, 'decodeIfJson' ]); |
|
343 | 343 | // If no manifest file is found, bail |
344 | 344 | if ($manifest === null) { |
345 | - Craft::error('Manifest not found at ' . $this->manifestPath, __METHOD__); |
|
345 | + Craft::error('Manifest not found at '.$this->manifestPath, __METHOD__); |
|
346 | 346 | |
347 | - return []; |
|
347 | + return [ ]; |
|
348 | 348 | } |
349 | 349 | // Set the async CSS args |
350 | - $asyncCssOptions = []; |
|
350 | + $asyncCssOptions = [ ]; |
|
351 | 351 | if ($asyncCss) { |
352 | 352 | $asyncCssOptions = [ |
353 | 353 | 'media' => 'print', |
@@ -366,21 +366,21 @@ discard block |
||
366 | 366 | } |
367 | 367 | // Iterate through the manifest |
368 | 368 | foreach ($manifest as $manifestFile => $entry) { |
369 | - if (isset($entry['isEntry']) && $entry['isEntry']) { |
|
369 | + if (isset($entry[ 'isEntry' ]) && $entry[ 'isEntry' ]) { |
|
370 | 370 | // Include the entry script |
371 | - if (isset($entry['file']) && strpos($path, $manifestFile) !== false) { |
|
372 | - $url = $this->createUrl($this->serverPublic, $entry['file']); |
|
373 | - $tags[] = [ |
|
371 | + if (isset($entry[ 'file' ]) && strpos($path, $manifestFile) !== false) { |
|
372 | + $url = $this->createUrl($this->serverPublic, $entry[ 'file' ]); |
|
373 | + $tags[ ] = [ |
|
374 | 374 | 'type' => 'file', |
375 | 375 | 'url' => $url, |
376 | 376 | 'options' => array_merge($scriptOptions, $scriptTagAttrs) |
377 | 377 | ]; |
378 | 378 | // @TODO Imports are actually just a list of dynamic imports, so we probably don't need to be including them |
379 | - if (isset($entry['imports'])) { |
|
380 | - foreach ($entry['imports'] as $import) { |
|
381 | - if (isset($manifest[$import]['file'])) { |
|
382 | - $url = $this->createUrl($this->serverPublic, $manifest[$import]['file']); |
|
383 | - $tags[] = [ |
|
379 | + if (isset($entry[ 'imports' ])) { |
|
380 | + foreach ($entry[ 'imports' ] as $import) { |
|
381 | + if (isset($manifest[ $import ][ 'file' ])) { |
|
382 | + $url = $this->createUrl($this->serverPublic, $manifest[ $import ][ 'file' ]); |
|
383 | + $tags[ ] = [ |
|
384 | 384 | 'type' => 'imports', |
385 | 385 | 'url' => $url, |
386 | 386 | 'options' => array_merge([ |
@@ -391,10 +391,10 @@ discard block |
||
391 | 391 | ]; |
392 | 392 | } |
393 | 393 | // Handle CSS inside of imports |
394 | - if (isset($manifest[$import]['css'])) { |
|
395 | - foreach ($manifest[$import]['css'] as $css) { |
|
394 | + if (isset($manifest[ $import ][ 'css' ])) { |
|
395 | + foreach ($manifest[ $import ][ 'css' ] as $css) { |
|
396 | 396 | $url = $this->createUrl($this->serverPublic, $css); |
397 | - $tags[] = [ |
|
397 | + $tags[ ] = [ |
|
398 | 398 | 'type' => 'css', |
399 | 399 | 'url' => $url, |
400 | 400 | 'options' => array_merge([ |
@@ -406,10 +406,10 @@ discard block |
||
406 | 406 | } |
407 | 407 | } |
408 | 408 | // If there are any CSS files, include them |
409 | - if (isset($entry['css'])) { |
|
410 | - foreach ($entry['css'] as $css) { |
|
409 | + if (isset($entry[ 'css' ])) { |
|
410 | + foreach ($entry[ 'css' ] as $css) { |
|
411 | 411 | $url = $this->createUrl($this->serverPublic, $css); |
412 | - $tags[] = [ |
|
412 | + $tags[ ] = [ |
|
413 | 413 | 'type' => 'css', |
414 | 414 | 'url' => $url, |
415 | 415 | 'options' => array_merge([ |
@@ -435,8 +435,8 @@ discard block |
||
435 | 435 | */ |
436 | 436 | protected function createUrl(string $url, string $path): string |
437 | 437 | { |
438 | - $url = (string)Craft::parseEnv($url); |
|
439 | - return rtrim($url, '/') . '/' . trim($path, '/'); |
|
438 | + $url = (string) Craft::parseEnv($url); |
|
439 | + return rtrim($url, '/').'/'.trim($path, '/'); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | /** |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | // Create the dependency tags |
452 | 452 | $dependency = new TagDependency([ |
453 | 453 | 'tags' => [ |
454 | - self::CACHE_TAG . $this->cacheKeySuffix, |
|
455 | - self::CACHE_TAG . $this->cacheKeySuffix . $pathOrUrl, |
|
454 | + self::CACHE_TAG.$this->cacheKeySuffix, |
|
455 | + self::CACHE_TAG.$this->cacheKeySuffix.$pathOrUrl, |
|
456 | 456 | ], |
457 | 457 | ]); |
458 | 458 | // If this is a file path such as for the `manifest.json`, add a FileDependency so it's cache bust if the file changes |
@@ -473,8 +473,8 @@ discard block |
||
473 | 473 | // Get the result from the cache, or parse the file |
474 | 474 | $cache = Craft::$app->getCache(); |
475 | 475 | $file = $cache->getOrSet( |
476 | - self::CACHE_KEY . $this->cacheKeySuffix . $pathOrUrl, |
|
477 | - function () use ($pathOrUrl, $callback) { |
|
476 | + self::CACHE_KEY.$this->cacheKeySuffix.$pathOrUrl, |
|
477 | + function() use ($pathOrUrl, $callback) { |
|
478 | 478 | $contents = null; |
479 | 479 | $result = null; |
480 | 480 | if (UrlHelper::isAbsoluteUrl($pathOrUrl)) { |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return Markup |
49 | 49 | */ |
50 | - public function script(string $path, bool $asyncCss = true, array $scriptTagAttrs = [], array $cssTagAttrs = []): Markup |
|
50 | + public function script(string $path, bool $asyncCss = true, array $scriptTagAttrs = [ ], array $cssTagAttrs = [ ]): Markup |
|
51 | 51 | { |
52 | 52 | return Template::raw( |
53 | 53 | $this->viteService->script($path, $asyncCss, $scriptTagAttrs, $cssTagAttrs) |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return string |
67 | 67 | * @throws InvalidConfigException |
68 | 68 | */ |
69 | - public function register(string $path, bool $asyncCss = true, array $scriptTagAttrs = [], array $cssTagAttrs = []): string |
|
69 | + public function register(string $path, bool $asyncCss = true, array $scriptTagAttrs = [ ], array $cssTagAttrs = [ ]): string |
|
70 | 70 | { |
71 | 71 | $this->viteService->register($path, $asyncCss, $scriptTagAttrs, $cssTagAttrs); |
72 | 72 |