From 45ffc6e128d77cb58c16f040908085de3a2b5c7e Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 4 Dec 2023 12:34:31 -0500 Subject: [PATCH] - Merged --- meta/definitions/event.php | 4 ++-- meta/definitions/language.php | 2 -- meta/definitions/software.php | 8 +++++++- skeleton/src/Kernel.php | 3 ++- src/Composer.php | 4 ++++ src/Kernel.php | 10 +++++++--- src/Lean.php | 33 +++++++++++++++++++++++++++++++-- 7 files changed, 53 insertions(+), 11 deletions(-) diff --git a/meta/definitions/event.php b/meta/definitions/event.php index bfa78a9..db5801a 100644 --- a/meta/definitions/event.php +++ b/meta/definitions/event.php @@ -24,10 +24,10 @@ return [ }, Event\EventDefinition::class => function($c) { - $ext = $c->has(\Picea\Extension\UrlExtension::class) ? $c->get(\Picea\Extension\UrlExtension::class) : null; + $extension = $c->has(\Picea\Extension\UrlExtension::class) ? $c->get(\Picea\Extension\UrlExtension::class) : null; return new Event\EventDefinition([ - new class($ext) implements RoutingCompileRoutes { + new class($extension) implements RoutingCompileRoutes { public function __construct( protected ? \Picea\Extension\UrlExtension $extension, ) {} diff --git a/meta/definitions/language.php b/meta/definitions/language.php index 2438eaa..910580d 100644 --- a/meta/definitions/language.php +++ b/meta/definitions/language.php @@ -26,6 +26,4 @@ return [ Tell\Reader\JsonReader::class => function($c) { return new Tell\Reader\JsonReader($c->get(Lean\Lean::class)->getI18n('json'), true, \JSON_PRETTY_PRINT); }, - - LanguageHandler::class => autowire(LanguageHandler::class), ]; diff --git a/meta/definitions/software.php b/meta/definitions/software.php index c6b8605..27e71b5 100644 --- a/meta/definitions/software.php +++ b/meta/definitions/software.php @@ -65,7 +65,13 @@ return [ 'cronard' => [], - 'taxus' => [], + 'taxus' => [ + 'is_dev' => [ ' dev' => "Is a developper of this application or has the same rights" ], + 'is_admin' => [ 'admin' => "Can manage almost everything in this application."], + 'is_moderator' => [ 'moderator' => "Can moderate this application."], + 'is_user' => [ 'user' => "Is an authenticated user."], + 'is_anonymous' => [ 'anonymous' => "Is an anonymous user."], + ], ], Lean::class => autowire(Lean::class), diff --git a/skeleton/src/Kernel.php b/skeleton/src/Kernel.php index 7bfccd4..e5dfc21 100644 --- a/skeleton/src/Kernel.php +++ b/skeleton/src/Kernel.php @@ -2,6 +2,7 @@ namespace %NAMESPACE%; +use Lean\Lean; use Ulmus\ConnectionAdapter; require_once dirname(__DIR__) . '/vendor/autoload.php'; @@ -22,7 +23,7 @@ new class(dirname(__DIR__)) extends \Lean\Kernel { { $this->errorLogPath = getenv("LOGS_PATH") . DIRECTORY_SEPARATOR. date("Y-m").".log"; - $this->definitionFilePath = implode(DIRECTORY_SEPARATOR, [ getenv('META_PATH'), 'definitions', 'definitions.php' ]); + $this->definitionFilePaths = Lean::getDefinitionsPathsFromComposer(); return parent::initializeEngine(); } diff --git a/src/Composer.php b/src/Composer.php index 572be9f..3ffd7e2 100644 --- a/src/Composer.php +++ b/src/Composer.php @@ -73,6 +73,10 @@ class Composer if ( file_exists($container = static::createPath('var/cache/di/CompiledContainer.php')) ) { unlink($container); } + + if (function_exists("apcu_clear_cache")) { + apcu_clear_cache(); + } } public static function readComposerLock() : false|array diff --git a/src/Kernel.php b/src/Kernel.php index b6784a4..9f27cb2 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -31,6 +31,8 @@ class Kernel { public string $definitionFilePath; + public array $definitionFilePaths = []; + public string $errorLogPath; public string $projectPath; @@ -124,10 +126,12 @@ class Kernel { } } - # $containerBuilder->useAnnotations(false); - if ($this->definitionFilePath ?? false) { - $containerBuilder->addDefinitions(require($this->definitionFilePath)); + $containerBuilder->addDefinitions($this->definitionFilePath); + } + + foreach($this->definitionFilePaths ?? [] as $path) { + $containerBuilder->addDefinitions($path); } $this->container = $containerBuilder->build(); diff --git a/src/Lean.php b/src/Lean.php index 7b05895..5fe87fe 100644 --- a/src/Lean.php +++ b/src/Lean.php @@ -161,6 +161,23 @@ class Lean return []; } + public static function getDefinitionsPathsFromComposer() : array + { + $list = []; + + foreach(Composer::readComposerLock()['packages'] as $package) { + foreach($package['extra']['lean']['autoload']['definitions'] ?? [] as $autoload) { + $list[] = static::pathFromPackage($package, $autoload); + } + } + + foreach(Composer::readComposerJson()['extra']['lean']['autoload']['definitions'] ?? [] ?? [] as $autoload) { + $list[] = getenv('PROJECT_PATH') . DIRECTORY_SEPARATOR . $autoload; + } + + return $list; + } + public static function autoloadDefinitionsFromComposerExtra() : array { $list = []; @@ -187,13 +204,25 @@ class Lean return $list; } + protected static function pathFromPackage(array $package, array|string $autoload) : string + { + $vendor = getenv('VENDOR_DIR') ? getenv('VENDOR_PATH') : dirname(__DIR__, 3); + + $filepath = $vendor . DIRECTORY_SEPARATOR . $package['name'] . DIRECTORY_SEPARATOR . $autoload; + + if (! file_exists($filepath)) { + throw new \InvalidArgumentException("Given definition filepath do not exists '$filepath'"); + } + + return $filepath; + } + protected static function loadFromPackage(array $package, array|string $autoload) : false|array { $list = []; if (is_string($autoload)) { - $vendor = getenv('VENDOR_DIR') ? getenv('VENDOR_PATH') : dirname(__DIR__, 3); - $file = $vendor . DIRECTORY_SEPARATOR . $package['name'] . DIRECTORY_SEPARATOR . $autoload; + $file = static::pathFromPackage($package, $autoload); if ( ! file_exists($file) ) { throw new \InvalidArgumentException(sprintf("Given autoload file `%s` from package `%s` was not found or is unreachable", $autoload, $package['name']));