diff --git a/docs/99-dependency-injection.md b/docs/99-dependency-injection.md index 5e45e98..980bb53 100644 --- a/docs/99-dependency-injection.md +++ b/docs/99-dependency-injection.md @@ -10,7 +10,7 @@ use function DI\autowire, DI\create, DI\get; use Laminas\Diactoros\Response\HtmlResponse; use Picea\{ Picea, Caching\Cache, Caching\Opcache, Compiler, Compiler\Context, Compiler\BaseContext, FileFetcher, Language\DefaultRegistrations, Method\Request }; -use Picea\Extension\{ LanguageHandler, LanguageExtension, TitleExtension, NumberExtension, UrlExtension }; +use Picea\Extension\{ LanguageHandlerInterface, LanguageExtension, TitleExtension, NumberExtension, UrlExtension }; use Picea\Ui\{ Method, Ui }; return [ @@ -49,10 +49,10 @@ return [ Method\Pagination::class => autowire(Method\Pagination::class), - LanguageExtension::class => create(LanguageExtension::class)->constructor(get(LanguageHandler::class)), + LanguageExtension::class => create(LanguageExtension::class)->constructor(get(LanguageHandlerInterface::class)), - LanguageHandler::class => function($c) { - return new class( $c->get(Tell\I18n::class) ) implements LanguageHandler { + LanguageHandlerInterface::class => function($c) { + return new class( $c->get(Tell\I18n::class) ) implements LanguageHandlerInterface { public Tell\I18n $tell; public function __construct(Tell\I18n $tell) { diff --git a/src/Compiler.php b/src/Compiler.php index 788873e..3edb082 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -25,11 +25,10 @@ class Compiler public array $extensionList = []; - public ? LanguageRegistration $languageRegistration; - - public function __construct(?LanguageRegistration $languageRegistration = null) + public function __construct( + public LanguageRegistration $languageRegistration + ) { - $this->languageRegistration = $languageRegistration; $this->languageRegistration->registerAll($this); } @@ -158,7 +157,7 @@ class Compiler return $this->extensionList[$tokenName]; } - + public function exportFunctions() : void { static $caching = []; diff --git a/src/Extension/LanguageExtension.php b/src/Extension/LanguageExtension.php index a821e85..3df7c7b 100644 --- a/src/Extension/LanguageExtension.php +++ b/src/Extension/LanguageExtension.php @@ -11,9 +11,9 @@ class LanguageExtension implements Extension, FunctionExtension { public string $currentLanguage = ""; - protected LanguageHandler $languageHandler; + protected LanguageHandlerInterface $languageHandler; - public function __construct(LanguageHandler $handler) { + public function __construct(LanguageHandlerInterface $handler) { $this->languageHandler = $handler; } diff --git a/src/Extension/LanguageHandler.php b/src/Extension/LanguageHandlerInterface.php similarity index 78% rename from src/Extension/LanguageHandler.php rename to src/Extension/LanguageHandlerInterface.php index 281e6aa..85af89d 100644 --- a/src/Extension/LanguageHandler.php +++ b/src/Extension/LanguageHandlerInterface.php @@ -2,7 +2,7 @@ namespace Picea\Extension; -interface LanguageHandler +interface LanguageHandlerInterface { public function languageFromKey(string $key, array $variables = []); #: array|string; } diff --git a/src/Extension/UrlExtension.php b/src/Extension/UrlExtension.php index 974a329..95d4920 100644 --- a/src/Extension/UrlExtension.php +++ b/src/Extension/UrlExtension.php @@ -43,13 +43,6 @@ PATTERN; $this->assetToken = $assetToken; $this->appUrl = $appUrl; $this->forceSSL = $forceSSL; - - $this->eventRegister(new class() implements BuildAssetUrl { - public function execute(string $uri, array $parameters = [], bool $appendVersion = true) : mixed - { - - } - }); } public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string diff --git a/src/Language/DefaultRegistrations.php b/src/Language/DefaultRegistrations.php index 72d40f0..d694e29 100644 --- a/src/Language/DefaultRegistrations.php +++ b/src/Language/DefaultRegistrations.php @@ -6,18 +6,11 @@ use Picea\Compiler; class DefaultRegistrations implements LanguageRegistration { - protected array $extensions; - - protected array $syntaxes; - - protected array $controlStructures; - - public function __construct(array $extensions = [], array $syntaxes = [], array $controlStructure = []) - { - $this->extensions = $extensions; - $this->syntaxes = $syntaxes; - $this->controlStructures = $controlStructure; - } + public function __construct( + protected array $extensions, + protected array $syntaxes, + protected array $controlStructures, + ) { } public function registerAll(Compiler $compiler) : void { diff --git a/src/Picea.php b/src/Picea.php index eb1f600..4528d96 100644 --- a/src/Picea.php +++ b/src/Picea.php @@ -43,7 +43,7 @@ class Picea implements LanguageRegistration ){ $this->cache = $cache ?? new Caching\Memory(""); $this->context = $context ?? new Compiler\BaseContext(); - $this->languageRegistration = $languageRegistration ?? new Language\DefaultRegistrations(); + $this->languageRegistration = $languageRegistration ?? new Language\DefaultRegistrations([], [], []); $this->builderTemplatePath = $builderTemplatePath ?? dirname(__FILE__) . static::DEFAULT_BUILDER_TEMPLATE; $this->compiler = $compiler ?? $this->instanciateCompiler(); $this->fileFetcher = $fileFetcher ?? $this->instanciateFileFetcher();