- WIP on picea-asset
This commit is contained in:
parent
42d84796ee
commit
3ccbf6bfab
|
@ -58,7 +58,12 @@ if (! class_exists("%NAMESPACE%\%CLASSNAME%", false) ) {
|
|||
|
||||
$__event->eventExecute(\Picea\Event\Builder\ClassTemplateOutputDone::class, $variablesList);
|
||||
|
||||
# try{
|
||||
%PARENT_OUTPUT%
|
||||
# }
|
||||
# catch(\Exception $e) {
|
||||
# dump($this->isTemplateError($e));
|
||||
# }
|
||||
|
||||
$this->depth--;
|
||||
|
||||
|
@ -138,6 +143,13 @@ if (! class_exists("%NAMESPACE%\%CLASSNAME%", false) ) {
|
|||
$this->output($variablesList);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public static function isTemplateError(\Throwable $error) : bool
|
||||
{
|
||||
$class = substr(static::class, strripos(static::class, '\\') + 1) . ".php";
|
||||
|
||||
return substr($error->getFile(), -strlen($class)) === $class;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,17 @@
|
|||
|
||||
namespace Picea;
|
||||
|
||||
use Picea\Event\Compiler\CompileTokenExtension;
|
||||
use Picea\Event\Compiler\CompileTokenExtensionEvent;
|
||||
use Picea\Event\Compiler\CompileTokenTagEvent;
|
||||
use Picea\Exception\RegisterExtensionToken;
|
||||
use Picea\Extension\FunctionExtension;
|
||||
use Picea\Language\LanguageRegistration;
|
||||
|
||||
class Compiler
|
||||
{
|
||||
use EventTrait;
|
||||
|
||||
protected string $sourceCode = "";
|
||||
|
||||
protected array $syntaxObjectList = [];
|
||||
|
@ -53,11 +58,14 @@ class Compiler
|
|||
$tokenName = $context->tokenName($token);
|
||||
$tokenOptions = $context->tokenOptions($token);
|
||||
|
||||
# @TODO Refractor this parts to allows registration to the tag's name
|
||||
if ( $this->tagList[$tokenName] ?? false ) {
|
||||
$this->eventExecute(CompileTokenTagEvent::class, $context, $arguments, $tokenName, $tokenOptions);
|
||||
|
||||
return $this->tagList[$tokenName]->parse($context, $arguments, $tokenName, $tokenOptions);
|
||||
}
|
||||
elseif ( $this->extensionList[$tokenName] ?? false ) {
|
||||
$this->eventExecute(CompileTokenExtensionEvent::class, $context, $arguments, $tokenName, $tokenOptions);
|
||||
|
||||
return $this->extensionList[$tokenName]->parse($context, $arguments, $tokenName, $tokenOptions);
|
||||
}
|
||||
else {
|
||||
|
@ -135,7 +143,7 @@ class Compiler
|
|||
|
||||
public function __toString() : string
|
||||
{
|
||||
return "WHATAFAK";
|
||||
return "???";
|
||||
}
|
||||
|
||||
public function getExtensionFromToken(string $name) : Extension\Extension
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Picea\Event\Compiler;
|
||||
|
||||
use Picea\Compiler\Context;
|
||||
|
||||
interface CompileTokenExtensionEvent
|
||||
{
|
||||
public function execute(Context $context, ?string $arguments, string $token, array $options = []);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Picea\Event\Compiler;
|
||||
|
||||
use Picea\Compiler\Context;
|
||||
|
||||
interface CompileTokenTagEvent
|
||||
{
|
||||
public function execute(Context &$context, ?string $arguments, string $token, array $options = []);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Picea\Event\Extension;
|
||||
|
||||
interface UrlBuildAssetEvent
|
||||
{
|
||||
public function execute(string $uri, array $parameters = [], bool $appendVersion) : void;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Picea\Event\Extension;
|
||||
|
||||
interface UrlBuildRouteEvent
|
||||
{
|
||||
public function execute(string $uri, array $parameters = [], bool $appendVersion) : void;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Picea\Event\Extension;
|
||||
|
||||
interface UrlBuildUrlEvent
|
||||
{
|
||||
public function execute(string $uri, array $parameters = [], bool $appendVersion) : void;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Picea\Event\Extension;
|
||||
|
||||
interface UrlRegisterRouteEvent
|
||||
{
|
||||
public function execute(string $name, array $route) : void;
|
||||
}
|
|
@ -3,10 +3,14 @@
|
|||
namespace Picea\Extension;
|
||||
|
||||
use Notes\Route\Attribute\Object\Route;
|
||||
use Picea\EventTrait;
|
||||
use Picea\Compiler\Context;
|
||||
use Picea\Event\Extension\{ UrlBuildAssetEvent, UrlBuildUrlEvent, UrlBuildRouteEvent, UrlRegisterRouteEvent };
|
||||
|
||||
class UrlExtension implements Extension, FunctionExtension {
|
||||
|
||||
use EventTrait;
|
||||
|
||||
public const URLIZE_PATTERN_URL = <<<PATTERN
|
||||
~(?<!href=['"])https?://[\w/._\-&?]*(?!</a>)(?=[^\w/._\-&])~s
|
||||
PATTERN;
|
||||
|
@ -105,11 +109,15 @@ PATTERN;
|
|||
|
||||
public function buildUrl(string $uri = "", array $parameters = [], bool $appendVersion = false) : string
|
||||
{
|
||||
$this->eventExecute(UrlBuildUrlEvent::class, $uri, $parameters, $appendVersion);
|
||||
|
||||
return $this->setUrlParameters($this->url() . "/" . ltrim($uri, "/"), $appendVersion ? array_replace([ 'v' => $this->assetToken ], $parameters) : $parameters);
|
||||
}
|
||||
|
||||
public function buildAssetUrl(string $uri, array $parameters = [], bool $appendVersion = true) : string
|
||||
{
|
||||
$this->eventExecute(UrlBuildAssetEvent::class, $uri, $parameters, $appendVersion);
|
||||
|
||||
return $this->buildUrl($uri, $parameters, $appendVersion);
|
||||
}
|
||||
|
||||
|
@ -150,6 +158,8 @@ PATTERN;
|
|||
'class' => $class,
|
||||
'classMethod' => $method,
|
||||
];
|
||||
|
||||
$this->eventExecute(UrlRegisterRouteEvent::class, $name, $this->routes[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -274,7 +284,6 @@ PATTERN;
|
|||
}
|
||||
|
||||
$search[$item[0]] = $value ?? "";
|
||||
|
||||
}
|
||||
|
||||
$route = str_replace(array_keys($search), array_values($search), $route);
|
||||
|
|
Loading…
Reference in New Issue