Skip to content

Commit

Permalink
Extension: Add support for base scripts in all templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Feb 12, 2020
1 parent b551b9f commit 844273d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/LoaderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ class LoaderExtension extends CompilerExtension
public function afterCompile(ClassType $class): void
{
$assets = [];
$files = $this->getConfig()['routing'] ?? [];

foreach ($this->getConfig()['routing'] as $route => $assetFiles) {
if (isset($this->getConfig()['base']) === true) {
$files = array_merge($files, ['base' => $this->getConfig()['base']]);
}

foreach ($files as $route => $assetFiles) {
foreach ($assetFiles as $assetFile) {
if (preg_match('/^(?<name>.+)\.(?<format>[a-zA-Z0-9]+)$/', $assetFile, $fileParser)) {
if (isset($assets[$route][$fileParser['format']]) === false) {
Expand All @@ -40,7 +45,9 @@ public function afterCompile(ClassType $class): void

$class->addMethod('getBarajaAssetsLoader')
->setReturnType('array')
->setBody('return $route === null ? ($this->' . self::PROPERTY_NAME . ' ?? []) : ($this->' . self::PROPERTY_NAME . '[$route] ?? []);')
->setBody('return $route === null '
. '? $this->' . self::PROPERTY_NAME . ' '
. ': array_merge($this->' . self::PROPERTY_NAME . '[$route] ?? [], $this->' . self::PROPERTY_NAME . '[\'base\'] ?? []);')
->addParameter('route', null)
->setType('string')
->setNullable(true);
Expand All @@ -54,4 +61,4 @@ public function afterCompile(ClassType $class): void
);
}

}
}

0 comments on commit 844273d

Please sign in to comment.