Compare commits
	
		
			No commits in common. "master" and "picea-asset" have entirely different histories.
		
	
	
		
			master
			...
			picea-asse
		
	
		
@ -16,14 +16,5 @@
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    "require": {
 | 
					    "require": {
 | 
				
			||||||
        "psr/http-message": "^1.0"
 | 
					        "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
 | 
					```html
 | 
				
			||||||
{% arguments string $name, string $anchor, int $index = 0 %}
 | 
					{% 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 :
 | 
					**[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 = [
 | 
					        $replace = [
 | 
				
			||||||
            '%NAMESPACE%' => $context->namespace,
 | 
					            '%NAMESPACE%' => $context->namespace,
 | 
				
			||||||
            '%USE%' => ( $uses = $context->renderUses() ) ? $uses : false,
 | 
					            '%USE%' => ( $uses = $context->renderUses() ) ? "use $uses;" : false,
 | 
				
			||||||
            '%CLASSNAME%' => $context->className,
 | 
					            '%CLASSNAME%' => $context->className,
 | 
				
			||||||
            '%PATHNAME%' => $path($context->viewPath),
 | 
					            '%PATHNAME%' => $path($context->viewPath),
 | 
				
			||||||
            '%FULLPATH%' => $path($context->filePath),
 | 
					            '%FULLPATH%' => $path($context->filePath),
 | 
				
			||||||
 | 
				
			|||||||
@ -57,7 +57,7 @@ abstract class Context {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function renderUses() : string
 | 
					    public function renderUses() : string
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return implode(PHP_EOL, array_map(fn($use) => "use $use;", $this->useStack ?? []));
 | 
					        return implode(",", $this->useStack ?? []);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function renderFunctions() : string
 | 
					    public function renderFunctions() : string
 | 
				
			||||||
 | 
				
			|||||||
@ -4,43 +4,45 @@ namespace Picea\ControlStructure;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
abstract class AbstractLoop implements ControlStructure {
 | 
					abstract class AbstractLoop implements ControlStructure {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected function openLoop(\Picea\Compiler\Context &$context, ?string $arguments, string $token,) : string
 | 
					    public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $name = "$".uniqid("{$token}_");
 | 
					        switch($token) {
 | 
				
			||||||
 | 
					            case "while":
 | 
				
			||||||
 | 
					            case "foreach":
 | 
				
			||||||
 | 
					                $name = "$".uniqid("{$token}_");
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                $stack = array_filter($context->iterationStack ?? [], function($item) {
 | 
				
			||||||
 | 
					                    return ! $item['or'];
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                $count = count($stack);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $stack = array_filter($context->iterationStack ?? [], function($item) {
 | 
					                if ( $count > 0 ) {
 | 
				
			||||||
            return ! $item['or'];
 | 
					                    $name .= "[" . end($stack)['uid'] . "]";
 | 
				
			||||||
        });
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $count = count($stack);
 | 
					                $context->iterationStack[] = [
 | 
				
			||||||
 | 
					                    'or' => false,
 | 
				
			||||||
 | 
					                    'uid' => $name,
 | 
				
			||||||
 | 
					                    'token' => "end{$token}",
 | 
				
			||||||
 | 
					                ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ( $count > 0 ) {
 | 
					                return "<?php $token ($arguments): $name = ( $name ?? 0 ) + 1; ?>";
 | 
				
			||||||
            $name .= "[" . end($stack)['uid'] . "]";
 | 
					
 | 
				
			||||||
 | 
					            case "endwhile":
 | 
				
			||||||
 | 
					            case "endforeach":
 | 
				
			||||||
 | 
					                $last = end($context->iterationStack);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if ( $last['or'] === false ) {
 | 
				
			||||||
 | 
					                    $output = "<?php $token; ?>";
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else {
 | 
				
			||||||
 | 
					                    $output = "<?php endif; if ( isset({$last['uid']}) ) unset({$last['uid']}); ?>";
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                array_pop($context->iterationStack);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                return $output;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        $context->iterationStack[] = [
 | 
					 | 
				
			||||||
            'or' => false,
 | 
					 | 
				
			||||||
            'uid' => $name,
 | 
					 | 
				
			||||||
            'token' => "end{$token}",
 | 
					 | 
				
			||||||
        ];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return "<?php $token ($arguments): \$__loop_index = $name = ( $name ?? 0 ) + 1; ?>";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    protected function closeLoop(\Picea\Compiler\Context &$context, ?string $arguments, string $token,) : string
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $last = end($context->iterationStack);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if ( $last['or'] === false ) {
 | 
					 | 
				
			||||||
            $output = "<?php $token; ?>";
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            $output = "<?php endif; if ( isset({$last['uid']}) ) unset({$last['uid']}); ?>";
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        array_pop($context->iterationStack);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return $output;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
					 | 
				
			||||||
@ -4,27 +4,21 @@ namespace Picea\ControlStructure;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class BlockToken implements ControlStructure {
 | 
					class BlockToken implements ControlStructure {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public array $token = [ "arguments", "block", "endblock", "/block", "define", "slot", "endslot", "/slot", "using" ];
 | 
					    public array $token = [ "arguments", "block", "endblock", "define", "slot", "endslot", "using" ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
 | 
					    public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        static $depth = 0;
 | 
					 | 
				
			||||||
        static $slotDefinitions = [];
 | 
					        static $slotDefinitions = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # dump($depth, $token, $arguments, $slotDefinitions);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        switch($token) {
 | 
					        switch($token) {
 | 
				
			||||||
            case "block":
 | 
					            case "block":
 | 
				
			||||||
                $slotDefinitions[] = $this->slotDefinitions();
 | 
					                $slotDefinitions[] = $this->slotDefinitions();
 | 
				
			||||||
                $depth++;
 | 
					                
 | 
				
			||||||
 | 
					 | 
				
			||||||
                return "<?php \$___block = \Picea\ControlStructure\BlockToken::instanciateBlock($arguments); ?>";
 | 
					                return "<?php \$___block = \Picea\ControlStructure\BlockToken::instanciateBlock($arguments); ?>";
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            case "/block":
 | 
					 | 
				
			||||||
            case "endblock":
 | 
					            case "endblock":
 | 
				
			||||||
                $depth--;
 | 
					 | 
				
			||||||
                return "<?php echo \$___block->render(\$___class__template); unset(\$___block); ?>";
 | 
					                return "<?php echo \$___block->render(\$___class__template); unset(\$___block); ?>";
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            case "arguments":
 | 
					            case "arguments":
 | 
				
			||||||
                $class = static::class;
 | 
					                $class = static::class;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -42,19 +36,19 @@ class BlockToken implements ControlStructure {
 | 
				
			|||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    /*%EXCEPTION_LINE_BASE%*/?>
 | 
					                    /*%EXCEPTION_LINE_BASE%*/?>
 | 
				
			||||||
                PHP;
 | 
					                PHP;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            case "define":
 | 
					            case "define":
 | 
				
			||||||
                list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, "");
 | 
					                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
 | 
					                return <<<PHP
 | 
				
			||||||
                <?php \$this->defineSlot($name, function($definition) {}); ?>
 | 
					                    <?php \$this->defineSlot($name, function($definition) {}); ?>
 | 
				
			||||||
                PHP;
 | 
					                PHP;
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
            case "slot":
 | 
					            case "slot":
 | 
				
			||||||
                $def = ( $slotDefinitions[$depth] ?? end($slotDefinitions) );
 | 
					                $def = end($slotDefinitions);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
                list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, "");
 | 
					                list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $loops = count($context->iterationStack ?? []) ? ",". implode(', ', array_filter(array_column($context->iterationStack, 'uid'), fn($e) => strpos($e, '[') === false)) : null;
 | 
					                $loops = count($context->iterationStack ?? []) ? ",". implode(', ', array_filter(array_column($context->iterationStack, 'uid'), fn($e) => strpos($e, '[') === false)) : null;
 | 
				
			||||||
@ -63,7 +57,7 @@ class BlockToken implements ControlStructure {
 | 
				
			|||||||
                    $slotName = eval("return $name;");
 | 
					                    $slotName = eval("return $name;");
 | 
				
			||||||
                    $def->currentSlot = $slotName;
 | 
					                    $def->currentSlot = $slotName;
 | 
				
			||||||
                    $def->setDefinitionVars($slotName, $definition);
 | 
					                    $def->setDefinitionVars($slotName, $definition);
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
                    $definition = $def->printDefinition($slotName);
 | 
					                    $definition = $def->printDefinition($slotName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if ($definition) {
 | 
					                    if ($definition) {
 | 
				
			||||||
@ -71,53 +65,53 @@ class BlockToken implements ControlStructure {
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    return <<<PHP
 | 
					                    return <<<PHP
 | 
				
			||||||
                    <?php \$this->printSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
 | 
					                        <?php \$this->printSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
 | 
				
			||||||
                    PHP;
 | 
					                    PHP;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else {
 | 
					                else {
 | 
				
			||||||
                    if ($definition) {
 | 
					                    if ($definition) {
 | 
				
			||||||
                        $definition .= ",";
 | 
					                        $definition .= ",";
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
                    return <<<PHP
 | 
					                    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;
 | 
					                    PHP;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
            case "/slot":
 | 
					 | 
				
			||||||
            case "endslot":
 | 
					            case "endslot":
 | 
				
			||||||
                $def = ( $slotDefinitions[$depth] ?? end($slotDefinitions) );
 | 
					                $def =end($slotDefinitions);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
                if ($def->hasDefinitions() ) {
 | 
					                if ($def->hasDefinitions() ) {
 | 
				
			||||||
                    $definition = $def->getCurrentSlotDefinitionVars();
 | 
					                    $definition = $def->getCurrentSlotDefinitionVars();
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
                    if ($definition) {
 | 
					                    if ($definition) {
 | 
				
			||||||
                        $definition .= ",";
 | 
					                        $definition .= ",";
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    return <<<PHP
 | 
					                    return <<<PHP
 | 
				
			||||||
                    <?php })->call(\$this, $definition array_merge(get_defined_vars(), \$this->using)); ?>
 | 
					                        <?php })->call(\$this, $definition array_merge(get_defined_vars(), \$this->using)); ?>
 | 
				
			||||||
                    PHP;
 | 
					                    PHP;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else {
 | 
					                else {
 | 
				
			||||||
                    return "<?php }); ?>";
 | 
					                    return "<?php }); ?>";
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
            case "using":
 | 
					            case "using":
 | 
				
			||||||
                return "<?php \$___block->setUsing($arguments); ?>";
 | 
					                return "<?php \$___block->setUsing($arguments); ?>";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    public function inlineHtml(? object $proxy, string $viewPath, ... $variables) {
 | 
					    public function inlineHtml(? object $proxy, string $viewPath, ... $variables) {
 | 
				
			||||||
        return $this->renderHtml($viewPath, [ 'inlineVariables' => $variables ], $proxy);
 | 
					        return $this->renderHtml($viewPath, [ 'inlineVariables' => $variables ], $proxy);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    public static function parseSlotArguments(Callable $method) : array
 | 
					    public static function parseSlotArguments(Callable $method) : array
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        #return
 | 
					        #return 
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
    public static function parseArguments(Callable $method, array $arguments) : array
 | 
					    public static function parseArguments(Callable $method, array $arguments) : array
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        try{
 | 
					        try{
 | 
				
			||||||
@ -125,10 +119,10 @@ class BlockToken implements ControlStructure {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        catch(\TypeError $ex) {
 | 
					        catch(\TypeError $ex) {
 | 
				
			||||||
            throw $ex;
 | 
					            throw $ex;
 | 
				
			||||||
        }
 | 
					        } 
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        $parameters = [];
 | 
					        $parameters = [];
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        foreach((new \ReflectionFunction($method))->getParameters() as $key => $value) {
 | 
					        foreach((new \ReflectionFunction($method))->getParameters() as $key => $value) {
 | 
				
			||||||
            if ( isset($arguments[$key]) ) {
 | 
					            if ( isset($arguments[$key]) ) {
 | 
				
			||||||
                $parameters[ $value->getName() ] = $arguments[$key];
 | 
					                $parameters[ $value->getName() ] = $arguments[$key];
 | 
				
			||||||
@ -143,119 +137,115 @@ class BlockToken implements ControlStructure {
 | 
				
			|||||||
                $parameters[ $value->getName() ] = null;
 | 
					                $parameters[ $value->getName() ] = null;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        return $parameters;
 | 
					        return $parameters;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    public static function slotDefinitions() {
 | 
					    public static function slotDefinitions() {
 | 
				
			||||||
        return new class() {
 | 
					        return new class() {
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public array $definitions = [];
 | 
					            public array $definitions = [];
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public array $variables = [];
 | 
					            public array $variables = [];
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public bool $rendering = false;
 | 
					            public bool $rendering = false;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public string $currentSlot;
 | 
					            public string $currentSlot;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function setDefinition(string $name, string $definition) : self
 | 
					            public function setDefinition(string $name, string $definition) : self 
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                $this->definitions[$name] = $definition;
 | 
					                $this->definitions[$name] = $definition;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
                return $this;
 | 
					                return $this;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function setDefinitionVars(string $name, string $variables) : self
 | 
					            public function setDefinitionVars(string $name, string $variables) : self
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                $this->variables[$name] = $variables;
 | 
					                $this->variables[$name] = $variables;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
                return $this;
 | 
					                return $this;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function getDefinitionVars(string $name) : string
 | 
					            public function getDefinitionVars(string $name) : string
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return $this->variables[$name] ?? "";
 | 
					                return $this->variables[$name] ?? "";
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function getCurrentSlotDefinitionVars() : string
 | 
					            public function getCurrentSlotDefinitionVars() : string
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return $this->getDefinitionVars($this->currentSlot);
 | 
					                return $this->getDefinitionVars($this->currentSlot);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function hasDefinitions() : bool
 | 
					            public function hasDefinitions() : bool
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return count($this->definitions) > 0;
 | 
					                return count($this->definitions) > 0;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function printDefinition(string $name) : string
 | 
					            public function printDefinition(string $name) : string
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if ( ! isset($this->definitions[$name]) ) {
 | 
					                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];
 | 
					                return $this->definitions[$name];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function render() : void
 | 
					            public function render() : void
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                $this->rendering = true;
 | 
					                $this->rendering = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    public static function instanciateBlock(string $viewPath, ... $arguments)
 | 
					    public static function instanciateBlock(string $viewPath, ... $arguments) 
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return new class($viewPath, ...$arguments) {
 | 
					        return new class($viewPath, ...$arguments) {
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public bool $rendering = false;
 | 
					            public bool $rendering = false;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public string $viewPath;
 | 
					            public string $viewPath;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public array $using = [];
 | 
					            public array $using = [];
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public array $arguments = [];
 | 
					            public array $arguments = [];
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public array $slots = [];
 | 
					            public array $slots = [];
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public array $definition = [];
 | 
					            public array $definition = [];
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function __construct(string $viewPath, ...$arguments) {
 | 
					            public function __construct(string $viewPath, ...$arguments) {
 | 
				
			||||||
                $this->viewPath = $viewPath;
 | 
					                $this->viewPath = $viewPath;
 | 
				
			||||||
                $this->arguments = $arguments;
 | 
					                $this->arguments = $arguments;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function render(object $classTemplate) : string
 | 
					            public function render(object $classTemplate) : string
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                $this->rendering = true;
 | 
					                $this->rendering = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if ($this->using['this'] ?? false) {
 | 
					                return $classTemplate->picea->inlineBlock($this, $this->viewPath, ...$this->arguments);
 | 
				
			||||||
                    $thisProxy = $this->using['this'];
 | 
					 | 
				
			||||||
                    unset($this->using['this']);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                
 | 
					 | 
				
			||||||
                return $classTemplate->picea->inlineBlock($thisProxy ?? $this, $this->viewPath, ...$this->arguments);
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function setSlot(string $name, Callable $method) : void
 | 
					            public function setSlot(string $name, Callable $method) : void
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                $this->slots[$name] = $method;
 | 
					                $this->slots[$name] = $method;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function defineSlot(string $name, Callable $method) : void
 | 
					            public function defineSlot(string $name, Callable $method) : void
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                $this->definition[$name] = $method;
 | 
					                $this->definition[$name] = $method;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function slotIsSet(string $name) : bool
 | 
					            public function slotIsSet(string $name) : bool
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return ! empty($this->slots[$name]);
 | 
					                return ! empty($this->slots[$name]);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function printSlot(string $name, Callable $default)
 | 
					            public function printSlot(string $name, Callable $default)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return $this->slotIsSet($name) ? $this->slots[$name] : $default;
 | 
					                return $this->slotIsSet($name) ? $this->slots[$name] : $default;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            public function setUsing(array $variables) {
 | 
					            public function setUsing(array $variables) {
 | 
				
			||||||
                $this->using = $variables;
 | 
					                $this->using = $variables;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,7 @@ namespace Picea\ControlStructure;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class ForToken implements ControlStructure {
 | 
					class ForToken implements ControlStructure {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public array $token = [ "for", "endfor", "/for" ];
 | 
					    public array $token = [ "for", "endfor" ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string {
 | 
					    public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string {
 | 
				
			||||||
        switch($token) {
 | 
					        switch($token) {
 | 
				
			||||||
@ -18,8 +18,7 @@ class ForToken implements ControlStructure {
 | 
				
			|||||||
                ];
 | 
					                ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                return "<?php for ($arguments): {$uid} = 1; ?>";
 | 
					                return "<?php for ($arguments): {$uid} = 1; ?>";
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
            case "/for":
 | 
					 | 
				
			||||||
            case "endfor":
 | 
					            case "endfor":
 | 
				
			||||||
                $last = end($context->iterationStack);
 | 
					                $last = end($context->iterationStack);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -5,17 +5,5 @@ namespace Picea\ControlStructure;
 | 
				
			|||||||
use DI\Definition\Source\AnnotationBasedAutowiring;
 | 
					use DI\Definition\Source\AnnotationBasedAutowiring;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ForeachToken extends AbstractLoop {
 | 
					class ForeachToken extends AbstractLoop {
 | 
				
			||||||
    public array $token = [ "foreach", "endforeach", "/foreach" ];
 | 
					    public array $token = [ "foreach", "endforeach" ];
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        switch($token) {
 | 
					 | 
				
			||||||
            case "foreach":
 | 
					 | 
				
			||||||
                return $this->openLoop($context, $arguments, $token);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            case "endforeach":
 | 
					 | 
				
			||||||
            case "/foreach":
 | 
					 | 
				
			||||||
                return $this->closeLoop($context, $arguments, $token);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -33,9 +33,7 @@ class FunctionToken implements ControlStructure {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function printFunction($context, ?string $arguments) : string
 | 
					    protected function printFunction($context, ?string $arguments) : string
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $name = trim(explode('(', $arguments, 2)[0]);
 | 
					        return "<?php function $arguments { ?>";
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return "<?php if (! function_exists(__NAMESPACE__ . '\\$name')) { function $arguments { ?>";
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected function printReturn($context, ?string $arguments) : string
 | 
					    protected function printReturn($context, ?string $arguments) : string
 | 
				
			||||||
@ -45,6 +43,6 @@ class FunctionToken implements ControlStructure {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function printEndFunction($context) : string
 | 
					    protected function printEndFunction($context) : string
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return "<?php } } ?>";
 | 
					        return "<?php } ?>";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -4,7 +4,7 @@ namespace Picea\ControlStructure;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class IfToken implements ControlStructure {
 | 
					class IfToken implements ControlStructure {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public array $token = [ "if", "else", "elseif", "endif", "/if" ];
 | 
					    public array $token = [ "if", "else", "elseif", "endif" ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string {
 | 
					    public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string {
 | 
				
			||||||
        switch($token) {
 | 
					        switch($token) {
 | 
				
			||||||
@ -16,8 +16,7 @@ class IfToken implements ControlStructure {
 | 
				
			|||||||
            
 | 
					            
 | 
				
			||||||
            case "elseif":
 | 
					            case "elseif":
 | 
				
			||||||
                return "<?php elseif ($arguments): ?>";
 | 
					                return "<?php elseif ($arguments): ?>";
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
            case "/if":
 | 
					 | 
				
			||||||
            case "endif":
 | 
					            case "endif":
 | 
				
			||||||
                return "<?php endif ?>";
 | 
					                return "<?php endif ?>";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,7 @@ enum PrintActionEnum : string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class SectionToken implements ControlStructure {
 | 
					class SectionToken implements ControlStructure {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public array $token = [ "section", "endsection", "/section" ];
 | 
					    public array $token = [ "section", "endsection" ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected PrintActionEnum $action = PrintActionEnum::default;
 | 
					    protected PrintActionEnum $action = PrintActionEnum::default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -29,13 +29,10 @@ class SectionToken implements ControlStructure {
 | 
				
			|||||||
                return $this->printSection($context, $arguments);
 | 
					                return $this->printSection($context, $arguments);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            case "endsection":
 | 
					            case "endsection":
 | 
				
			||||||
            case "/endsection":
 | 
					 | 
				
			||||||
                if ( empty($context->sections) ) {
 | 
					                if ( empty($context->sections) ) {
 | 
				
			||||||
                    throw new \RuntimeException("A section closing tag {% endsection %} was found without an opening {% section %} tag");
 | 
					                    throw new \RuntimeException("A section closing tag {% endsection %} was found without an opening {% section %} tag");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $this->action = PrintActionEnum::default;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return $this->printEndSection($context);
 | 
					                return $this->printEndSection($context);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -23,13 +23,11 @@ class SwitchToken implements ControlStructure {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                return ( $output ?? "" ) . "case $arguments: ?>";
 | 
					                return ( $output ?? "" ) . "case $arguments: ?>";
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            case "endcase":
 | 
					            case "endcase":
 | 
				
			||||||
            case "/case":
 | 
					 | 
				
			||||||
                return "<?php break; ?>";
 | 
					                return "<?php break; ?>";
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
            case "endswitch":
 | 
					            case "endswitch":
 | 
				
			||||||
            case "/switch":
 | 
					 | 
				
			||||||
                return "<?php endswitch; ?>"; 
 | 
					                return "<?php endswitch; ?>"; 
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,25 +0,0 @@
 | 
				
			|||||||
<?php
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace Picea\ControlStructure;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class TryCatchToken implements ControlStructure {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public array $token = [ "try", "catch", "finally", "endtry", "/try" ];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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":
 | 
					 | 
				
			||||||
            case "/try":
 | 
					 | 
				
			||||||
                return "<?php } ?>";
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -3,7 +3,7 @@
 | 
				
			|||||||
namespace Picea\ControlStructure;
 | 
					namespace Picea\ControlStructure;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WhileToken extends AbstractLoop {
 | 
					class WhileToken extends AbstractLoop {
 | 
				
			||||||
    public array $token = [ "do", "while", "endwhile", "/while" ];
 | 
					    public array $token = [ "do", "while", "endwhile", ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string {
 | 
					    public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string {
 | 
				
			||||||
        switch($token) {
 | 
					        switch($token) {
 | 
				
			||||||
@ -23,13 +23,10 @@ class WhileToken extends AbstractLoop {
 | 
				
			|||||||
                        return "<?php } while($arguments); ?>";
 | 
					                        return "<?php } while($arguments); ?>";
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					 | 
				
			||||||
                return $this->openLoop($context, $arguments, $token);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            case "endwhile":
 | 
					 | 
				
			||||||
            case "/while":
 | 
					 | 
				
			||||||
                return $this->closeLoop($context, $arguments, $token);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return parent::parse($context, $arguments, $token);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -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 = "",
 | 
					        public string $title = "",
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
        $this->locale = explode('.', \Locale::getDefault())[0];
 | 
					        $this->locale = explode('.', \Locale::getDefault())[0];
 | 
				
			||||||
        $this->formatter = new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function exportFunctions(): array
 | 
					    public function exportFunctions(): array
 | 
				
			||||||
@ -56,6 +55,8 @@ class NumberExtension implements Extension, FunctionExtension {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function money(float $money, ? string $currency = null) /* : string|false */
 | 
					    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->setTextAttribute(\NumberFormatter::CURRENCY_CODE, 'CAD');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->formatter->setPattern( str_replace('¤#','¤ #', $this->formatter->getPattern() ) );
 | 
					        $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 array $token = [ "echo", "print", "printf", "no_html" ];
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    public int $flag = \ENT_QUOTES | \ENT_DISALLOWED | \ENT_SUBSTITUTE;
 | 
					    public int $flag = \ENT_QUOTES;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public string $encoding;
 | 
					    public string $encoding;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -2,10 +2,15 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Picea\Extension;
 | 
					namespace Picea\Extension;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Notes\Route\Attribute\Object\Route;
 | 
				
			||||||
use Picea\EventTrait;
 | 
					use Picea\EventTrait;
 | 
				
			||||||
 | 
					use Picea\Compiler\Context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use Picea\Event\Extension\{ UrlBuildAssetEvent, UrlBuildUrlEvent, UrlBuildRouteEvent, UrlRegisterRouteEvent };
 | 
					use Picea\Event\Extension\{ UrlBuildAssetEvent, UrlBuildUrlEvent, UrlBuildRouteEvent, UrlRegisterRouteEvent };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class UrlExtension implements Extension, FunctionExtension {
 | 
					class UrlExtension implements Extension, FunctionExtension {
 | 
				
			||||||
 | 
					    use \Picea\EventTrait;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    use EventTrait;
 | 
					    use EventTrait;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public const URLIZE_PATTERN_URL = <<<PATTERN
 | 
					    public const URLIZE_PATTERN_URL = <<<PATTERN
 | 
				
			||||||
@ -30,8 +35,8 @@ PATTERN;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public array $tokens = [ "url" , "route", "asset", "slug" ];
 | 
					    public array $tokens = [ "url" , "route", "asset", "slug" ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ##[\Deprecated]
 | 
					    #[\Deprecated]
 | 
				
			||||||
    public bool $enforceExistingArguments = true;
 | 
					    protected bool $enforceExistingArguments = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function __construct(string $urlBase = "", string $assetToken = "", array $appUrl = [], bool $forceSSL = false) {
 | 
					    public function __construct(string $urlBase = "", string $assetToken = "", array $appUrl = [], bool $forceSSL = false) {
 | 
				
			||||||
        $this->urlBase = trim($urlBase, "/");
 | 
					        $this->urlBase = trim($urlBase, "/");
 | 
				
			||||||
@ -63,7 +68,7 @@ PATTERN;
 | 
				
			|||||||
                return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->slug($arguments) ?>";
 | 
					                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
 | 
					    public function exportFunctions(): array
 | 
				
			||||||
@ -120,7 +125,7 @@ PATTERN;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function buildRouteUrl(string $name, array $parameters = [], bool $appendVersion = false) : string
 | 
					    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);
 | 
					            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
 | 
					    public function registerRoute(string $name, string $route, string $class, string $method, array $routeMethods) : void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->routes[] = $array = [
 | 
					        $this->routes[$name] = [
 | 
				
			||||||
            'name' => $name,
 | 
					 | 
				
			||||||
            'route' => $route,
 | 
					            'route' => $route,
 | 
				
			||||||
            'routeMethods' => array_map('strtoupper', $routeMethods),
 | 
					            'routeMethods' => $routeMethods,
 | 
				
			||||||
            'class' => $class,
 | 
					            'class' => $class,
 | 
				
			||||||
            'classMethod' => $method,
 | 
					            'classMethod' => $method,
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->eventExecute(UrlRegisterRouteEvent::class, $name, $array);
 | 
					        $this->eventExecute(UrlRegisterRouteEvent::class, $name, $this->routes[$name]);
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -289,7 +280,7 @@ PATTERN;
 | 
				
			|||||||
                    if ($default ?? false) {
 | 
					                    if ($default ?? false) {
 | 
				
			||||||
                        $value = $default;
 | 
					                        $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']));
 | 
					                        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
 | 
					    public function registerControlStructure(Compiler $compiler) : void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $compiler->registerControlStructure(new \Picea\ControlStructure\TryCatchToken());
 | 
					 | 
				
			||||||
        $compiler->registerControlStructure(new \Picea\ControlStructure\NamespaceToken());
 | 
					        $compiler->registerControlStructure(new \Picea\ControlStructure\NamespaceToken());
 | 
				
			||||||
        $compiler->registerControlStructure(new \Picea\ControlStructure\UseToken());
 | 
					        $compiler->registerControlStructure(new \Picea\ControlStructure\UseToken());
 | 
				
			||||||
        $compiler->registerControlStructure(new \Picea\ControlStructure\IfToken());
 | 
					        $compiler->registerControlStructure(new \Picea\ControlStructure\IfToken());
 | 
				
			||||||
 | 
				
			|||||||
@ -180,7 +180,6 @@ class Picea implements LanguageRegistration
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if ( $this->debug || ! $this->cache->compiled( $context->cacheFilename() ) ) {
 | 
					        if ( $this->debug || ! $this->cache->compiled( $context->cacheFilename() ) ) {
 | 
				
			||||||
            $context = $this->compileContext($context);
 | 
					            $context = $this->compileContext($context);
 | 
				
			||||||
 | 
					 | 
				
			||||||
            $this->cache->save($context);
 | 
					            $this->cache->save($context);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user