MAPG-187 refactor view parsing and linking
This commit is contained in:
2 files changed
+14
-17
No files matched your search
+12
-15
@@ -108,7 +108,7 @@ class Linker
|
||||
private function generateAssets(ParsedFragment $fragment, array &$sections)
|
||||
{
|
||||
foreach ($fragment->getCss() as $cssFile) {
|
||||
$asset = $this->parseAsset($cssFile, 'css');
|
||||
$asset = $this->parseAsset($cssFile);
|
||||
if (isset($asset['code'])) {
|
||||
$sections['inlineCss'] .= '<style>' . PHP_EOL;
|
||||
$sections['inlineCss'] .= $asset['code'];
|
||||
@@ -119,7 +119,7 @@ class Linker
|
||||
}
|
||||
|
||||
foreach ($fragment->getJs() as $jsFile) {
|
||||
$asset = $this->parseAsset($jsFile, 'js');
|
||||
$asset = $this->parseAsset($jsFile);
|
||||
if (isset($asset['code'])) {
|
||||
$sections['inlineJs'] .= '<script>' . PHP_EOL;
|
||||
$sections['inlineJs'] .= $asset['code'];
|
||||
@@ -130,24 +130,21 @@ class Linker
|
||||
}
|
||||
}
|
||||
|
||||
private function parseAsset(string $asset, string $type): array
|
||||
private function parseAsset(string $asset): array
|
||||
{
|
||||
$output = [];
|
||||
|
||||
eval('$asset = ' . $asset . ';');
|
||||
|
||||
if (
|
||||
empty($_ENV['DEV']) &&
|
||||
preg_match('/^' . $type . '\/.*/', $asset) &&
|
||||
filesize(ROOT . '/public/static/' . $asset) < self::INLINE_ASSET_LIMIT
|
||||
) {
|
||||
$output['code'] = file_get_contents(ROOT . '/public/static/' . $asset);
|
||||
} else {
|
||||
if (!preg_match('/^http(s)?/', $asset)) {
|
||||
$output['file'] = $_ENV['STATIC_ROOT'] . '/' . $asset . '?rev=<?= REVISION ?>';
|
||||
if (preg_match('/^[\w\/\.]+$/', $asset)) {
|
||||
if (
|
||||
empty($_ENV['DEV']) &&
|
||||
filesize(ROOT . '/public/static/' . $asset) < self::INLINE_ASSET_LIMIT
|
||||
) {
|
||||
$output['code'] = file_get_contents(ROOT . '/public/static/' . $asset);
|
||||
} else {
|
||||
$output['file'] = $asset;
|
||||
$output['file'] = '<?= $_ENV[\'STATIC_ROOT\'] ?>/' . $asset . '?rev=<?= REVISION ?>';
|
||||
}
|
||||
} else {
|
||||
$output['file'] = $asset;
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
Reference in new issue
Block a user