| 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 |
/** |
| 17 |
* Implementation of Webpack manifest.json parsing into Assets. |
| 18 |
* |
| 19 |
* @link https://www.npmjs.com/package/webpack-manifest-plugin |
| 20 |
* |
| 21 |
* @package Inpsyde\Assets\Loader |
| 22 |
*/ |
| 23 |
class WebpackManifestLoader extends AbstractWebpackLoader |
| 24 |
{ |
| 25 |
/** |
| 26 |
* {@inheritDoc} |
| 27 |
*/ |
| 28 |
protected function parseData(array $data, string $resource): array |
| 29 |
{ |
| 30 |
$directory = trailingslashit(dirname($resource)); |
| 31 |
$assets = []; |
| 32 |
foreach ($data as $handle => $file) { |
| 33 |
// It can be possible, that the "handle"-key is a filepath. |
| 34 |
$handle = pathinfo($handle, PATHINFO_FILENAME); |
| 35 |
|
| 36 |
$sanitizedFile = $this->sanitizeFileName($file); |
| 37 |
|
| 38 |
$fileUrl = (! $this->directoryUrl) |
| 39 |
? $file |
| 40 |
: $this->directoryUrl . $sanitizedFile; |
| 41 |
|
| 42 |
$filePath = $directory . $sanitizedFile; |
| 43 |
|
| 44 |
$asset = $this->buildAsset($handle, $fileUrl, $filePath); |
| 45 |
if ($asset !== null) { |
| 46 |
$assets[] = $asset; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
return $assets; |
| 51 |
} |
| 52 |
} |
| 53 |
|