Compare commits

..

No commits in common. "ffe66e522c52c951404272a3746d650fbfc11a6b" and "97dac9ddc4247e873c55afec9497e8b6fd8490bf" have entirely different histories.

3 changed files with 66 additions and 46 deletions

View File

@ -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;
@ -122,11 +124,12 @@ class Kernel {
} }
} }
# $containerBuilder->useAnnotations(false);
if ($this->definitionFilePath ?? false) { if ($this->definitionFilePath ?? false) {
$containerBuilder->addDefinitions(Lean::autoloadDefinitionsFromComposerExtra()); $containerBuilder->addDefinitions($this->definitionFilePath);
$containerBuilder->addDefinitions(require($this->definitionFilePath)); }
foreach($this->definitionFilePaths ?? [] as $path) {
$containerBuilder->addDefinitions($path);
} }
$this->container = $containerBuilder->build(); $this->container = $containerBuilder->build();

View File

@ -161,20 +161,33 @@ 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 = [];
foreach(Composer::readComposerLock()['packages'] as $package) { foreach(Composer::readComposerLock()['packages'] as $package) {
foreach($package['extra']['lean']['autoload']['definitions'] ?? [] as $autoload) { foreach($package['extra']['lean']['autoload']['definitions'] ?? [] as $autoload) {
$list = array_replace($list, static::loadFromPackage($package, $autoload, getenv('VENDOR_DIR') ?: dirname(__DIR__, 3))); $list = array_replace($list, static::loadFromPackage($package, $autoload));
} }
} }
foreach(Composer::readComposerJson()['extra']['lean']['autoload']['definitions'] ?? [] as $autoload) {
$list = array_replace($list, static::loadFromPackage(null, $autoload, getenv('PROJECT_PATH') ?: dirname(__DIR__, 5)));
}
return $list; return $list;
} }
@ -184,26 +197,35 @@ class Lean
foreach(Composer::readComposerLock()['packages'] as $package) { foreach(Composer::readComposerLock()['packages'] as $package) {
foreach($package['extra']['lean']['autoload']['config'] ?? [] as $autoload) { foreach($package['extra']['lean']['autoload']['config'] ?? [] as $autoload) {
$list = array_merge_recursive($list, static::loadFromPackage($package, $autoload, getenv('VENDOR_DIR') ?: dirname(__DIR__, 3))); $list = array_merge_recursive($list, static::loadFromPackage($package, $autoload));
} }
} }
foreach(Composer::readComposerJson()['extra']['lean']['autoload']['config'] ?? [] as $autoload) {
$list = array_merge_recursive($list, static::loadFromPackage(null, $autoload, getenv('PROJECT_PATH') ?: dirname(__DIR__, 5)));
}
return $list; return $list;
} }
protected static function loadFromPackage(?array $package, array|string $autoload, string $path) : false|array 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 = []; $list = [];
if (is_string($autoload)) { if (is_string($autoload)) {
$file = $path . DIRECTORY_SEPARATOR . ($package ? $package['name'] . DIRECTORY_SEPARATOR : "") . $autoload; $file = static::pathFromPackage($package, $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", $file, $package['name'])); throw new \InvalidArgumentException(sprintf("Given autoload file `%s` from package `%s` was not found or is unreachable", $autoload, $package['name']));
} }
return require($file); return require($file);
@ -216,4 +238,4 @@ class Lean
return false; return false;
} }
} }

View File

@ -1,33 +1,28 @@
{% if isset($this->breadcrumb) %} <ol class="breadcrumb ">
{% php $routeTree = $this->breadcrumb->getRouteTree($this->session->get('lean.route')) %} <li class="breadcrumb-item"><a href="{% url '' %}"><i class="fas fa-fw fa-tachometer-alt"></i> Tableau de bord</a></li>
{% if count($routeTree) %} {% foreach $this->breadcrumb ?? [] as $crumb %}
<ol class="breadcrumb mb-4 px-3 py-2"> <li class="breadcrumb-item {{ ( $crumb['active'] ?? false ) ? 'active' : '' }}">
{% foreach $routeTree as $index => $crumb %} {% if ! ($crumb['active'] ?? false) %}
<li class="breadcrumb-item {% if $crumb->current %}active{% endif %}"> {? $last = $crumb ?}
{% if ! $crumb->current %}
{% php $last = $crumb %}
<a href="{% route $crumb->routeAnnotation->name %}"> <a href="{% url $crumb['url'] %}">
{% if $crumb->icon ?? false %} {% if $crumb['icon'] ?? false %}
<i class="fa fa-{{ $crumb->icon }}"></i> <i class="fa fa-{{ $crumb['icon'] }}"></i>
{% endif %} {% endif %}
<span>{{ lang($crumb->lang, get_defined_vars()) }}</span> {{ $crumb['title'] }}
</a> </a>
{% else %} {% else %}
{% if $crumb->icon ?? false %} {% if $crumb['icon'] ?? false %}
<i class="fa fa-{{ $crumb->icon }}"></i> <i class="fa fa-{{ $crumb['icon'] }}"></i>
{% endif %} {% endif %}
<span>{{ $crumb['title'] }}</span>
{% endif %}
</li>
{% endforeach %}
<span>{{ lang($crumb->lang, get_defined_vars()) }}</span> {% if $last ?? false %}
{% endif %} <li class="breadcrumb-last-item ml-auto"><a href="{{ url( $last['url']) }}"><i class="fas fa-chevron-circle-left"></i> Retour</a></li>
</li>
{% endforeach %}
{# if $last ?? false %}
<li class="breadcrumb-last-item ml-auto"><a href="{{ ( $last['route'] ?? false ) ? $last['route'] : url($last['url']) }}"><i class="fas fa-chevron-circle-left"></i> Retour</a></li>
{% endif #}
</ol>
{% endif %} {% endif %}
{% endif %} </ol>