diff --git a/src/Caching/Opcache.php b/src/Caching/Opcache.php index 7c0c940..5970e3e 100644 --- a/src/Caching/Opcache.php +++ b/src/Caching/Opcache.php @@ -54,7 +54,7 @@ class Opcache implements Cache { } if ( file_exists($path = $this->cachePath($viewPath)) ) { - $this->compiled[$viewPath] = require_once($path); + $this->compiled[$viewPath] = include($path); return true; } @@ -82,6 +82,6 @@ class Opcache implements Cache { protected function cachePath(string $fileName = "") : string { - return implode(DIRECTORY_SEPARATOR, array_filter([ $this->cachePath, $this->cacheFolder, $fileName ? str_replace([ "/", DIRECTORY_SEPARATOR ], "_", $fileName . ".php") : null ])); + return implode(DIRECTORY_SEPARATOR, array_filter([ $this->cachePath, $this->cacheFolder, $fileName ? str_replace([ "/", DIRECTORY_SEPARATOR ], "~", $fileName . ".php") : null ])); } } diff --git a/src/ControlStructure/OrToken.php b/src/ControlStructure/OrToken.php index 862cbab..7f9490d 100644 --- a/src/ControlStructure/OrToken.php +++ b/src/ControlStructure/OrToken.php @@ -13,7 +13,7 @@ class OrToken implements ControlStructure { $key = count( $context->iterationStack ) - 1; $context->iterationStack[$key]['or'] = true; - return "iterationStack[$key]['token']}; if(false === {$context->iterationStack[$key]['uid']} ?? false): ?>"; + return "iterationStack[$key]['token']}; if( false === ({$context->iterationStack[$key]['uid']} ?? false) ): ?>"; } } diff --git a/src/Extension/UrlExtension.php b/src/Extension/UrlExtension.php index 1aefb7f..eb46764 100644 --- a/src/Extension/UrlExtension.php +++ b/src/Extension/UrlExtension.php @@ -4,10 +4,63 @@ namespace Picea\Extension; class UrlExtension implements Extension { + protected string $urlBase; + public array $tokens = [ "url" , "route" ]; + + public function __construct(string $urlBase = "") { + $this->urlBase = $urlBase; + } + + public function addRoute(string $routeName, string $url, array $parameters = []) + { + + } public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { return ""; } + + /** + * Return URI formatted + */ + public function uri($query_string = false) { + $uri = $_SERVER['REQUEST_URI'] ?? $this->php_self() . ($query_string ? $this->query_string() : ""); -} + if ( ! $query_string ) { + $uri = explode('?', $uri, 2)[0]; + } + + if (($base = $this->config['base'] ?? false) && ( stripos($uri, $base) === 0 )) { + $uri = substr($uri, strlen($base)); + } + return '/' . ltrim($uri, '/'); + } + + public function php_self() { + return isset($_SERVER['PHP_SELF']) ? str_replace(NEX . '/', '', $_SERVER['PHP_SELF']) : null; + } + + /** + * Return query string + */ + public function query_string() { + return isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ""; + } + + /** + * Check if Uri's segments are valid + * @param array $segments The uri's segments + */ + public function secure($segments = []) { + return array_diff($segments, ['..', '://']); + } + + public function domain() { + $domain_list = (array) $this->config('Eckinox.system.url.root'); + $current = strtolower($_SERVER['HTTP_HOST']); + + return $domain = in_array($current, $domain_list) ? $current : $domain_list[0]; + } + +} \ No newline at end of file