This commit is contained in:
Dave M. 2023-12-04 12:34:31 -05:00
parent a9db9cd846
commit 45ffc6e128
7 changed files with 53 additions and 11 deletions

View File

@ -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,
) {}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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