From 2f8abebc44d75cc9fa70ff9b47b50b7c589f4ebc Mon Sep 17 00:00:00 2001 From: Dave M Date: Tue, 20 Oct 2020 19:38:37 +0000 Subject: [PATCH] - Added a new Include token (which was added as RAW content) - Fixed UrlExtension to reflect on notes-routes changes - Added some methods to FileFetcher --- src/ControlStructure/IncludeToken.php | 12 ++++++++++++ src/Extension/AssetExtension.php | 13 ------------- src/Extension/UrlExtension.php | 18 +++++++++++++++--- src/FileFetcher.php | 9 +++++++++ src/Language/DefaultRegistrations.php | 2 +- src/Picea.php | 4 ++++ 6 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 src/ControlStructure/IncludeToken.php delete mode 100644 src/Extension/AssetExtension.php diff --git a/src/ControlStructure/IncludeToken.php b/src/ControlStructure/IncludeToken.php new file mode 100644 index 0000000..b75d253 --- /dev/null +++ b/src/ControlStructure/IncludeToken.php @@ -0,0 +1,12 @@ +picea->inlineContent($arguments); ?>"; + } +} diff --git a/src/Extension/AssetExtension.php b/src/Extension/AssetExtension.php deleted file mode 100644 index 33e45f8..0000000 --- a/src/Extension/AssetExtension.php +++ /dev/null @@ -1,13 +0,0 @@ -"; - } - -} diff --git a/src/Extension/UrlExtension.php b/src/Extension/UrlExtension.php index e906953..0fcbd33 100644 --- a/src/Extension/UrlExtension.php +++ b/src/Extension/UrlExtension.php @@ -12,6 +12,8 @@ class UrlExtension implements Extension { protected array $routes; + protected array $routesTarget; + public array $tokens = [ "url" , "route", "asset", "url.parameters" ]; public function __construct(Context $context, string $urlBase = "", string $assetToken = "") { @@ -46,6 +48,11 @@ class UrlExtension implements Extension { $context->pushFunction("route", [ $this, 'buildRouteUrl' ]); } + public function getRouteList(bool $full = false) : array + { + return $this->routes; + } + public function setUrlParameters(string $url = "", array $parameters = []) : string { return $url . ( $parameters ? "?" . http_build_query($parameters) : "" ); @@ -64,7 +71,7 @@ class UrlExtension implements Extension { public function buildRouteUrl(string $name, array $parameters = []) : string { if ( false !== ( $route = $this->routes[$name] ?? false ) ) { - return $this->buildUrl($this->prepareRoute($route, $parameters), $parameters); + return $this->buildUrl($this->prepareRoute($route['route'], $parameters), $parameters); } $routeList = json_encode($this->routes, \JSON_PRETTY_PRINT); @@ -80,9 +87,14 @@ class UrlExtension implements Extension { return $this->scheme() . $this->domain() . $this->base(); } - public function registerRoute(string $name, string $route) : void + public function registerRoute(string $name, string $route, string $class, string $method, array $routeMethods) : void { - $this->routes[$name] = $route; + $this->routes[$name] = [ + 'route' => $route, + 'routeMethods' => $routeMethods, + 'class' => $class, + 'classMethod' => $method, + ]; } /** diff --git a/src/FileFetcher.php b/src/FileFetcher.php index 7a069c2..f827a2c 100644 --- a/src/FileFetcher.php +++ b/src/FileFetcher.php @@ -50,6 +50,15 @@ class FileFetcher } } + # Fallback on full-path + foreach($this->folderList as $folder) { + $file = $folder['path'] . DIRECTORY_SEPARATOR . $fileName; + + if ( file_exists($file) ) { + return $file; + } + } + throw new \RuntimeException("Given view file `$fileName` can not be found within given folder list.."); } diff --git a/src/Language/DefaultRegistrations.php b/src/Language/DefaultRegistrations.php index 6f9199c..1f9ec3a 100644 --- a/src/Language/DefaultRegistrations.php +++ b/src/Language/DefaultRegistrations.php @@ -57,6 +57,7 @@ class DefaultRegistrations implements LanguageRegistration $compiler->registerControlStructure(new \Picea\ControlStructure\ExtendsToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\BlockToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\IncludeToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\ViewToken()); foreach($this->controlStructures ?? [] as $controlStructure) { @@ -68,7 +69,6 @@ class DefaultRegistrations implements LanguageRegistration { $compiler->registerExtension(new \Picea\Extension\PhpExtension()); $compiler->registerExtension(new \Picea\Extension\JsonExtension($this->context)); - $compiler->registerExtension(new \Picea\Extension\AssetExtension()); foreach($this->extensions ?? [] as $extension) { $compiler->registerExtension($extension); diff --git a/src/Picea.php b/src/Picea.php index bffa014..ea2140a 100644 --- a/src/Picea.php +++ b/src/Picea.php @@ -68,6 +68,10 @@ class Picea implements LanguageRegistration public function inlineHtml(? object $proxy, string $viewPath, ... $variables) { return $this->renderHtml($viewPath, [ 'inlineVariables' => $variables ], $proxy); } + + public function inlineContent(string $viewPath) { + return $this->fileFetcher->getFileContent($viewPath); + } public function renderContext(Compiler\Context $context) : object {