Compare commits

..

No commits in common. "14cfb46c98164bbebd014a5741637925b9efddfa" and "5bac6cd843d7a8da85bb5e462943407f173eeb26" have entirely different histories.

3 changed files with 42 additions and 11 deletions

View File

@ -14,8 +14,8 @@ class UrlExtension implements Extension {
protected array $routesTarget; protected array $routesTarget;
public array $tokens = [ "url" , "route", "route.cacheless", "asset", "url.current", "url.parameters", "slug" ]; public array $tokens = [ "url" , "route", "asset", "url.current", "url.parameters", "slug" ];
public function __construct(Context $context, string $urlBase = "", string $assetToken = "") { public function __construct(Context $context, string $urlBase = "", string $assetToken = "") {
$this->urlBase = trim($urlBase, "/"); $this->urlBase = trim($urlBase, "/");
$this->assetToken = $assetToken; $this->assetToken = $assetToken;
@ -71,20 +71,20 @@ class UrlExtension implements Extension {
return $this->buildUrl($this->uri(), $parameters); return $this->buildUrl($this->uri(), $parameters);
} }
public function buildUrl(string $uri = "", array $parameters = [], bool $appendVersion = false) : string public function buildUrl(string $uri = "", array $parameters = []) : string
{ {
return $this->setUrlParameters($this->url() . "/" . ltrim($uri, "/"), $appendVersion ? array_replace([ 'v' => $this->assetToken ], $parameters) : $parameters); return $this->setUrlParameters($this->url() . "/" . ltrim($uri, "/"), $parameters);
} }
public function buildAssetUrl(string $uri, array $parameters = [], bool $appendVersion = true) : string public function buildAssetUrl(string $uri, array $parameters = []) : string
{ {
return $this->buildUrl($uri, $parameters, $appendVersion); return $this->buildUrl($uri, array_replace([ 'v' => $this->assetToken ], $parameters));
} }
public function buildRouteUrl(string $name, array $parameters = [], bool $appendVersion = false) : string public function buildRouteUrl(string $name, array $parameters = []) : string
{ {
if ( false !== ( $route = $this->routes[$name] ?? false ) ) { if ( false !== ( $route = $this->routes[$name] ?? false ) ) {
return $this->buildUrl($this->prepareRoute($route['route'], $parameters), $parameters, $appendVersion); return $this->buildUrl($this->prepareRoute($route['route'], $parameters), $parameters);
} }
$routeList = json_encode($this->routes, \JSON_PRETTY_PRINT); $routeList = json_encode($this->routes, \JSON_PRETTY_PRINT);
@ -174,7 +174,7 @@ class UrlExtension implements Extension {
$_SERVER['Front-End-Https'] ?? "", $_SERVER['Front-End-Https'] ?? "",
$_SERVER['X-Forwarded-Proto'] ?? "", $_SERVER['X-Forwarded-Proto'] ?? "",
$_SERVER['X-Forwarded-Protocol'] ?? "", $_SERVER['X-Forwarded-Protocol'] ?? "",
$_SERVER['HTTP_X_FORWARDED_PROTO'] ?? "", $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? "",
$_SERVER['HTTP_X_FORWARDED_PROTOCOL'] ?? "", $_SERVER['HTTP_X_FORWARDED_PROTOCOL'] ?? "",
])) || isset($_SERVER['HTTP_X_ARR_SSL']); ])) || isset($_SERVER['HTTP_X_ARR_SSL']);
@ -193,7 +193,7 @@ class UrlExtension implements Extension {
list($variable, $default) = explode('=', $item[1]); list($variable, $default) = explode('=', $item[1]);
} }
elseif (strpos($item[1], ":") !== false) { elseif (strpos($item[1], ":") !== false) {
list($variable, ) = explode(':', $item[1]); list($variable, $type) = explode(':', $item[1]);
} }
else { else {
$variable = $item[1]; $variable = $item[1];
@ -201,6 +201,7 @@ class UrlExtension implements Extension {
if ( array_key_exists($variable, $arguments) ) { if ( array_key_exists($variable, $arguments) ) {
$value = $arguments[ $variable ]; $value = $arguments[ $variable ];
unset($arguments[ $variable ]); unset($arguments[ $variable ]);
} }
else { else {
@ -208,12 +209,22 @@ class UrlExtension implements Extension {
} }
$search[ $item[0] ] = $value; $search[ $item[0] ] = $value;
} }
$route = str_replace(array_keys($search), array_values($search), $route); $route = str_replace(array_keys($search), array_values($search), $route);
} }
/*
* @TODO - must also take into account that recursivity is possible here [/test[/another[/still]]],
* so the regex must be adjusted (or simply using another method could also be a possiblity)
* while(strpos($route, '[') !== false && strpos($route, ']') !== false ) {
if ( preg_match_all('~[(.*?)]~si', $route, $matches, PREG_SET_ORDER) ) {
}
}*/
$route = trim(str_replace([ '[', ']' ], '', $route), '/');
return $route; return $route;
} }
} }

View File

@ -28,6 +28,7 @@ class DefaultRegistrations implements LanguageRegistration
public function registerSyntax(Compiler $compiler) : void public function registerSyntax(Compiler $compiler) : void
{ {
$compiler->registerSyntax(new \Picea\Syntax\PhpTagToken());
$compiler->registerSyntax(new \Picea\Syntax\CommentToken()); $compiler->registerSyntax(new \Picea\Syntax\CommentToken());
$compiler->registerSyntax(new \Picea\Syntax\EchoRawToken()); $compiler->registerSyntax(new \Picea\Syntax\EchoRawToken());
$compiler->registerSyntax(new \Picea\Syntax\EchoSafeToken()); $compiler->registerSyntax(new \Picea\Syntax\EchoSafeToken());
@ -48,6 +49,7 @@ class DefaultRegistrations implements LanguageRegistration
$compiler->registerControlStructure(new \Picea\ControlStructure\SwitchToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\SwitchToken());
$compiler->registerControlStructure(new \Picea\ControlStructure\DefaultToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\DefaultToken());
$compiler->registerControlStructure(new \Picea\ControlStructure\BreakToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\BreakToken());
$compiler->registerControlStructure(new \Picea\ControlStructure\ContinueToken());
$compiler->registerControlStructure(new \Picea\ControlStructure\ExtendsToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\ExtendsToken());
$compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken());
$compiler->registerControlStructure(new \Picea\ControlStructure\FunctionToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\FunctionToken());

View File

@ -0,0 +1,18 @@
<?php
namespace Picea\Syntax;
class PhpTagToken implements Syntax {
public string $tokenOpen = "\{\?";
public string $tokenClose = "\?\}";
public function parse(/*\Picae\Compiler\Context*/ &$context, string &$sourceCode)
{
$sourceCode = preg_replace_callback("#({$this->tokenOpen})(.*?)({$this->tokenClose})#s", function ($matches) {
return "<?php {$matches[2]} ?>";
}, $sourceCode);
}
}