Compare commits
No commits in common. "master" and "picea-asset" have entirely different histories.
master
...
picea-asse
|
@ -16,14 +16,5 @@
|
|||
},
|
||||
"require": {
|
||||
"psr/http-message": "^1.0"
|
||||
},
|
||||
"extra": {
|
||||
"lean": {
|
||||
"autoload": {
|
||||
"definitions": [
|
||||
"meta/definitions.php"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -96,9 +96,9 @@ You can do so by using `define` and `slot`.
|
|||
```html
|
||||
{% arguments string $name, string $anchor, int $index = 0 %}
|
||||
|
||||
{% define "attributes" %}
|
||||
{% define slot %}
|
||||
|
||||
<a {% slot "attributes" %}{% endslot %} href="{{ $anchor }}" tabindex="{{ $index }}"{% endslot %}>{{ $name }}"</a>
|
||||
<a {% slot "attributes" %}href="{{ $anchor }}" tabindex="{{ $index }}"{% endslot %}>{{ $name }}"</a>
|
||||
```
|
||||
|
||||
**[HTML]** Would render the same as the `view` example :
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use Picea\{
|
||||
Caching\Cache,
|
||||
Caching\Opcache,
|
||||
Compiler,
|
||||
Compiler\Context,
|
||||
Compiler\BaseContext,
|
||||
FileFetcher,
|
||||
Method\Request
|
||||
};
|
||||
|
||||
use Picea\Extension\{ LanguageHandlerInterface, LanguageExtension, TitleExtension, NumberExtension, UrlExtension };
|
||||
|
||||
return [
|
||||
Picea\Picea::class => function($c) {
|
||||
return new Picea\Picea($c->get(Context::class), $c->get(Cache::class), $c->get(Compiler::class), null, $c->get(FileFetcher::class), null, getenv("DEBUG"));
|
||||
},
|
||||
|
||||
Context::class => function($c) {
|
||||
return new BaseContext($c->get(Lean\Lean::class)->getPiceaContext());
|
||||
},
|
||||
|
||||
Compiler::class => autowire(Compiler::class),
|
||||
|
||||
Request::class => autowire(Request::class),
|
||||
|
||||
LanguageExtension::class => create(LanguageExtension::class)->constructor(get(LanguageHandlerInterface::class)),
|
||||
|
||||
# LanguageHandlerInterface::class => autowire(\Lean\LanguageHandler::class),
|
||||
|
||||
# LanguageRegistration::class => create(\Lean\PiceaDefaultRegistration::class)->constructor(get('picea.extensions'), [], [], get(Ui::class), null),
|
||||
|
||||
'picea.extensions' => function(\Psr\Container\ContainerInterface $c) {
|
||||
return array_merge([
|
||||
$c->get(LanguageExtension::class),
|
||||
$c->get(TitleExtension::class),
|
||||
$c->get(NumberExtension::class),
|
||||
$c->get(UrlExtension::class),
|
||||
$c->get(Request::class),
|
||||
], class_exists(\Taxus\Picea\Extension::class) ? [ $c->get(\Taxus\Picea\Extension::class) ] : [],
|
||||
array_map(fn($class) => $c->get($class), $c->get(Lean\Lean::class)->getPiceaExtensions())
|
||||
);
|
||||
},
|
||||
|
||||
TitleExtension::class => autowire(TitleExtension::class),
|
||||
|
||||
NumberExtension::class => autowire(NumberExtension::class),
|
||||
|
||||
UrlExtension::class => create(UrlExtension::class)->constructor(getenv("URL_BASE"), get('git.commit'), explode(',', getenv('APP_URL')), (bool) getenv('FORCE_SSL')),
|
||||
|
||||
Cache::class => create(Opcache::class)->constructor(getenv("CACHE_PATH"), get(Context::class)),
|
||||
|
||||
FileFetcher::class => function($c) {
|
||||
return new FileFetcher($c->get(Lean\Lean::class)->getViewPaths());
|
||||
},
|
||||
];
|
|
@ -21,7 +21,7 @@ class Builder
|
|||
|
||||
$replace = [
|
||||
'%NAMESPACE%' => $context->namespace,
|
||||
'%USE%' => ( $uses = $context->renderUses() ) ? $uses : false,
|
||||
'%USE%' => ( $uses = $context->renderUses() ) ? "use $uses;" : false,
|
||||
'%CLASSNAME%' => $context->className,
|
||||
'%PATHNAME%' => $path($context->viewPath),
|
||||
'%FULLPATH%' => $path($context->filePath),
|
||||
|
|
|
@ -57,7 +57,7 @@ abstract class Context {
|
|||
|
||||
public function renderUses() : string
|
||||
{
|
||||
return implode(PHP_EOL, array_map(fn($use) => "use $use;", $this->useStack ?? []));
|
||||
return implode(",", $this->useStack ?? []);
|
||||
}
|
||||
|
||||
public function renderFunctions() : string
|
||||
|
|
|
@ -8,20 +8,15 @@ class BlockToken implements ControlStructure {
|
|||
|
||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
||||
{
|
||||
static $depth = 0;
|
||||
static $slotDefinitions = [];
|
||||
|
||||
# dump($depth, $token, $arguments, $slotDefinitions);
|
||||
|
||||
switch($token) {
|
||||
case "block":
|
||||
$slotDefinitions[] = $this->slotDefinitions();
|
||||
$depth++;
|
||||
|
||||
return "<?php \$___block = \Picea\ControlStructure\BlockToken::instanciateBlock($arguments); ?>";
|
||||
|
||||
case "endblock":
|
||||
$depth--;
|
||||
return "<?php echo \$___block->render(\$___class__template); unset(\$___block); ?>";
|
||||
|
||||
case "arguments":
|
||||
|
@ -45,14 +40,14 @@ class BlockToken implements ControlStructure {
|
|||
case "define":
|
||||
list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, "");
|
||||
|
||||
( $slotDefinitions[$depth] ?? end($slotDefinitions) )->setDefinition(eval("return $name;"), $definition);
|
||||
end($slotDefinitions)->setDefinition(eval("return $name;"), $definition);
|
||||
|
||||
return <<<PHP
|
||||
<?php \$this->defineSlot($name, function($definition) {}); ?>
|
||||
PHP;
|
||||
|
||||
case "slot":
|
||||
$def = ( $slotDefinitions[$depth] ?? end($slotDefinitions) );
|
||||
$def = end($slotDefinitions);
|
||||
|
||||
list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, "");
|
||||
|
||||
|
@ -79,12 +74,12 @@ class BlockToken implements ControlStructure {
|
|||
}
|
||||
|
||||
return <<<PHP
|
||||
<?php (\$___block ?? \$this)->slotIsSet($name) || (\$___block ?? \$this)->setSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
|
||||
<?php (\$___block ?? \$this)->slotIsSet($name) || \$___block->setSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
|
||||
PHP;
|
||||
}
|
||||
|
||||
case "endslot":
|
||||
$def = ( $slotDefinitions[$depth] ?? end($slotDefinitions) );
|
||||
$def =end($slotDefinitions);
|
||||
|
||||
if ($def->hasDefinitions() ) {
|
||||
$definition = $def->getCurrentSlotDefinitionVars();
|
||||
|
@ -189,7 +184,7 @@ class BlockToken implements ControlStructure {
|
|||
public function printDefinition(string $name) : string
|
||||
{
|
||||
if ( ! isset($this->definitions[$name]) ) {
|
||||
throw new \Exception("Slot definition for `$name` was not found. Have you defined it in your block header using something like '{% define \"$name\", ...\$arguments %}' ?");
|
||||
throw new \Exception("Slot definition for `$name` was not found. Have you defined it in your block header ?");
|
||||
}
|
||||
|
||||
return $this->definitions[$name];
|
||||
|
@ -199,6 +194,7 @@ class BlockToken implements ControlStructure {
|
|||
{
|
||||
$this->rendering = true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -227,12 +223,7 @@ class BlockToken implements ControlStructure {
|
|||
{
|
||||
$this->rendering = true;
|
||||
|
||||
if ($this->using['this'] ?? false) {
|
||||
$thisProxy = $this->using['this'];
|
||||
unset($this->using['this']);
|
||||
}
|
||||
|
||||
return $classTemplate->picea->inlineBlock($thisProxy ?? $this, $this->viewPath, ...$this->arguments);
|
||||
return $classTemplate->picea->inlineBlock($this, $this->viewPath, ...$this->arguments);
|
||||
}
|
||||
|
||||
public function setSlot(string $name, Callable $method) : void
|
||||
|
|
|
@ -33,9 +33,7 @@ class FunctionToken implements ControlStructure {
|
|||
|
||||
protected function printFunction($context, ?string $arguments) : string
|
||||
{
|
||||
$name = trim(explode('(', $arguments, 2)[0]);
|
||||
|
||||
return "<?php if (! function_exists(__NAMESPACE__ . '\\$name')) { function $arguments { ?>";
|
||||
return "<?php function $arguments { ?>";
|
||||
}
|
||||
|
||||
protected function printReturn($context, ?string $arguments) : string
|
||||
|
@ -45,6 +43,6 @@ class FunctionToken implements ControlStructure {
|
|||
|
||||
protected function printEndFunction($context) : string
|
||||
{
|
||||
return "<?php } } ?>";
|
||||
return "<?php } ?>";
|
||||
}
|
||||
}
|
|
@ -33,8 +33,6 @@ class SectionToken implements ControlStructure {
|
|||
throw new \RuntimeException("A section closing tag {% endsection %} was found without an opening {% section %} tag");
|
||||
}
|
||||
|
||||
$this->action = PrintActionEnum::default;
|
||||
|
||||
return $this->printEndSection($context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Picea\ControlStructure;
|
||||
|
||||
class TryCatchToken implements ControlStructure {
|
||||
|
||||
public array $token = [ "try", "catch", "finally", "endtry" ];
|
||||
|
||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string {
|
||||
switch($token) {
|
||||
case "try":
|
||||
|
||||
return "<?php try { ?>";
|
||||
|
||||
case "catch":
|
||||
return "<?php } catch($arguments) { ?>";
|
||||
|
||||
case "finally":
|
||||
return "<?php } finally { ?>";
|
||||
|
||||
case "endtry":
|
||||
return "<?php } ?>";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Picea\Event\Extension;
|
||||
|
||||
interface BuildAssetUrl
|
||||
{
|
||||
public function execute(string $uri, array $parameters = [], bool $appendVersion = true) : mixed;
|
||||
}
|
|
@ -15,7 +15,6 @@ class NumberExtension implements Extension, FunctionExtension {
|
|||
public string $title = "",
|
||||
) {
|
||||
$this->locale = explode('.', \Locale::getDefault())[0];
|
||||
$this->formatter = new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY);
|
||||
}
|
||||
|
||||
public function exportFunctions(): array
|
||||
|
@ -56,6 +55,8 @@ class NumberExtension implements Extension, FunctionExtension {
|
|||
|
||||
public function money(float $money, ? string $currency = null) /* : string|false */
|
||||
{
|
||||
$this->formatter ??= new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY);
|
||||
|
||||
$this->formatter->setTextAttribute(\NumberFormatter::CURRENCY_CODE, 'CAD');
|
||||
|
||||
$this->formatter->setPattern( str_replace('¤#','¤ #', $this->formatter->getPattern() ) );
|
||||
|
|
|
@ -8,7 +8,7 @@ class PrintExtension implements Extension {
|
|||
|
||||
public array $token = [ "echo", "print", "printf", "no_html" ];
|
||||
|
||||
public int $flag = \ENT_QUOTES | \ENT_DISALLOWED | \ENT_SUBSTITUTE;
|
||||
public int $flag = \ENT_QUOTES;
|
||||
|
||||
public string $encoding;
|
||||
|
||||
|
|
|
@ -2,10 +2,15 @@
|
|||
|
||||
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 \Picea\EventTrait;
|
||||
|
||||
use EventTrait;
|
||||
|
||||
public const URLIZE_PATTERN_URL = <<<PATTERN
|
||||
|
@ -30,7 +35,7 @@ PATTERN;
|
|||
|
||||
public array $tokens = [ "url" , "route", "asset", "slug" ];
|
||||
|
||||
##[\Deprecated]
|
||||
#[\Deprecated]
|
||||
protected bool $enforceExistingArguments = true;
|
||||
|
||||
public function __construct(string $urlBase = "", string $assetToken = "", array $appUrl = [], bool $forceSSL = false) {
|
||||
|
@ -63,7 +68,7 @@ PATTERN;
|
|||
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->slug($arguments) ?>";
|
||||
}
|
||||
|
||||
throw new \Exception("Unknown token given $token in UrlExtension.");
|
||||
throw new \ParseExtensionException("Unknown token given $token in UrlExtension.");
|
||||
}
|
||||
|
||||
public function exportFunctions(): array
|
||||
|
@ -120,7 +125,7 @@ PATTERN;
|
|||
|
||||
public function buildRouteUrl(string $name, array $parameters = [], bool $appendVersion = false) : string
|
||||
{
|
||||
if ( false !== $route = $this->findRoute($name) ) {
|
||||
if ( false !== ( $route = $this->routes[$name] ?? false ) ) {
|
||||
return $this->buildUrl($this->prepareRoute($route, $parameters), $parameters, $appendVersion);
|
||||
}
|
||||
|
||||
|
@ -149,28 +154,14 @@ PATTERN;
|
|||
|
||||
public function registerRoute(string $name, string $route, string $class, string $method, array $routeMethods) : void
|
||||
{
|
||||
$this->routes[] = $array = [
|
||||
'name' => $name,
|
||||
$this->routes[$name] = [
|
||||
'route' => $route,
|
||||
'routeMethods' => array_map('strtoupper', $routeMethods),
|
||||
'routeMethods' => $routeMethods,
|
||||
'class' => $class,
|
||||
'classMethod' => $method,
|
||||
];
|
||||
|
||||
$this->eventExecute(UrlRegisterRouteEvent::class, $name, $array);
|
||||
}
|
||||
|
||||
protected function findRoute(string $name, string $method = "*") : false|array
|
||||
{
|
||||
foreach($this->routes as $route) {
|
||||
if ( $route['name'] === $name ) {
|
||||
if ($method === '*' || in_array(strtoupper($method), $route['routeMethods']) ) {
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
$this->eventExecute(UrlRegisterRouteEvent::class, $name, $this->routes[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -289,7 +280,7 @@ PATTERN;
|
|||
if ($default ?? false) {
|
||||
$value = $default;
|
||||
}
|
||||
elseif ( $this->enforceExistingArguments && ! preg_match(sprintf("/\[\/?%s]/i", $item[0]), $route) ) {
|
||||
elseif ( strpos($route, "[{$matches[0][0]}]") !== false && $this->enforceExistingArguments) {
|
||||
throw new \RuntimeException(sprintf("Error while preparing route %s : could not match variable '%s' into given arguments ( %s ) from %s::%s", $route, $variable, json_encode($arguments), $routeParam['class'], $routeParam['classMethod']));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ class DefaultRegistrations implements LanguageRegistration
|
|||
|
||||
public function registerControlStructure(Compiler $compiler) : void
|
||||
{
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\TryCatchToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\NamespaceToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\UseToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\IfToken());
|
||||
|
|
|
@ -180,7 +180,6 @@ class Picea implements LanguageRegistration
|
|||
{
|
||||
if ( $this->debug || ! $this->cache->compiled( $context->cacheFilename() ) ) {
|
||||
$context = $this->compileContext($context);
|
||||
|
||||
$this->cache->save($context);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue