- Added a new Include token (which was added as RAW content)
- Fixed UrlExtension to reflect on notes-routes changes - Added some methods to FileFetcher
This commit is contained in:
parent
10632e9f67
commit
2f8abebc44
|
@ -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); ?>";
|
||||
}
|
||||
}
|
|
@ -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' ?>";
|
||||
}
|
||||
|
||||
}
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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..");
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue