| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package WPEmergeAppCore |
| 4 |
* @author Atanas Angelov <hi@atanas.dev> |
| 5 |
* @copyright 2017-2020 Atanas Angelov |
| 6 |
* @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0 |
| 7 |
* @link https://wpemerge.com/ |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace WPEmergeAppCore\Assets; |
| 11 |
|
| 12 |
use WPEmerge\Helpers\MixedType; |
| 13 |
use WPEmergeAppCore\Concerns\JsonFileNotFoundException; |
| 14 |
use WPEmergeAppCore\Concerns\ReadsJsonTrait; |
| 15 |
|
| 16 |
class Manifest { |
| 17 |
use ReadsJsonTrait { |
| 18 |
load as traitLoad; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* App root path. |
| 23 |
* |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
protected $path = ''; |
| 27 |
|
| 28 |
/** |
| 29 |
* Constructor. |
| 30 |
* |
| 31 |
* @param string $path |
| 32 |
*/ |
| 33 |
public function __construct( $path ) { |
| 34 |
$this->path = $path; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* {@inheritDoc} |
| 39 |
*/ |
| 40 |
protected function getJsonPath() { |
| 41 |
return MixedType::normalizePath( $this->path . DIRECTORY_SEPARATOR . 'dist' . DIRECTORY_SEPARATOR . 'manifest.json' ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* {@inheritDoc} |
| 46 |
*/ |
| 47 |
protected function load( $file ) { |
| 48 |
try { |
| 49 |
return $this->traitLoad( $file ); |
| 50 |
} catch ( JsonFileNotFoundException $e ) { |
| 51 |
// We used to throw an exception here but it just causes confusion for new users. |
| 52 |
} |
| 53 |
|
| 54 |
return []; |
| 55 |
} |
| 56 |
} |
| 57 |
|