- Fixed merges of latest master
This commit is contained in:
commit
1c2ce07179
15 files changed
+187
-86
No files matched your search
@@ -22,6 +22,8 @@ class Application
|
||||
|
||||
public array $entities;
|
||||
|
||||
public array $connectionAdapters;
|
||||
|
||||
public array $events;
|
||||
|
||||
public array $tellJson;
|
||||
@@ -68,6 +70,7 @@ class Application
|
||||
if (is_array($ulmus = $this->data['ulmus'] ?? false)) {
|
||||
if ($ulmus['entities'] ?? false) {
|
||||
$this->entities = $ulmus['entities'];
|
||||
$this->connectionAdapters = $ulmus['adapters'] ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-42
@@ -3,63 +3,33 @@
|
||||
namespace Lean;
|
||||
|
||||
use League\Route\Strategy;
|
||||
|
||||
use League\Route\Http\Exception\NotFoundException;
|
||||
use Picea\Asset\Asset;
|
||||
use Lean\ApplicationStrategy\NotFoundDecoratorInterface;
|
||||
use Lean\ApplicationStrategy\ThrowableHandlerInterface;
|
||||
use Lean\Factory\HttpFactoryInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Picea\Picea;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use function DI\get;
|
||||
|
||||
class ApplicationStrategy extends Strategy\ApplicationStrategy {
|
||||
|
||||
public const ASSET_TRIGGER_UPDATE = [
|
||||
"js", "mjs", "manifest", "webmanifest", "css", "png", "ico",
|
||||
"jpg", "jpeg", "gif", "webp", "woff", "woff2", "eot", "svg",
|
||||
"ttf"
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
protected Picea $picea,
|
||||
protected ContainerInterface $di,
|
||||
) {}
|
||||
ContainerInterface $di,
|
||||
) {
|
||||
$this->setContainer($di);
|
||||
}
|
||||
|
||||
public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface
|
||||
{
|
||||
return new class($this->picea, $this->di) implements MiddlewareInterface {
|
||||
return $this->getContainer()->get(NotFoundDecoratorInterface::class);
|
||||
}
|
||||
|
||||
public function __construct(
|
||||
protected Picea $picea,
|
||||
protected ContainerInterface $di,
|
||||
) { }
|
||||
public function getThrowableHandler(): MiddlewareInterface
|
||||
{
|
||||
return $this->getContainer()->get(ThrowableHandlerInterface::class);
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if (php_sapi_name() !== 'cli' and ! defined('STDIN')) {
|
||||
return $this->throw404($request);
|
||||
}
|
||||
|
||||
return $handler->handle($request);;
|
||||
}
|
||||
|
||||
public function throw404(ServerRequestInterface $request) : ResponseInterface
|
||||
{
|
||||
if ( getenv('DEBUG') && $this->di->has(\Picea\Asset\Asset::class) ) {
|
||||
$params = $request->getServerParams();
|
||||
|
||||
$scpName = basename(explode('?', $params['REQUEST_URI'] ?? "", 2)[0]);
|
||||
list(, $ext) = array_pad(explode('.', $scpName), 2, null);
|
||||
|
||||
if ($ext && in_array($ext, ApplicationStrategy::ASSET_TRIGGER_UPDATE)) {
|
||||
$this->di->get(\Picea\Asset\Asset::class)->launchInstall();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->di->get('error.404');
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\ApplicationStrategy;
|
||||
|
||||
use DI\Attribute\Inject;
|
||||
use Lean\ApplicationStrategy;
|
||||
use Lean\Factory\HttpFactoryInterface;
|
||||
use Picea\Picea;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
class NotFoundDecorator implements NotFoundDecoratorInterface
|
||||
{
|
||||
#[Inject]
|
||||
protected Picea $picea;
|
||||
|
||||
#[Inject]
|
||||
protected ContainerInterface $container;
|
||||
|
||||
#[Inject]
|
||||
protected HttpFactoryInterface $httpFactory;
|
||||
|
||||
public const ASSET_TRIGGER_UPDATE = [
|
||||
"js", "mjs", "manifest", "webmanifest", "css", "png", "ico",
|
||||
"jpg", "jpeg", "gif", "webp", "woff", "woff2", "eot", "svg",
|
||||
"ttf"
|
||||
];
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if (php_sapi_name() !== 'cli' and ! defined('STDIN')) {
|
||||
return $this->throw404($request);
|
||||
}
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
public function throw404(ServerRequestInterface $request) : ResponseInterface
|
||||
{
|
||||
return $this->checkAssetTrigger($request) ?: $this->httpFactory->createHtmlResponse($this->picea->renderHtml("lean/error/404", [], $this), 404);
|
||||
}
|
||||
|
||||
protected function checkAssetTrigger(ServerRequestInterface $request) : false|ResponseInterface
|
||||
{
|
||||
if (getenv('DEBUG') && $this->container->has(\Picea\Asset\Asset::class)) {
|
||||
$params = $request->getServerParams();
|
||||
|
||||
$scpName = basename(explode('?', $params['REQUEST_URI'] ?? "", 2)[0]);
|
||||
list(, $ext) = array_pad(explode('.', $scpName), 2, null);
|
||||
|
||||
if ($ext && in_array($ext, static::ASSET_TRIGGER_UPDATE)) {
|
||||
$this->container->get(\Picea\Asset\Asset::class)->launchInstall();
|
||||
|
||||
return $this->httpFactory->createTextResponse("Asset updated");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\ApplicationStrategy;
|
||||
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
|
||||
interface NotFoundDecoratorInterface extends MiddlewareInterface
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\ApplicationStrategy;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
class ThrowableHandler implements ThrowableHandlerInterface
|
||||
{
|
||||
public function process(
|
||||
ServerRequestInterface $request,
|
||||
RequestHandlerInterface $handler
|
||||
): ResponseInterface {
|
||||
try {
|
||||
return $handler->handle($request);
|
||||
} catch (Throwable $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\ApplicationStrategy;
|
||||
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
|
||||
interface ThrowableHandlerInterface extends MiddlewareInterface
|
||||
{
|
||||
|
||||
}
|
||||
+11
-9
@@ -20,8 +20,8 @@ use function file_get_contents;
|
||||
#[Route(method: [ "GET", "POST" ])]
|
||||
trait ControllerTrait {
|
||||
|
||||
#[Inject]
|
||||
public \Notes\Breadcrumb\Breadcrumb $breadcrumb;
|
||||
##[Inject]
|
||||
# public \Notes\Breadcrumb\Breadcrumb $breadcrumb;
|
||||
|
||||
#[Inject]
|
||||
public Session $session;
|
||||
@@ -147,13 +147,15 @@ trait ControllerTrait {
|
||||
#[Ignore]
|
||||
public function renderCLI(ServerRequestInterface $request, mixed $data) : ResponseInterface
|
||||
{
|
||||
if ($data instanceof \JsonSerializable ) {
|
||||
return $this->renderJson(
|
||||
$data
|
||||
);
|
||||
}
|
||||
elseif ( is_array($data) ) {
|
||||
var_export($data);
|
||||
if (! $data instanceof \Stringable) {
|
||||
if ($data instanceof \JsonSerializable) {
|
||||
return $this->renderJson(
|
||||
$data
|
||||
);
|
||||
}
|
||||
elseif (is_iterable($data) || is_object($data)) {
|
||||
return $this->renderText(var_export($data, true));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->renderText(
|
||||
|
||||
@@ -6,6 +6,7 @@ use Lean\Routing;
|
||||
use Notes\Route\Attribute\Method\Route;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||
use Ulmus\User\Entity\UserInterface;
|
||||
|
||||
interface RoutingMapRoutes {
|
||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void;
|
||||
|
||||
+4
-1
@@ -73,7 +73,9 @@ class Kernel {
|
||||
$path = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . getenv($envkey);
|
||||
|
||||
if (getenv('DEBUG') && ! file_exists($path)) {
|
||||
mkdir($path, 0755, true);
|
||||
if (false === mkdir($path, 0755, true)) {
|
||||
throw new \Exception(sprintf("Folder '%s' could not be created", $path));
|
||||
}
|
||||
}
|
||||
|
||||
static::putenv($name, realpath($path));
|
||||
@@ -155,6 +157,7 @@ class Kernel {
|
||||
|
||||
# Must be removed from KERNEL !
|
||||
$this->container->has('ulmus.caching') and ( Ulmus::$cache = $this->container->get('ulmus.caching') );
|
||||
# $this->container->has(AdapterProxy::class) and ( $ )
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
+15
-10
@@ -77,37 +77,42 @@ class Lean
|
||||
|
||||
public function getRoutable() : array
|
||||
{
|
||||
return array_merge(...array_map(fn($app) => $app->routes ?? [], $this->applications));
|
||||
return array_merge(...array_map(fn(Application $app) => $app->routes ?? [], $this->applications));
|
||||
}
|
||||
|
||||
public function getCronard() : array
|
||||
{
|
||||
return array_merge(...array_map(fn($app) => $app->cronard ?? [], $this->applications));
|
||||
return array_merge(...array_map(fn(Application $app) => $app->cronard ?? [], $this->applications));
|
||||
}
|
||||
|
||||
public function getCLI() : array
|
||||
{
|
||||
return array_merge(...array_map(fn($app) => $app->cli ?? [], $this->applications));
|
||||
return array_merge(...array_map(fn(Application $app) => $app->cli ?? [], $this->applications));
|
||||
}
|
||||
|
||||
public function getEvents() : array
|
||||
{
|
||||
return array_merge(...array_map(fn($app) => $app->events ?? [], $this->applications));
|
||||
return array_merge(...array_map(fn(Application $app) => $app->events ?? [], $this->applications));
|
||||
}
|
||||
|
||||
public function getTaxusPrivileges() : array
|
||||
{
|
||||
return array_merge(...array_map(fn($app) => $app->taxus ?? [], $this->applications));
|
||||
return array_merge(...array_map(fn(Application $app) => $app->taxus ?? [], $this->applications));
|
||||
}
|
||||
|
||||
public function getEntities() : array
|
||||
{
|
||||
return array_merge(...array_map(fn($app) => $app->entities ?? [], $this->applications));
|
||||
return array_merge(...array_map(fn(Application $app) => $app->entities ?? [], $this->applications));
|
||||
}
|
||||
|
||||
public function getConnectionAdapters() : array
|
||||
{
|
||||
return array_merge(...array_map(fn(Application $app) => $app->connectionAdapters ?? [], $this->applications));
|
||||
}
|
||||
|
||||
public function getViewPaths() : array
|
||||
{
|
||||
$list = array_merge(...array_map(fn($app) => $app->views ?? [], $this->applications));
|
||||
$list = array_merge(...array_map(fn(Application $app) => $app->views ?? [], $this->applications));
|
||||
|
||||
$this->verifyPathList($list);
|
||||
|
||||
@@ -118,7 +123,7 @@ class Lean
|
||||
|
||||
public function getAssetPaths() : array
|
||||
{
|
||||
$list = array_merge(...array_map(fn($app) => $app->piceaAssets ?? [], $this->applications));
|
||||
$list = array_merge(...array_map(fn(Application $app) => $app->piceaAssets ?? [], $this->applications));
|
||||
|
||||
$this->verifyPathList($list);
|
||||
|
||||
@@ -140,11 +145,11 @@ class Lean
|
||||
{
|
||||
switch($reader) {
|
||||
case "php":
|
||||
$list = array_merge(...array_map(fn($app) => $app->tellPhp ?? [], $this->applications));
|
||||
$list = array_merge(...array_map(fn(Application $app) => $app->tellPhp ?? [], $this->applications));
|
||||
break;
|
||||
|
||||
case "json":
|
||||
$list = array_merge(...array_map(fn($app) => $app->tellJson ?? [], $this->applications));
|
||||
$list = array_merge(...array_map(fn(Application $app) => $app->tellJson ?? [], $this->applications));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user