- Added a token to asset keyword
This commit is contained in:
parent
a56b64cf49
commit
a64989af9f
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue