- WIP on cleaning of definitions files

This commit is contained in:
Dave Mc Nicoll 2024-06-07 00:01:43 +00:00
parent 63fde92b68
commit d9f9c053c3
8 changed files with 55 additions and 29 deletions

View File

@ -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",

View File

@ -1,29 +1,37 @@
<?php
use function DI\autowire, DI\create, DI\get;
use Tell\I18n;
use Psr\Container\ContainerInterface;
use Notes\Tell\LanguageHandler;
return [
Tell\I18n::class => 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,
]),
];

9
meta/definitions/orm.php Normal file
View File

@ -0,0 +1,9 @@
<?php
use Ulmus\Container\AdapterProxy;
return [
'lean.autoload' => add([
AdapterProxy::class,
]),
];

View File

@ -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);

View File

@ -1,6 +1,6 @@
<?php
use function DI\autowire, DI\create, DI\get;
use Tell\I18n;
use TheBugs\JavascriptMiddleware;
@ -10,6 +10,8 @@ use Storage\Cookie,
Storage\Session,
Storage\SessionMiddleware;
use function DI\autowire, DI\create, DI\get, DI\add;
$dir = dirname(__DIR__, 2);
return [
@ -74,6 +76,10 @@ return [
],
],
'lean.autoload' => add([
Lean::class,
]),
Lean::class => autowire(Lean::class),
JavascriptMiddleware::class => create(JavascriptMiddleware::class),

View File

@ -1,6 +1,7 @@
<?php
use Ulmus\ConnectionAdapter;
use Ulmus\{ ConnectionAdapter, Container\AdapterProxy };
use Lean\Lean;
return [
'lean:adapter.sqlite' => function($c) {

View File

@ -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);

View File

@ -0,0 +1,5 @@
<?php
namespace Lean\Routing;
interface RouteDefinitionInterface {}