- 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);
|
$__event->eventExecute(\Picea\Event\Builder\ClassTemplateOutputDone::class, $variablesList);
|
||||||
|
|
||||||
%PARENT_OUTPUT%
|
# try{
|
||||||
|
%PARENT_OUTPUT%
|
||||||
|
# }
|
||||||
|
# catch(\Exception $e) {
|
||||||
|
# dump($this->isTemplateError($e));
|
||||||
|
# }
|
||||||
|
|
||||||
$this->depth--;
|
$this->depth--;
|
||||||
|
|
||||||
|
@ -138,6 +143,13 @@ if (! class_exists("%NAMESPACE%\%CLASSNAME%", false) ) {
|
||||||
$this->output($variablesList);
|
$this->output($variablesList);
|
||||||
return ob_get_clean();
|
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;
|
namespace Picea;
|
||||||
|
|
||||||
|
use Picea\Event\Compiler\CompileTokenExtension;
|
||||||
|
use Picea\Event\Compiler\CompileTokenExtensionEvent;
|
||||||
|
use Picea\Event\Compiler\CompileTokenTagEvent;
|
||||||
use Picea\Exception\RegisterExtensionToken;
|
use Picea\Exception\RegisterExtensionToken;
|
||||||
use Picea\Extension\FunctionExtension;
|
use Picea\Extension\FunctionExtension;
|
||||||
use Picea\Language\LanguageRegistration;
|
use Picea\Language\LanguageRegistration;
|
||||||
|
|
||||||
class Compiler
|
class Compiler
|
||||||
{
|
{
|
||||||
|
use EventTrait;
|
||||||
|
|
||||||
protected string $sourceCode = "";
|
protected string $sourceCode = "";
|
||||||
|
|
||||||
protected array $syntaxObjectList = [];
|
protected array $syntaxObjectList = [];
|
||||||
|
@ -52,12 +57,15 @@ class Compiler
|
||||||
$token = strtolower(trim($token));
|
$token = strtolower(trim($token));
|
||||||
$tokenName = $context->tokenName($token);
|
$tokenName = $context->tokenName($token);
|
||||||
$tokenOptions = $context->tokenOptions($token);
|
$tokenOptions = $context->tokenOptions($token);
|
||||||
|
|
||||||
# @TODO Refractor this parts to allows registration to the tag's name
|
|
||||||
if ( $this->tagList[$tokenName] ?? false ) {
|
if ( $this->tagList[$tokenName] ?? false ) {
|
||||||
|
$this->eventExecute(CompileTokenTagEvent::class, $context, $arguments, $tokenName, $tokenOptions);
|
||||||
|
|
||||||
return $this->tagList[$tokenName]->parse($context, $arguments, $tokenName, $tokenOptions);
|
return $this->tagList[$tokenName]->parse($context, $arguments, $tokenName, $tokenOptions);
|
||||||
}
|
}
|
||||||
elseif ( $this->extensionList[$tokenName] ?? false ) {
|
elseif ( $this->extensionList[$tokenName] ?? false ) {
|
||||||
|
$this->eventExecute(CompileTokenExtensionEvent::class, $context, $arguments, $tokenName, $tokenOptions);
|
||||||
|
|
||||||
return $this->extensionList[$tokenName]->parse($context, $arguments, $tokenName, $tokenOptions);
|
return $this->extensionList[$tokenName]->parse($context, $arguments, $tokenName, $tokenOptions);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -135,7 +143,7 @@ class Compiler
|
||||||
|
|
||||||
public function __toString() : string
|
public function __toString() : string
|
||||||
{
|
{
|
||||||
return "WHATAFAK";
|
return "???";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getExtensionFromToken(string $name) : Extension\Extension
|
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;
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ trait EventTrait
|
||||||
{
|
{
|
||||||
return array_filter($this->_eventList, fn($ev) => $ev instanceof $type);
|
return array_filter($this->_eventList, fn($ev) => $ev instanceof $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function eventExecute(string $type, ...$arguments) : void
|
public function eventExecute(string $type, ...$arguments) : void
|
||||||
{
|
{
|
||||||
foreach($this->eventFromType($type) as $event) {
|
foreach($this->eventFromType($type) as $event) {
|
||||||
|
|
|
@ -3,10 +3,14 @@
|
||||||
namespace Picea\Extension;
|
namespace Picea\Extension;
|
||||||
|
|
||||||
use Notes\Route\Attribute\Object\Route;
|
use Notes\Route\Attribute\Object\Route;
|
||||||
|
use Picea\EventTrait;
|
||||||
use Picea\Compiler\Context;
|
use Picea\Compiler\Context;
|
||||||
|
use Picea\Event\Extension\{ UrlBuildAssetEvent, UrlBuildUrlEvent, UrlBuildRouteEvent, UrlRegisterRouteEvent };
|
||||||
|
|
||||||
class UrlExtension implements Extension, FunctionExtension {
|
class UrlExtension implements Extension, FunctionExtension {
|
||||||
|
|
||||||
|
use EventTrait;
|
||||||
|
|
||||||
public const URLIZE_PATTERN_URL = <<<PATTERN
|
public const URLIZE_PATTERN_URL = <<<PATTERN
|
||||||
~(?<!href=['"])https?://[\w/._\-&?]*(?!</a>)(?=[^\w/._\-&])~s
|
~(?<!href=['"])https?://[\w/._\-&?]*(?!</a>)(?=[^\w/._\-&])~s
|
||||||
PATTERN;
|
PATTERN;
|
||||||
|
@ -105,11 +109,15 @@ PATTERN;
|
||||||
|
|
||||||
public function buildUrl(string $uri = "", array $parameters = [], bool $appendVersion = false) : string
|
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);
|
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
|
public function buildAssetUrl(string $uri, array $parameters = [], bool $appendVersion = true) : string
|
||||||
{
|
{
|
||||||
|
$this->eventExecute(UrlBuildAssetEvent::class, $uri, $parameters, $appendVersion);
|
||||||
|
|
||||||
return $this->buildUrl($uri, $parameters, $appendVersion);
|
return $this->buildUrl($uri, $parameters, $appendVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +158,8 @@ PATTERN;
|
||||||
'class' => $class,
|
'class' => $class,
|
||||||
'classMethod' => $method,
|
'classMethod' => $method,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$this->eventExecute(UrlRegisterRouteEvent::class, $name, $this->routes[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,7 +205,7 @@ PATTERN;
|
||||||
|
|
||||||
protected function domain() : string
|
protected function domain() : string
|
||||||
{
|
{
|
||||||
if ( ! empty($_SERVER['HTTP_X_FORWARDED_PROTO']) || ! empty($_SERVER['HTTP_X_FORWARDED_SSL']) ) {
|
if ( ! empty($_SERVER['HTTP_X_FORWARDED_PROTO']) || ! empty($_SERVER['HTTP_X_FORWARDED_SSL']) ) {
|
||||||
$port = "";
|
$port = "";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -274,7 +284,6 @@ PATTERN;
|
||||||
}
|
}
|
||||||
|
|
||||||
$search[$item[0]] = $value ?? "";
|
$search[$item[0]] = $value ?? "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$route = str_replace(array_keys($search), array_values($search), $route);
|
$route = str_replace(array_keys($search), array_values($search), $route);
|
||||||
|
|
Loading…
Reference in New Issue