Merge branch 'master' of https://git.mcnd.ca/mcndave/picea
This commit is contained in:
commit
69db3efdce
|
@ -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 $routes;
|
||||||
|
|
||||||
|
protected array $routesTarget;
|
||||||
|
|
||||||
public array $tokens = [ "url" , "route", "asset", "url.parameters" ];
|
public array $tokens = [ "url" , "route", "asset", "url.parameters" ];
|
||||||
|
|
||||||
public function __construct(Context $context, string $urlBase = "", string $assetToken = "") {
|
public function __construct(Context $context, string $urlBase = "", string $assetToken = "") {
|
||||||
|
@ -46,6 +48,11 @@ class UrlExtension implements Extension {
|
||||||
$context->pushFunction("route", [ $this, 'buildRouteUrl' ]);
|
$context->pushFunction("route", [ $this, 'buildRouteUrl' ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRouteList(bool $full = false) : array
|
||||||
|
{
|
||||||
|
return $this->routes;
|
||||||
|
}
|
||||||
|
|
||||||
public function setUrlParameters(string $url = "", array $parameters = []) : string
|
public function setUrlParameters(string $url = "", array $parameters = []) : string
|
||||||
{
|
{
|
||||||
return $url . ( $parameters ? "?" . http_build_query($parameters) : "" );
|
return $url . ( $parameters ? "?" . http_build_query($parameters) : "" );
|
||||||
|
@ -64,7 +71,7 @@ class UrlExtension implements Extension {
|
||||||
public function buildRouteUrl(string $name, array $parameters = []) : string
|
public function buildRouteUrl(string $name, array $parameters = []) : string
|
||||||
{
|
{
|
||||||
if ( false !== ( $route = $this->routes[$name] ?? false ) ) {
|
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);
|
$routeList = json_encode($this->routes, \JSON_PRETTY_PRINT);
|
||||||
|
@ -80,9 +87,14 @@ class UrlExtension implements Extension {
|
||||||
return $this->scheme() . $this->domain() . $this->base();
|
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..");
|
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\ExtendsToken());
|
||||||
$compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken());
|
$compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken());
|
||||||
$compiler->registerControlStructure(new \Picea\ControlStructure\BlockToken());
|
$compiler->registerControlStructure(new \Picea\ControlStructure\BlockToken());
|
||||||
|
$compiler->registerControlStructure(new \Picea\ControlStructure\IncludeToken());
|
||||||
$compiler->registerControlStructure(new \Picea\ControlStructure\ViewToken());
|
$compiler->registerControlStructure(new \Picea\ControlStructure\ViewToken());
|
||||||
|
|
||||||
foreach($this->controlStructures ?? [] as $controlStructure) {
|
foreach($this->controlStructures ?? [] as $controlStructure) {
|
||||||
|
@ -68,7 +69,6 @@ class DefaultRegistrations implements LanguageRegistration
|
||||||
{
|
{
|
||||||
$compiler->registerExtension(new \Picea\Extension\PhpExtension());
|
$compiler->registerExtension(new \Picea\Extension\PhpExtension());
|
||||||
$compiler->registerExtension(new \Picea\Extension\JsonExtension($this->context));
|
$compiler->registerExtension(new \Picea\Extension\JsonExtension($this->context));
|
||||||
$compiler->registerExtension(new \Picea\Extension\AssetExtension());
|
|
||||||
|
|
||||||
foreach($this->extensions ?? [] as $extension) {
|
foreach($this->extensions ?? [] as $extension) {
|
||||||
$compiler->registerExtension($extension);
|
$compiler->registerExtension($extension);
|
||||||
|
|
|
@ -89,6 +89,10 @@ class Picea implements LanguageRegistration
|
||||||
return $this->renderHtml($viewPath, [ 'inlineVariables' => $variables ], $proxy);
|
return $this->renderHtml($viewPath, [ 'inlineVariables' => $variables ], $proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function inlineContent(string $viewPath) {
|
||||||
|
return $this->fileFetcher->getFileContent($viewPath);
|
||||||
|
}
|
||||||
|
|
||||||
public function renderContext(Compiler\Context $context) : object
|
public function renderContext(Compiler\Context $context) : object
|
||||||
{
|
{
|
||||||
if ( null === $object = $this->contextFromCache($context) ) {
|
if ( null === $object = $this->contextFromCache($context) ) {
|
||||||
|
@ -98,7 +102,6 @@ class Picea implements LanguageRegistration
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#public function outputHtml(string $viewPath, array $variables) : ResponseInterface
|
#public function outputHtml(string $viewPath, array $variables) : ResponseInterface
|
||||||
#{
|
#{
|
||||||
# if ( $this->response ?? false ) {
|
# if ( $this->response ?? false ) {
|
||||||
|
|
Loading…
Reference in New Issue