- 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,55 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Lean;
|
||||
|
||||
|
||||
class Application
|
||||
{
|
||||
public string $piceaContext;
|
||||
|
||||
public array $views;
|
||||
|
||||
public array $routes;
|
||||
|
||||
public array $entities;
|
||||
|
||||
public array $tellJson;
|
||||
|
||||
public array $tellPhp;
|
||||
|
||||
public function fromArray(array $data) : self
|
||||
{
|
||||
if (is_array($picea = $data['picea'] ?? false)) {
|
||||
if ($picea['context'] ?? false ) {
|
||||
$this->piceaContext = $picea['context'];
|
||||
}
|
||||
|
||||
if ($picea['view'] ?? false) {
|
||||
$this->views = $picea['view'];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($ulmus = $data['ulmus'] ?? false)) {
|
||||
if ($ulmus['entities'] ?? false) {
|
||||
$this->entities = $ulmus['entities'];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($tell = $data['tell'] ?? false)) {
|
||||
if ($tell['json'] ?? false) {
|
||||
$this->tellJson = $tell['json'];
|
||||
}
|
||||
|
||||
if ($tell['php'] ?? false) {
|
||||
$this->tellPhp = $tell['php'];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($routes = $data['routes'] ?? false)) {
|
||||
$this->routes = $data['routes'];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ use function file_get_contents;
|
||||
*/
|
||||
trait ControllerTrait {
|
||||
|
||||
public Session $session;
|
||||
public Session $session;
|
||||
|
||||
public ? Picea\Picea $picea;
|
||||
|
||||
@@ -37,7 +37,7 @@ trait ControllerTrait {
|
||||
|
||||
public array $contextList = [];
|
||||
|
||||
public function __construct(? Picea\Picea $picea, Session $session, ? MailerInterface $mailer = null) {
|
||||
public function __construct(? Picea\Picea $picea = null, ? Session $session = null, ? MailerInterface $mailer = null) {
|
||||
$this->picea = $picea;
|
||||
$this->session = $session;
|
||||
$this->mailer = $mailer;
|
||||
|
||||
@@ -112,6 +112,7 @@ class Kernel {
|
||||
protected function serviceContainer() : self
|
||||
{
|
||||
$this->container->has(AdapterProxy::class) and $this->container->get(AdapterProxy::class);
|
||||
$this->container->has(Lean::class) and $this->container->get(Lean::class);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -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