- Merged
This commit is contained in:
parent
a9db9cd846
commit
45ffc6e128
|
@ -24,10 +24,10 @@ return [
|
||||||
},
|
},
|
||||||
|
|
||||||
Event\EventDefinition::class => function($c) {
|
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([
|
return new Event\EventDefinition([
|
||||||
new class($ext) implements RoutingCompileRoutes {
|
new class($extension) implements RoutingCompileRoutes {
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected ? \Picea\Extension\UrlExtension $extension,
|
protected ? \Picea\Extension\UrlExtension $extension,
|
||||||
) {}
|
) {}
|
||||||
|
|
|
@ -26,6 +26,4 @@ return [
|
||||||
Tell\Reader\JsonReader::class => function($c) {
|
Tell\Reader\JsonReader::class => function($c) {
|
||||||
return new Tell\Reader\JsonReader($c->get(Lean\Lean::class)->getI18n('json'), true, \JSON_PRETTY_PRINT);
|
return new Tell\Reader\JsonReader($c->get(Lean\Lean::class)->getI18n('json'), true, \JSON_PRETTY_PRINT);
|
||||||
},
|
},
|
||||||
|
|
||||||
LanguageHandler::class => autowire(LanguageHandler::class),
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -65,7 +65,13 @@ return [
|
||||||
|
|
||||||
'cronard' => [],
|
'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),
|
Lean::class => autowire(Lean::class),
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace %NAMESPACE%;
|
namespace %NAMESPACE%;
|
||||||
|
|
||||||
|
use Lean\Lean;
|
||||||
use Ulmus\ConnectionAdapter;
|
use Ulmus\ConnectionAdapter;
|
||||||
|
|
||||||
require_once dirname(__DIR__) . '/vendor/autoload.php';
|
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->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();
|
return parent::initializeEngine();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,10 @@ class Composer
|
||||||
if ( file_exists($container = static::createPath('var/cache/di/CompiledContainer.php')) ) {
|
if ( file_exists($container = static::createPath('var/cache/di/CompiledContainer.php')) ) {
|
||||||
unlink($container);
|
unlink($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (function_exists("apcu_clear_cache")) {
|
||||||
|
apcu_clear_cache();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function readComposerLock() : false|array
|
public static function readComposerLock() : false|array
|
||||||
|
|
|
@ -31,6 +31,8 @@ class Kernel {
|
||||||
|
|
||||||
public string $definitionFilePath;
|
public string $definitionFilePath;
|
||||||
|
|
||||||
|
public array $definitionFilePaths = [];
|
||||||
|
|
||||||
public string $errorLogPath;
|
public string $errorLogPath;
|
||||||
|
|
||||||
public string $projectPath;
|
public string $projectPath;
|
||||||
|
@ -124,10 +126,12 @@ class Kernel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# $containerBuilder->useAnnotations(false);
|
|
||||||
|
|
||||||
if ($this->definitionFilePath ?? 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();
|
$this->container = $containerBuilder->build();
|
||||||
|
|
33
src/Lean.php
33
src/Lean.php
|
@ -161,6 +161,23 @@ class Lean
|
||||||
return [];
|
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
|
public static function autoloadDefinitionsFromComposerExtra() : array
|
||||||
{
|
{
|
||||||
$list = [];
|
$list = [];
|
||||||
|
@ -187,13 +204,25 @@ class Lean
|
||||||
return $list;
|
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
|
protected static function loadFromPackage(array $package, array|string $autoload) : false|array
|
||||||
{
|
{
|
||||||
$list = [];
|
$list = [];
|
||||||
|
|
||||||
if (is_string($autoload)) {
|
if (is_string($autoload)) {
|
||||||
$vendor = getenv('VENDOR_DIR') ? getenv('VENDOR_PATH') : dirname(__DIR__, 3);
|
$file = static::pathFromPackage($package, $autoload);
|
||||||
$file = $vendor . DIRECTORY_SEPARATOR . $package['name'] . DIRECTORY_SEPARATOR . $autoload;
|
|
||||||
|
|
||||||
if ( ! file_exists($file) ) {
|
if ( ! file_exists($file) ) {
|
||||||
throw new \InvalidArgumentException(sprintf("Given autoload file `%s` from package `%s` was not found or is unreachable", $autoload, $package['name']));
|
throw new \InvalidArgumentException(sprintf("Given autoload file `%s` from package `%s` was not found or is unreachable", $autoload, $package['name']));
|
||||||
|
|
Loading…
Reference in New Issue