Merge branch 'master' of https://git.mcnd.ca/mcndave/picea
This commit is contained in:
commit
57367968ca
|
@ -16,17 +16,26 @@ PATTERN;
|
||||||
|
|
||||||
protected string $urlBase;
|
protected string $urlBase;
|
||||||
|
|
||||||
|
protected string $appUrl;
|
||||||
|
|
||||||
protected string $assetToken;
|
protected string $assetToken;
|
||||||
|
|
||||||
protected array $routes;
|
protected array $routes;
|
||||||
|
|
||||||
protected array $routesTarget;
|
protected array $routesTarget;
|
||||||
|
|
||||||
|
protected bool $forceSSL = false;
|
||||||
|
|
||||||
public array $tokens = [ "url" , "route", "asset", "slug" ];
|
public array $tokens = [ "url" , "route", "asset", "slug" ];
|
||||||
|
|
||||||
public function __construct(string $urlBase = "", string $assetToken = "") {
|
#[\Deprecated]
|
||||||
|
protected bool $enforceExistingArguments = true;
|
||||||
|
|
||||||
|
public function __construct(string $urlBase = "", string $assetToken = "", string $appUrl = "", bool $forceSSL = false) {
|
||||||
$this->urlBase = trim($urlBase, "/");
|
$this->urlBase = trim($urlBase, "/");
|
||||||
$this->assetToken = $assetToken;
|
$this->assetToken = $assetToken;
|
||||||
|
$this->appUrl = $appUrl;
|
||||||
|
$this->forceSSL = $forceSSL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
||||||
|
@ -166,7 +175,7 @@ PATTERN;
|
||||||
|
|
||||||
protected function scheme() : string
|
protected function scheme() : string
|
||||||
{
|
{
|
||||||
return ( $this->isHttps() ? "https" : "http" ) . "://";
|
return ( $this->forceSSL || $this->isHttps() ? "https" : "http" ) . "://";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function base() : string
|
protected function base() : string
|
||||||
|
@ -185,7 +194,9 @@ PATTERN;
|
||||||
|
|
||||||
protected function domain() : string
|
protected function domain() : string
|
||||||
{
|
{
|
||||||
return strtolower($_SERVER['HTTP_HOST']);
|
$port = $this->isDefaultPort() ? "" : ":" . $_SERVER['SERVER_PORT'];
|
||||||
|
|
||||||
|
return strtolower($this->appUrl ? $this->appUrl . $port : $_SERVER['HTTP_HOST']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isDefaultPort() : bool
|
protected function isDefaultPort() : bool
|
||||||
|
@ -216,26 +227,34 @@ PATTERN;
|
||||||
$search = [];
|
$search = [];
|
||||||
|
|
||||||
foreach($matches as $item) {
|
foreach($matches as $item) {
|
||||||
if (strpos($item[1], "=") !== false) {
|
$default = null;
|
||||||
|
|
||||||
|
$variable = $item[1];
|
||||||
|
|
||||||
|
# Handles default
|
||||||
|
if (strpos($variable, "=") !== false) {
|
||||||
list($variable, $default) = explode('=', $item[1]);
|
list($variable, $default) = explode('=', $item[1]);
|
||||||
}
|
}
|
||||||
elseif (strpos($item[1], ":") !== false) {
|
|
||||||
|
# Handles type
|
||||||
|
if (strpos($variable, ":") !== false) {
|
||||||
list($variable, ) = explode(':', $item[1]);
|
list($variable, ) = explode(':', $item[1]);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$variable = $item[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
||||||
$value = $default ?? "";
|
if ($default ?? false) {
|
||||||
|
$value = $default;
|
||||||
|
}
|
||||||
|
elseif ($this->enforceExistingArguments) {
|
||||||
|
throw new \RuntimeException(sprintf("Error while preparing route %s : could not match variable '%s' into given arguments ( %s )", $route, $variable, json_encode($arguments)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$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);
|
||||||
|
|
|
@ -71,12 +71,12 @@ class Picea implements LanguageRegistration
|
||||||
return call_user_func($object);
|
return call_user_func($object);
|
||||||
}
|
}
|
||||||
catch(\Throwable $ex) {
|
catch(\Throwable $ex) {
|
||||||
# if (! $ex instanceof Exception\RenderHtmlException ) {
|
#if (! $ex instanceof Exception\RenderHtmlException ) {
|
||||||
# throw new Exception\RenderHtmlException($object, $this, "An error occurred trying to render HTML view `$viewPath` : " . $ex->getMessage(), 911, $ex);
|
# throw new Exception\RenderHtmlException($object, $this, "An error occurred trying to render HTML view `$viewPath` : " . $ex->getMessage(), 911, $ex);
|
||||||
# }
|
#}
|
||||||
#else {
|
#else {
|
||||||
throw $ex;
|
throw $ex;
|
||||||
# }
|
#}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit();
|
exit();
|
||||||
|
|
Loading…
Reference in New Issue