Merge branch 'master' of https://git.mcnd.ca/mcndave/picea-asset
This commit is contained in:
commit
58bc2211ad
|
@ -2,13 +2,16 @@
|
|||
|
||||
use Picea\{ Asset, Asset\Action, Language\LanguageRegistration, Ui\Ui };
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
use function DI\{get, autowire, create};
|
||||
|
||||
return [
|
||||
Asset\Asset::class => autowire(Asset\Asset::class),
|
||||
|
||||
Asset\Config::class => create(Asset\Config::class)->constructor(
|
||||
destination: getenv("PUBLIC_PATH") . DIRECTORY_SEPARATOR . "static"
|
||||
Asset\Config::class => fn(ContainerInterface $c) => new Asset\Config(
|
||||
destination: $c->get('config')['picea']['asset']['symlink']['destination'],
|
||||
path: $c->get('config')['picea']['asset']['path'],
|
||||
),
|
||||
|
||||
Asset\FileFetcher::class => function($c) {
|
||||
|
@ -22,4 +25,6 @@ return [
|
|||
Action\InstallActionInterface::class => autowire(Action\Symlink::class),
|
||||
|
||||
LanguageRegistration::class => create(\Lean\PiceaDefaultRegistration::class)->constructor(get('picea.extensions'), [], [], get(Ui::class), get(Asset\Asset::class)),
|
||||
|
||||
\Picea\Extension\UrlExtension::class => create(Asset\Extension\UrlExtension::class)->constructor(get(Asset\Config::class), getenv("URL_BASE"), get('git.commit'), explode(',', getenv('APP_URL')), (bool) getenv('FORCE_SSL')),
|
||||
];
|
|
@ -6,5 +6,6 @@ class Config
|
|||
{
|
||||
public function __construct(
|
||||
public null|string $destination = null,
|
||||
public null|string $path = null,
|
||||
) {}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Picea\Asset\Extension;
|
||||
|
||||
use Picea\Asset\Config;
|
||||
|
||||
class UrlExtension extends \Picea\Extension\UrlExtension {
|
||||
|
||||
protected Config $config;
|
||||
|
||||
public function __construct(Config $config, string $urlBase = "", string $assetToken = "", array $appUrl = [], bool $forceSSL = false) {
|
||||
$this->tokens[] = 'asset:path';
|
||||
$this->config = $config;
|
||||
|
||||
parent::__construct($urlBase, $assetToken, $appUrl, $forceSSL);
|
||||
}
|
||||
|
||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
||||
{
|
||||
if ( $token === 'asset:path' ) {
|
||||
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->buildAssetUrlFromPath($arguments) ?>";
|
||||
}
|
||||
|
||||
return parent::parse($context, $arguments, $token, $options);
|
||||
}
|
||||
|
||||
public function exportFunctions(): array
|
||||
{
|
||||
return array_replace([
|
||||
"asset_path" => [ $this, 'buildAssetUrlFromPath' ],
|
||||
], parent::exportFunctions());
|
||||
}
|
||||
|
||||
public function buildAssetUrlFromPath(string $uri, array $parameters = [], bool $appendVersion = true) : string
|
||||
{
|
||||
return $this->buildAssetUrl( trim($this->config->path, '/') . '/' . $uri, $parameters, $appendVersion);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue