MAPG-187 refactor view parsing and linking
This commit is contained in:
parent
71b1e28aa9
commit
e883d184b7
@ -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,25 +130,22 @@ class Linker
|
||||
}
|
||||
}
|
||||
|
||||
private function parseAsset(string $asset, string $type): array
|
||||
private function parseAsset(string $asset): array
|
||||
{
|
||||
$output = [];
|
||||
|
||||
eval('$asset = ' . $asset . ';');
|
||||
|
||||
if (preg_match('/^[\w\/\.]+$/', $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 ?>';
|
||||
$output['file'] = '<?= $_ENV[\'STATIC_ROOT\'] ?>/' . $asset . '?rev=<?= REVISION ?>';
|
||||
}
|
||||
} else {
|
||||
$output['file'] = $asset;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class Parser
|
||||
|
||||
private function matchExtends(string $line): ?string
|
||||
{
|
||||
if (preg_match('/^\s*@extends\(\'([\w\/]+)\'\)\s*$/', $line, $matches)) {
|
||||
if (preg_match('/^\s*@extends\(([\w\/]+)\)\s*$/', $line, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ class Parser
|
||||
|
||||
private function matchSection(string $line): ?string
|
||||
{
|
||||
if (preg_match('/^\s*@section\(\'(\w+)\'\)\s*$/', $line, $matches)) {
|
||||
if (preg_match('/^\s*@section\((\w+)\)\s*$/', $line, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user