This commit is contained in:
mcndave committed 2023-12-04 12:34:31 -05:00
1 parent a9db9cd846
commit 45ffc6e128
7 files changed
+53 -11

No files matched your search

+4
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
+7 -3
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();
+31 -2
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']));