- Added a token to asset keyword

This commit is contained in:
Dave Mc Nicoll 2019-12-20 12:27:41 -05:00
parent a56b64cf49
commit a64989af9f
1 changed files with 15 additions and 2 deletions

View File

@ -6,15 +6,24 @@ class UrlExtension implements Extension {
protected string $urlBase;
public array $tokens = [ "url" , "route" ];
protected string $assetToken;
public function __construct(string $urlBase = "") {
public array $tokens = [ "url" , "route", "asset" ];
public function __construct(string $urlBase = "", string $assetToken = "") {
$this->urlBase = $urlBase;
$this->assetToken = $assetToken;
}
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : ?string
{
switch($token) {
case "asset":
return "<?php echo \$___picea->compiler->getExtensionFromToken('$token')->buildAssetUrl($arguments) ?>";
case "route":
return "<?php echo \$___picea->compiler->getExtensionFromToken('$token')->buildUrl($arguments) ?>";
case "url":
return "<?php echo \$___picea->compiler->getExtensionFromToken('$token')->buildUrl($arguments) ?>";
}
@ -27,6 +36,10 @@ class UrlExtension implements Extension {
return $this->url() . $uri . ( $parameters ? "?" . http_build_query($parameters) : "" );
}
public function buildAssetUrl(string $uri, array $parameters = []) : string
{
return $this->url() . $uri . "?" . http_build_query( array_replace([ 'token' => $this->assetToken ], $parameters) );
}
public function url() : string
{