10 Commits
10 changed files with 85 additions and 12 deletions

No files matched your search

+10 -1
View File
@@ -16,5 +16,14 @@
}, },
"require": { "require": {
"psr/http-message": "^1.0" "psr/http-message": "^1.0"
},
"extra": {
"lean": {
"autoload": {
"definitions": [
"meta/definitions.php"
]
}
}
} }
} }
+59
View File
@@ -0,0 +1,59 @@
<?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());
},
];
+1 -1
View File
@@ -4,7 +4,7 @@ namespace Picea\Compiler;
class BaseContext extends Context { class BaseContext extends Context {
public function __construct(?string $defaultNamespace = null) { public function __construct(array|string|null $defaultNamespace = null) {
if ( $defaultNamespace !== null ) { if ( $defaultNamespace !== null ) {
$this->namespace = $defaultNamespace; $this->namespace = $defaultNamespace;
} }
+1 -1
View File
@@ -6,7 +6,7 @@ use Picea\Compiler;
abstract class Context { abstract class Context {
public string $namespace = ""; public string|array $namespace = "";
public string $extendFrom = ""; public string $extendFrom = "";
+2
View File
@@ -33,6 +33,8 @@ class SectionToken implements ControlStructure {
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);
} }
} }
+8
View File
@@ -0,0 +1,8 @@
<?php
namespace Picea\Event\Extension;
interface BuildAssetUrl
{
public function execute(string $uri, array $parameters = [], bool $appendVersion = true) : mixed;
}
+1 -2
View File
@@ -15,6 +15,7 @@ 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
@@ -55,8 +56,6 @@ 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() ) );
+1 -1
View File
@@ -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; public int $flag = \ENT_QUOTES | \ENT_DISALLOWED | \ENT_SUBSTITUTE;
public string $encoding; public string $encoding;
+1 -6
View File
@@ -2,15 +2,10 @@
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
@@ -68,7 +63,7 @@ PATTERN;
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->slug($arguments) ?>"; return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->slug($arguments) ?>";
} }
throw new \ParseExtensionException("Unknown token given $token in UrlExtension."); throw new \Exception("Unknown token given $token in UrlExtension.");
} }
public function exportFunctions(): array public function exportFunctions(): array
+1
View File
@@ -180,6 +180,7 @@ 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);
} }