- Added the application feature - a big reason why Lean was created in the first place.
- Began moving some repetitive parts from projects to projects into lean
This commit is contained in:
1 parent
4bd68a74f8
commit
bdb9f7f732
13 files changed
+571
-2
No files matched your search
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Lean;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class Lean
|
||||
{
|
||||
const DEFAULT_PICEA_CONTEXT = __NAMESPACE__;
|
||||
|
||||
protected ContainerInterface $container;
|
||||
|
||||
public array $applications = [];
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
$this->loadApplications();
|
||||
}
|
||||
|
||||
protected function loadApplications() : void
|
||||
{
|
||||
$list = $this->container->get('config')['lean']['autoload'] ?? [];
|
||||
|
||||
if (! $list ) {
|
||||
throw new \Exception("You must provide at least one application to autoload within your config file ( 'lean' => 'autoload' => [] )");
|
||||
}
|
||||
|
||||
foreach($list as $application) {
|
||||
if ( $this->container->has($application) ) {
|
||||
$this->applications[] = ( new Application() )->fromArray($this->container->get($application));
|
||||
}
|
||||
else {
|
||||
throw new \RuntimeException("Trying to load an application '$application' which have not been configured yet");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getPiceaContext() : string
|
||||
{
|
||||
foreach(array_reverse($this->applications) as $apps) {
|
||||
if ( $apps->piceaContext ) {
|
||||
return $apps->piceaContext;
|
||||
}
|
||||
}
|
||||
|
||||
return static::DEFAULT_PICEA_CONTEXT;
|
||||
}
|
||||
|
||||
public function getRoutable() : array
|
||||
{
|
||||
return array_merge(...array_map(fn($app) => $app->routes ?? [], $this->applications));
|
||||
}
|
||||
|
||||
public function getViewPaths() : array
|
||||
{
|
||||
$list = array_merge(...array_map(fn($app) => $app->views ?? [], $this->applications));
|
||||
|
||||
uasort($list, fn($i1, $i2) => $i1['order'] <=> $i2['order'] );
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getI18n(string $reader) : ? array
|
||||
{
|
||||
switch($reader) {
|
||||
case "php":
|
||||
$list = array_merge(...array_map(fn($app) => $app->tellPhp ?? [], $this->applications));
|
||||
break;
|
||||
|
||||
case "json":
|
||||
$list = array_merge(...array_map(fn($app) => $app->tellJson ?? [], $this->applications));
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $list ?? false ) {
|
||||
uasort($list, fn($i1, $i2) => $i2['order'] <=> $i1['order']);
|
||||
|
||||
return array_map(fn($item) => $item['path'], $list);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function definitions() : array
|
||||
{
|
||||
$path = dirname(__DIR__) . "/meta/definitions/";
|
||||
|
||||
return array_merge(
|
||||
require($path . "http.php"),
|
||||
require($path . "language.php"),
|
||||
require($path . "routes.php"),
|
||||
require($path . "software.php"),
|
||||
require($path . "template.php"),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user