| 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\Exception\FileNotFoundException; |
| 17 |
|
| 18 |
/** |
| 19 |
* @package Inpsyde\Assets\Loader |
| 20 |
*/ |
| 21 |
class PhpFileLoader extends ArrayLoader |
| 22 |
{ |
| 23 |
/** |
| 24 |
* @param mixed $resource the path to your php-file. |
| 25 |
* @return array |
| 26 |
* |
| 27 |
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration |
| 28 |
* @psalm-suppress UnresolvableInclude |
| 29 |
*/ |
| 30 |
public function load($resource): array |
| 31 |
{ |
| 32 |
|
| 33 |
if (!is_string($resource) || !is_readable($resource)) { |
| 34 |
throw new FileNotFoundException( |
| 35 |
sprintf( |
| 36 |
'The given file "%s" does not exists or is not readable.', |
| 37 |
(string) $resource |
| 38 |
) |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
$data = require $resource; |
| 43 |
|
| 44 |
return parent::load($data); |
| 45 |
} |
| 46 |
} |
| 47 |
|