From 8b6dd85fd5d8b27ee904fc02c8c3ebd7063a84e4 Mon Sep 17 00:00:00 2001
From: Dave Mc Nicoll <info@mcnd.ca>
Date: Wed, 15 Nov 2023 22:12:25 -0500
Subject: [PATCH] - Added PPH-DI definition file

---
 composer.json        | 11 +++++++-
 meta/definitions.php | 61 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 meta/definitions.php

diff --git a/composer.json b/composer.json
index 83fe2ea..052defe 100644
--- a/composer.json
+++ b/composer.json
@@ -16,5 +16,14 @@
     },
     "require": {
         "psr/http-message": "^1.0"
+    },
+    "extra": {
+        "lean": {
+            "autoload": {
+                "definitions": [
+                    "meta/definitions.php"
+                ]
+            }
+        }
     }
-}
+}
\ No newline at end of file
diff --git a/meta/definitions.php b/meta/definitions.php
new file mode 100644
index 0000000..a04dfd5
--- /dev/null
+++ b/meta/definitions.php
@@ -0,0 +1,61 @@
+<?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());
+    },
+
+    Ui::class => autowire(Ui::class),
+
+    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());
+    },
+];
\ No newline at end of file