From dc52c88c03a08327ed30e725b24c065556ee7515 Mon Sep 17 00:00:00 2001 From: Dave M Date: Thu, 17 Jul 2025 18:37:46 +0000 Subject: [PATCH] - Various fixes bugs and missing code in project's skeleton --- meta/definitions/routes.php | 2 +- meta/i18n/en/lean.date.json | 9 ++++ meta/i18n/fr/lean.date.json | 9 ++++ skeleton/meta/definitions/definitions.php | 4 ++ skeleton/src/Factory/FormFactory.php | 46 +++++++++++++++++++ skeleton/src/Factory/FormFactoryInterface.php | 25 ++++++++++ src/ControllerTrait.php | 5 +- src/Kernel.php | 11 ++--- view/lean/block/since.phtml | 23 ++++++++++ 9 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 skeleton/src/Factory/FormFactory.php create mode 100644 skeleton/src/Factory/FormFactoryInterface.php create mode 100644 view/lean/block/since.phtml diff --git a/meta/definitions/routes.php b/meta/definitions/routes.php index a2460b9..b2a4c94 100644 --- a/meta/definitions/routes.php +++ b/meta/definitions/routes.php @@ -59,7 +59,7 @@ return [ $router = $container->get(Router::class); foreach([ 'routes.middlewares', 'app.middlewares' ] as $key) { - if ( $container->has($key) ) { + if ($container->has($key)) { foreach ($container->get($key) as $i => $middleware) { if ($container->has($middleware)) { $router->middleware($container->get($middleware)); diff --git a/meta/i18n/en/lean.date.json b/meta/i18n/en/lean.date.json index 2fe6844..c30924c 100644 --- a/meta/i18n/en/lean.date.json +++ b/meta/i18n/en/lean.date.json @@ -5,6 +5,15 @@ "week": "week" }, + "interval": { + "years": "{$years} year(s)", + "months": "{$months} month(s)", + "days": "{$days} day(s)", + "hours": "{$hours} hour(s)", + "minutes": "{$minutes} minutes(s)", + "seconds": "{$seconds} second(s)" + }, + "month": { "list": [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "Décember" diff --git a/meta/i18n/fr/lean.date.json b/meta/i18n/fr/lean.date.json index f236ce0..d6655c9 100644 --- a/meta/i18n/fr/lean.date.json +++ b/meta/i18n/fr/lean.date.json @@ -4,6 +4,15 @@ "week": "semaine" }, + "interval": { + "years": "{$years} années(s)", + "months": "{$months} mois", + "days": "{$days} jour(s)", + "hours": "{$hours} heure(s)", + "minutes": "{$minutes} minutes(s)", + "seconds": "{$seconds} seconde(s)" + }, + "month": { "list": [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" diff --git a/skeleton/meta/definitions/definitions.php b/skeleton/meta/definitions/definitions.php index d6e82dc..4c30de3 100644 --- a/skeleton/meta/definitions/definitions.php +++ b/skeleton/meta/definitions/definitions.php @@ -7,6 +7,10 @@ use function DI\{ autowire, add, create, get }; $dir = dirname(__DIR__, 2); return [ + \%NAMESPACE%\Factory\FormFactoryInterface::class => autowire(Factory\FormFactory::class), + \Lean\Api\Factory\MessageFactoryInterface::class => autowire(\%NAMESPACE%\Lib\Message::class), + + '%APPKEY%' => [ 'picea' => [ 'context' => "%ESCAPED_NAMESPACE%\\View", diff --git a/skeleton/src/Factory/FormFactory.php b/skeleton/src/Factory/FormFactory.php new file mode 100644 index 0000000..6d459a9 --- /dev/null +++ b/skeleton/src/Factory/FormFactory.php @@ -0,0 +1,46 @@ +languageHandler, $this->messageFactory, $entity); + } + + public function saveContext(? ServerRequestInterface $request = null, ? string $formName = null): FormContextInterface + { + return new Form\SaveContext($request ?: $this->request, $formName); + } + + public function delete(EntityInterface $entity): FormInterface + { + return new Form\Delete($this->languageHandler, $this->messageFactory, $entity); + } + + public function deleteContext(?ServerRequestInterface $request = null, ?string $formName = null): FormContextInterface + { + return new Lib\FormContext($request, $formName); + } + */ +} \ No newline at end of file diff --git a/skeleton/src/Factory/FormFactoryInterface.php b/skeleton/src/Factory/FormFactoryInterface.php new file mode 100644 index 0000000..e47e54e --- /dev/null +++ b/skeleton/src/Factory/FormFactoryInterface.php @@ -0,0 +1,25 @@ +contextList[$context->formName ?? uniqid("context_")] = $context; @@ -220,7 +221,7 @@ trait ControllerTrait { } #[Ignore] - public function context(? string $name = null) : ? FormContext + public function context(? string $name = null) : ? FormContextInterface { return $name ? $this->contextList[$name] : array_values($this->contextList)[0] ?? null; } diff --git a/src/Kernel.php b/src/Kernel.php index 9b18038..821d7b9 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -27,18 +27,15 @@ class Kernel { public array $paths = []; - public int $errorReporting = E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE; + public int $errorReporting = E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_NOTICE; public array $definitionFilePaths; public string $errorLogPath; - public string $projectPath; - - public function __construct(string $projectPath) - { - $this->projectPath = $projectPath; - + public function __construct( + public string $projectPath + ) { $this->setEnvironment(); $this->initializeEngine(); $this->setupContainer(); diff --git a/view/lean/block/since.phtml b/view/lean/block/since.phtml new file mode 100644 index 0000000..65be88c --- /dev/null +++ b/view/lean/block/since.phtml @@ -0,0 +1,23 @@ +{% arguments \DateInterval $interval %} + +{% if $interval->y %} + {% lang "lean.date.interval.years", [ 'years' => $interval->y ] %}, +{% endif %} + +{% if $interval->m %} + {% lang "lean.date.interval.months", [ 'months' => $interval->m ] %}, +{% endif %} + +{% if $interval->d %} + {% lang "lean.date.interval.days", [ 'days' => $interval->d ] %}, +{% endif %} + +{% if $interval->h %} + {% lang "lean.date.interval.hours", [ 'hours' => $interval->h ] %}, +{% endif %} + +{% if $interval->i %} + {% lang "lean.date.interval.minutes", [ 'minutes' => $interval->i ] %} +{% else %} + {% lang "lean.date.interval.seconds", [ 'seconds' => $interval->s ] %} +{% endif %} \ No newline at end of file