| 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\AssetFactory; |
| 17 |
use Inpsyde\Assets\Asset; |
| 18 |
use Inpsyde\Assets\BaseAsset; |
| 19 |
use Inpsyde\Assets\ConfigureAutodiscoverVersionTrait; |
| 20 |
|
| 21 |
/** |
| 22 |
* @package Inpsyde\Assets\Loader |
| 23 |
*/ |
| 24 |
class ArrayLoader implements LoaderInterface |
| 25 |
{ |
| 26 |
use ConfigureAutodiscoverVersionTrait; |
| 27 |
|
| 28 |
/** |
| 29 |
* @param mixed $resource |
| 30 |
* |
| 31 |
* @return array |
| 32 |
* |
| 33 |
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration |
| 34 |
* @psalm-suppress MixedArgument |
| 35 |
*/ |
| 36 |
public function load($resource): array |
| 37 |
{ |
| 38 |
$assets = array_map( |
| 39 |
[AssetFactory::class, 'create'], |
| 40 |
(array) $resource |
| 41 |
); |
| 42 |
|
| 43 |
return array_map( |
| 44 |
function (Asset $asset): Asset { |
| 45 |
if ($asset instanceof BaseAsset) { |
| 46 |
$this->autodiscoverVersion |
| 47 |
? $asset->enableAutodiscoverVersion() |
| 48 |
: $asset->disableAutodiscoverVersion(); |
| 49 |
} |
| 50 |
return $asset; |
| 51 |
}, |
| 52 |
$assets |
| 53 |
); |
| 54 |
} |
| 55 |
} |
| 56 |
|