This commit is contained in:
Dave M. 2020-10-21 03:57:02 +00:00
commit 69db3efdce
6 changed files with 41 additions and 18 deletions

View File

@ -0,0 +1,12 @@
<?php
namespace Picea\ControlStructure;
class IncludeToken implements ControlStructure {
public string $token = "include";
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
return "<?php echo \$___class__template->picea->inlineContent($arguments); ?>";
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace Picea\Extension;
class AssetExtension implements Extension {
public string $token = "asset";
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
return "<?php echo 'assets! $arguments' ?>";
}
}

View File

@ -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,
];
}
/**

View File

@ -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..");
}

View File

@ -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);

View File

@ -89,6 +89,10 @@ class Picea implements LanguageRegistration
return $this->renderHtml($viewPath, [ 'inlineVariables' => $variables ], $proxy);
}
public function inlineContent(string $viewPath) {
return $this->fileFetcher->getFileContent($viewPath);
}
public function renderContext(Compiler\Context $context) : object
{
if ( null === $object = $this->contextFromCache($context) ) {
@ -98,7 +102,6 @@ class Picea implements LanguageRegistration
return $object;
}
#public function outputHtml(string $viewPath, array $variables) : ResponseInterface
#{
# if ( $this->response ?? false ) {