PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.14
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.14
1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 1.3.47 1.3.46 1.3.45 All 177 releases
disco / vendor / inpsyde / assets / src / Loader / EncoreEntrypointsLoader.php

EncoreEntrypointsLoader.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.14, at vendor/inpsyde/assets/src/Loader/EncoreEntrypointsLoader.php

91 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Assets package.
5 *
6 * (c) Inpsyde GmbH
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 declare(strict_types=1);
13
14 namespace Inpsyde\Assets\Loader;
15
16 use Inpsyde\Assets\Asset;
17
18 /**
19 * Implementation of Symfony's Encore implementation of entrypoints.json which
20 * supports splitEntryChunks and hashing.
21 *
22 * @package Inpsyde\Assets\Loader
23 */
24 class EncoreEntrypointsLoader extends AbstractWebpackLoader implements LoaderInterface
25 {
26 /**
27 * {@inheritDoc}
28 */
29 protected function parseData(array $data, string $resource): array
30 {
31 $directory = trailingslashit(dirname($resource));
32 /** @var array{entrypoints:array{css?:string[], js?:string[]}} $data */
33 $data = $data['entrypoints'] ?? [];
34
35 $assets = [];
36 foreach ($data as $handle => $filesByExtension) {
37 $files = $filesByExtension['css'] ?? [];
38 $assets = array_merge($assets, $this->extractAssets($handle, $files, $directory));
39
40 $files = $filesByExtension['js'] ?? [];
41 $assets = array_merge($assets, $this->extractAssets($handle, $files, $directory));
42 }
43
44 return $assets;
45 }
46
47 /**
48 * @param string $handle
49 * @param string[] $files
50 * @param string $directory
51 *
52 * @return array
53 */
54 protected function extractAssets(string $handle, array $files, string $directory): array
55 {
56 $assets = [];
57
58 foreach ($files as $i => $file) {
59 $handle = $i > 0
60 ? "{$handle}-{$i}"
61 : $handle;
62
63 $sanitizedFile = $this->sanitizeFileName($file);
64
65 $fileUrl = (!$this->directoryUrl)
66 ? $file
67 : $this->directoryUrl . $sanitizedFile;
68
69 $filePath = $directory . $sanitizedFile;
70
71 $asset = $this->buildAsset($handle, $fileUrl, $filePath);
72
73 if ($asset !== null) {
74 $assets[] = $asset;
75 }
76 }
77
78 foreach ($assets as $i => $asset) {
79 $dependencies = array_map(
80 static function (Asset $asset): string {
81 return $asset->handle();
82 },
83 array_slice($assets, 0, $i)
84 );
85 $asset->withDependencies(...$dependencies);
86 }
87
88 return $assets;
89 }
90 }
91