From 212dbd17c0cdf4e9b1ba37a5033ef5458d236f55 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Sat, 30 Nov 2024 00:54:42 +0000 Subject: [PATCH] - Now using attributes injection based on PHP-DI's documentation suggestion --- skeleton/meta/definitions/storage.php | 6 ------ src/ControllerTrait.php | 17 ++++++++++++----- src/Kernel.php | 2 ++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/skeleton/meta/definitions/storage.php b/skeleton/meta/definitions/storage.php index 8b485dc..d33a130 100644 --- a/skeleton/meta/definitions/storage.php +++ b/skeleton/meta/definitions/storage.php @@ -16,10 +16,4 @@ return [ return $adapter; }, - - AdapterProxy::class => function (ContainerInterface $c) { - return new AdapterProxy( - $c->get(ConnectionAdapter::class) - ); - }, ]; diff --git a/src/ControllerTrait.php b/src/ControllerTrait.php index 0a9fbd2..4b90d2a 100644 --- a/src/ControllerTrait.php +++ b/src/ControllerTrait.php @@ -2,6 +2,7 @@ namespace Lean; +use DI\Attribute\Inject; use Lean\Factory\HttpFactory; use Notes\Attribute\Ignore; use Notes\Route\Attribute\Object\Route; @@ -18,15 +19,21 @@ use function file_get_contents; #[Security(locked: false, realm: "Protected Area")] #[Route(method: [ "GET", "POST" ])] trait ControllerTrait { - public ? \Notes\Breadcrumb\Breadcrumb $breadcrumb; - public ? Session $session; + #[Inject] + public \Notes\Breadcrumb\Breadcrumb $breadcrumb; - public ? Cookie $cookie; + #[Inject] + public Session $session; - public ? Picea\Picea $picea; + #[Inject] + public Cookie $cookie; - public ? MailerInterface $mailer; + #[Inject] + public Picea\Picea $picea; + + #[Inject] + public MailerInterface $mailer; public array $contextList = []; diff --git a/src/Kernel.php b/src/Kernel.php index f2bc02d..e427592 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -106,6 +106,8 @@ class Kernel { { $containerBuilder = new ContainerBuilder(); + $containerBuilder->useAttributes(true); + if (getenv("APP_ENV") === "prod") { if (getenv("CACHE_PATH")) { # check if ACPU is there first, $containerBuilder->enableDefinitionCache();