- Remove the old {? / ?} token as a PHP opening

- Added url versions if needed
This commit is contained in:
Dave M. 2022-10-12 18:25:39 +00:00
parent 45c8173029
commit 08201b1958
3 changed files with 11 additions and 41 deletions

View File

@ -14,7 +14,7 @@ class UrlExtension implements Extension {
protected array $routesTarget;
public array $tokens = [ "url" , "route", "asset", "url.current", "url.parameters" ];
public array $tokens = [ "url" , "route", "route.cacheless", "asset", "url.current", "url.parameters" ];
public function __construct(Context $context, string $urlBase = "", string $assetToken = "") {
$this->urlBase = trim($urlBase, "/");
@ -67,20 +67,20 @@ class UrlExtension implements Extension {
return $this->buildUrl($this->uri(), $parameters);
}
public function buildUrl(string $uri = "", array $parameters = []) : string
public function buildUrl(string $uri = "", array $parameters = [], bool $appendVersion = false) : string
{
return $this->setUrlParameters($this->url() . "/" . ltrim($uri, "/"), $parameters);
return $this->setUrlParameters($this->url() . "/" . ltrim($uri, "/"), $appendVersion ? array_replace([ 'v' => $this->assetToken ], $parameters) : $parameters);
}
public function buildAssetUrl(string $uri, array $parameters = []) : string
public function buildAssetUrl(string $uri, array $parameters = [], bool $appendVersion = true) : string
{
return $this->buildUrl($uri, array_replace([ 'v' => $this->assetToken ], $parameters));
return $this->buildUrl($uri, $parameters, $appendVersion);
}
public function buildRouteUrl(string $name, array $parameters = []) : string
public function buildRouteUrl(string $name, array $parameters = [], bool $appendVersion = false) : string
{
if ( false !== ( $route = $this->routes[$name] ?? false ) ) {
return $this->buildUrl($this->prepareRoute($route['route'], $parameters), $parameters);
return $this->buildUrl($this->prepareRoute($route['route'], $parameters), $parameters, $appendVersion);
}
$routeList = json_encode($this->routes, \JSON_PRETTY_PRINT);
@ -165,7 +165,7 @@ class UrlExtension implements Extension {
$_SERVER['X-Forwarded-Ssl'] ?? "",
$_SERVER['X-Forwarded-Proto'] ?? "",
$_SERVER['X-Forwarded-Protocol'] ?? "",
])) || isset($_SERVER['HTTP_X_ARR_SSL']);
]));
return $header
|| ( "443" === ( $_SERVER['SERVER_PORT'] ?? "" ) )
@ -183,7 +183,7 @@ class UrlExtension implements Extension {
list($variable, $default) = explode('=', $item[1]);
}
elseif (strpos($item[1], ":") !== false) {
list($variable, $type) = explode(':', $item[1]);
list($variable, ) = explode(':', $item[1]);
}
else {
$variable = $item[1];
@ -191,7 +191,6 @@ class UrlExtension implements Extension {
if ( array_key_exists($variable, $arguments) ) {
$value = $arguments[ $variable ];
unset($arguments[ $variable ]);
}
else {
@ -199,22 +198,13 @@ class UrlExtension implements Extension {
}
$search[ $item[0] ] = $value;
}
$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;
}
}
}

View File

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

View File

@ -1,18 +0,0 @@
<?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);
}
}