From d9f9c053c394bd6f3ea9abe704790b2c00753fd4 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 7 Jun 2024 00:01:43 +0000 Subject: [PATCH] - WIP on cleaning of definitions files --- composer.json | 1 + meta/definitions/language.php | 36 +++++++++++++++--------- meta/definitions/orm.php | 9 ++++++ meta/definitions/routes.php | 2 +- meta/definitions/software.php | 8 +++++- meta/definitions/storage.php | 3 +- src/Kernel.php | 20 ++++++------- src/Routing/RouteDefinitionInterface.php | 5 ++++ 8 files changed, 55 insertions(+), 29 deletions(-) create mode 100644 meta/definitions/orm.php create mode 100644 src/Routing/RouteDefinitionInterface.php diff --git a/composer.json b/composer.json index 5772d7d..3383551 100644 --- a/composer.json +++ b/composer.json @@ -87,6 +87,7 @@ "meta/definitions/email.php", "meta/definitions/event.php", "meta/definitions/http.php", + "meta/definitions/orm.php", "meta/definitions/language.php", "meta/definitions/routes.php", "meta/definitions/software.php", diff --git a/meta/definitions/language.php b/meta/definitions/language.php index 910580d..07afe90 100644 --- a/meta/definitions/language.php +++ b/meta/definitions/language.php @@ -1,29 +1,37 @@ create( Tell\I18n::class ) ->constructor( - get(Tell\Reader\JsonReader::class), - get(Tell\Reader\PhpReader::class), - get('tell.fallback') /* getenv("DEBUG") ? create(Tell\PrintMissingKey::class) : get('tell.fallback') */ - ), +use function DI\autowire, DI\create, DI\get, DI\add; - 'tell.fallback' => function($c) { - $i18n = new Tell\I18n( $c->get(Tell\Reader\JsonReader::class), $c->get(Tell\Reader\PhpReader::class), new Tell\PrintMissingKey() ); +return [ + I18n::class => function(ContainerInterface $container) { + $i18n = new I18n($container->get(Tell\Reader\JsonReader::class), $container->get(Tell\Reader\PhpReader::class), $container->get('tell.fallback')); + $i18n->locale(getenv('DEFAULT_LOCAL')); + $i18n->initialize(! getenv("DEBUG")); + + return $i18n; + }, + + 'tell.fallback' => function(ContainerInterface $container) { + $i18n = new Tell\I18n( $container->get(Tell\Reader\JsonReader::class), $container->get(Tell\Reader\PhpReader::class), new Tell\PrintMissingKey() ); $i18n->locale(getenv('DEFAULT_LOCAL_FALLBACK') ?: "en_US"); $i18n->initialize(true); return $i18n; }, - Tell\Reader\PhpReader::class => function($c) { - return new Tell\Reader\PhpReader($c->get(Lean\Lean::class)->getI18n('php'), false); + Tell\Reader\PhpReader::class => function(ContainerInterface $container) { + return new Tell\Reader\PhpReader($container->get(Lean\Lean::class)->getI18n('php'), false); }, - Tell\Reader\JsonReader::class => function($c) { - return new Tell\Reader\JsonReader($c->get(Lean\Lean::class)->getI18n('json'), true, \JSON_PRETTY_PRINT); + Tell\Reader\JsonReader::class => function(ContainerInterface $container) { + return new Tell\Reader\JsonReader($container->get(Lean\Lean::class)->getI18n('json'), true, \JSON_PRETTY_PRINT); }, + + 'lean.autoload' => add([ + I18n::class, + ]), ]; diff --git a/meta/definitions/orm.php b/meta/definitions/orm.php new file mode 100644 index 0000000..d947c33 --- /dev/null +++ b/meta/definitions/orm.php @@ -0,0 +1,9 @@ + add([ + AdapterProxy::class, + ]), +]; diff --git a/meta/definitions/routes.php b/meta/definitions/routes.php index e8bfc8b..09b022d 100644 --- a/meta/definitions/routes.php +++ b/meta/definitions/routes.php @@ -54,7 +54,7 @@ return [ # PostRequestAuthenticationMiddleware::class, ], - 'routes.list' => function($c) { + Lean\Routing\RouteDefinitionInterface::class => function($c) { return function (ContainerInterface $container) { $router = $container->get(Router::class); diff --git a/meta/definitions/software.php b/meta/definitions/software.php index 27e71b5..8cab042 100644 --- a/meta/definitions/software.php +++ b/meta/definitions/software.php @@ -1,6 +1,6 @@ add([ + Lean::class, + ]), + Lean::class => autowire(Lean::class), JavascriptMiddleware::class => create(JavascriptMiddleware::class), diff --git a/meta/definitions/storage.php b/meta/definitions/storage.php index 6020ee7..75c85bf 100644 --- a/meta/definitions/storage.php +++ b/meta/definitions/storage.php @@ -1,6 +1,7 @@ function($c) { diff --git a/src/Kernel.php b/src/Kernel.php index 9f27cb2..9eec3e7 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -37,8 +37,6 @@ class Kernel { public string $projectPath; - public string $routeDefinitionList = 'routes.list'; - public function __construct(string $projectPath) { $this->projectPath = $projectPath; @@ -141,16 +139,15 @@ class Kernel { protected function serviceContainer() : self { - $this->container->has(AdapterProxy::class) and $this->container->get(AdapterProxy::class); - $this->container->has('ulmus.caching') and ( Ulmus::$cache = $this->container->get('ulmus.caching') ); - $this->container->has(Lean::class) and $this->container->get(Lean::class); - - if ($this->container->has(I18n::class)) { - $i18n = $this->container->get(I18n::class); - $i18n->locale($this->locale); - $i18n->initialize(!getenv("DEBUG")); + if ($this->container->has('lean.autoload')) { + foreach($this->container->get('lean.autoload') as $class) { + $this->container->get($class); + } } + # Must be removed from KERNEL ! + $this->container->has('ulmus.caching') and ( Ulmus::$cache = $this->container->get('ulmus.caching') ); + return $this; } @@ -158,8 +155,7 @@ class Kernel { { ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); - // Router - $routeFactory = $this->container->get($this->routeDefinitionList); + $routeFactory = $this->container->get(Routing\RouteDefinitionInterface::class); $router = $routeFactory($this->container); diff --git a/src/Routing/RouteDefinitionInterface.php b/src/Routing/RouteDefinitionInterface.php new file mode 100644 index 0000000..71b56a4 --- /dev/null +++ b/src/Routing/RouteDefinitionInterface.php @@ -0,0 +1,5 @@ +