42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace KupShop\AdminBundle\Util;
|
|
|
|
use KupShop\KupShopBundle\Util\StringUtil;
|
|
|
|
class AssetsReactLoader
|
|
{
|
|
public static function getAssets($location, $sslIgnore = false)
|
|
{
|
|
if ($sslIgnore) {
|
|
$arrContextOptions = stream_context_create([
|
|
'ssl' => [
|
|
'verify_peer' => false,
|
|
'verify_peer_name' => false,
|
|
],
|
|
]);
|
|
}
|
|
|
|
$assets = json_decode(file_get_contents(rtrim($location, '/').'/asset-manifest.json', false, $arrContextOptions ?? null), true);
|
|
|
|
$loadLocation = ltrim($location, '.');
|
|
$assetEntryPoints = $assets['entrypoints'] ?? $assets;
|
|
if ($assetEntryPoints === null && isDevelopment()) {
|
|
throw new \RuntimeException("Action needed: in wpj container run command: 'update_automation_configurator.sh'");
|
|
}
|
|
|
|
$assets = array_map(function ($val) use ($loadLocation) {
|
|
return $loadLocation.$val;
|
|
}, $assetEntryPoints);
|
|
|
|
return ['js' => array_filter($assets,
|
|
function ($x) {
|
|
return StringUtil::endsWith($x, '.js');
|
|
}),
|
|
'css' => array_filter($assets,
|
|
function ($x) {
|
|
return StringUtil::endsWith($x, '.css');
|
|
}), ];
|
|
}
|
|
}
|