Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7a48d707e0 | ||
|
156defddc9 | ||
|
42f33d9f13 | ||
|
69382f912b |
@ -1,9 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Lean\Factory\HttpFactory;
|
|
||||||
|
|
||||||
use Ulmus\User\{Entity,
|
use Ulmus\User\{Entity,
|
||||||
Lib\Authenticate,
|
Lib\Authenticate,
|
||||||
|
Lib\Authorize,
|
||||||
Middleware\HeaderAuthenticationMiddleware,
|
Middleware\HeaderAuthenticationMiddleware,
|
||||||
Middleware\PostRequestAuthenticationMiddleware,
|
Middleware\PostRequestAuthenticationMiddleware,
|
||||||
Authorize\PostRequestAuthentication};
|
Authorize\PostRequestAuthentication};
|
||||||
@ -12,31 +11,33 @@ use Picea\Picea;
|
|||||||
|
|
||||||
use Storage\{ Cookie, Session };
|
use Storage\{ Cookie, Session };
|
||||||
|
|
||||||
use function DI\{get, autowire, create};
|
use function DI\{get, create};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Authenticate::class => create(Authenticate::class)->constructor(get(Entity\UserInterface::class), get(Session::class), get(Cookie::class), get('authentication.method')),
|
Authenticate::class => create(Authenticate::class)->constructor(get(Entity\UserInterface::class), get(Session::class), get(Cookie::class), get('authentication.method')),
|
||||||
|
|
||||||
HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authorize.error')),
|
Authorize::class => create(Authorize::class)->constructor(get(Entity\UserInterface::class), get(Session::class), get(Cookie::class), get('authentication.method')),
|
||||||
|
|
||||||
PostRequestAuthentication::class => create(PostRequestAuthentication::class)->constructor(get(\Ulmus\User\Lib\Authenticate::class), "email", "email", "password"),
|
HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(Authorize::class), get(Entity\UserInterface::class), get('authorize.error')),
|
||||||
|
|
||||||
|
PostRequestAuthentication::class => create(PostRequestAuthentication::class)->constructor(get(Authenticate::class), "email", "email", "password"),
|
||||||
|
|
||||||
PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authentication.error'), get(PostRequestAuthentication::class)),
|
PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authentication.error'), get(PostRequestAuthentication::class)),
|
||||||
|
|
||||||
'authentication.method' => null,
|
'authentication.method' => null,
|
||||||
|
|
||||||
'authorize.error' => function($c) {
|
'authorize.error' => function($c) {
|
||||||
return function(array $errorData) {
|
return function(array $errorData) use ($c) {
|
||||||
return HttpFactory::createJsonResponse($errorData + [
|
return $c->get(\Lean\Factory\HttpFactoryInterface::class)::createJsonResponse($errorData + [
|
||||||
'api.error' => "Authorization failed",
|
'api.error' => "Authorization failed",
|
||||||
'api.datetime' => (new \DateTime)->format(\DateTime::ISO8601),
|
'api.datetime' => (new \DateTime)->format(\DateTime::ATOM),
|
||||||
], 403);
|
], 403);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
'authentication.error' => function($c, Picea $picea) {
|
'authentication.error' => function($c, Picea $picea) {
|
||||||
return function($message) use ($picea) {
|
return function($message) use ($picea, $c) {
|
||||||
return HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/500', [
|
return $c->get(\Lean\Factory\HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml('lean/error/500', [
|
||||||
'title' => "Authentication failed",
|
'title' => "Authentication failed",
|
||||||
'subtitle' => "",
|
'subtitle' => "",
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Picea\Picea;
|
use Picea\Picea;
|
||||||
use function DI\autowire, DI\create, DI\get;
|
|
||||||
|
|
||||||
use Lean\{ Lean, Routing, Event\RoutingCompileRoutes, Event\RoutingMapRoutes };
|
use Lean\{ Lean, Routing, Event\RoutingCompileRoutes, Event\RoutingMapRoutes };
|
||||||
use Mcnd\Event;
|
use Mcnd\Event;
|
||||||
use Taxus\Taxus;
|
use Taxus\Taxus;
|
||||||
@ -11,6 +9,9 @@ use Notes\Route\Attribute\Method\Route;
|
|||||||
use Notes\Security\SecurityHandler;
|
use Notes\Security\SecurityHandler;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||||
|
use Ulmus\User\Entity\UserInterface;
|
||||||
|
|
||||||
|
use function DI\autowire, DI\create, DI\get;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Event\EventManager::class => autowire(Event\EventManager::class),
|
Event\EventManager::class => autowire(Event\EventManager::class),
|
||||||
@ -25,6 +26,7 @@ return [
|
|||||||
|
|
||||||
Event\EventDefinition::class => function($c) {
|
Event\EventDefinition::class => function($c) {
|
||||||
$extension = $c->has(\Picea\Extension\UrlExtension::class) ? $c->get(\Picea\Extension\UrlExtension::class) : null;
|
$extension = $c->has(\Picea\Extension\UrlExtension::class) ? $c->get(\Picea\Extension\UrlExtension::class) : null;
|
||||||
|
$user = $c->get(UserInterface::class);
|
||||||
|
|
||||||
return new Event\EventDefinition([
|
return new Event\EventDefinition([
|
||||||
new class($extension) implements RoutingCompileRoutes {
|
new class($extension) implements RoutingCompileRoutes {
|
||||||
@ -40,7 +42,12 @@ return [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
new class() implements RoutingMapRoutes {
|
new class($user) implements RoutingMapRoutes {
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected UserInterface $user
|
||||||
|
) {}
|
||||||
|
|
||||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void
|
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void
|
||||||
{
|
{
|
||||||
$class = $attribute->class;
|
$class = $attribute->class;
|
||||||
@ -54,7 +61,7 @@ return [
|
|||||||
$securityHandler = $container->get(SecurityHandler::class);
|
$securityHandler = $container->get(SecurityHandler::class);
|
||||||
|
|
||||||
if ( $redirect = $securityHandler->verify($class, $method) ) {
|
if ( $redirect = $securityHandler->verify($class, $method) ) {
|
||||||
if ( empty($object->user) || ! $object->user->logged ) {
|
if (! $this->user->loggedIn() ) {
|
||||||
if ($container->has(Session::class)) {
|
if ($container->has(Session::class)) {
|
||||||
$container->get(Session::class)->set('redirectedFrom', (string)$request->getUri());
|
$container->get(Session::class)->set('redirectedFrom', (string)$request->getUri());
|
||||||
}
|
}
|
||||||
@ -64,8 +71,8 @@ return [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $securityHandler->isLocked($class, $method) && $container->has(Taxus::class) && $container->has(SecurityHandler::class) ) {
|
if ( $securityHandler->isLocked($class, $method) && $container->has(Taxus::class)) {
|
||||||
if ( $forbidden = $container->get(SecurityHandler::class)->taxus($class, $method, $object->user ?? null) ) {
|
if ( $forbidden = $securityHandler->taxus($class, $method, $this->user) ) {
|
||||||
$routing->response = $forbidden;
|
$routing->response = $forbidden;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Lean\ApplicationStrategy\{ ThrowableHandler, ThrowableHandlerInterface, NotFoundDecoratorInterface, NotFoundDecorator };
|
||||||
use function DI\autowire, DI\create, DI\get;
|
use function DI\autowire, DI\create, DI\get;
|
||||||
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@ -14,4 +15,6 @@ return [
|
|||||||
},
|
},
|
||||||
|
|
||||||
EmitterInterface::class => create(SapiEmitter::class),
|
EmitterInterface::class => create(SapiEmitter::class),
|
||||||
|
ThrowableHandlerInterface::class => autowire(ThrowableHandler::class),
|
||||||
|
NotFoundDecoratorInterface::class => autowire(NotFoundDecorator::class),
|
||||||
];
|
];
|
||||||
|
@ -11,8 +11,12 @@ return [
|
|||||||
]),
|
]),
|
||||||
|
|
||||||
AdapterProxy::class => function (Psr\Container\ContainerInterface $c) {
|
AdapterProxy::class => function (Psr\Container\ContainerInterface $c) {
|
||||||
return new AdapterProxy(
|
$proxy = new AdapterProxy();
|
||||||
$c->get(ConnectionAdapter::class),
|
|
||||||
);
|
$autoload = $c->get(\Lean\Lean::class)->getConnectionAdapters();
|
||||||
|
|
||||||
|
$proxy->push($autoload);
|
||||||
|
|
||||||
|
return $proxy;
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -66,20 +66,14 @@ return [
|
|||||||
'routes' => [],
|
'routes' => [],
|
||||||
|
|
||||||
'cronard' => [],
|
'cronard' => [],
|
||||||
|
|
||||||
'taxus' => [
|
|
||||||
'is_dev' => [ ' dev' => "Is a developper of this application or has the same rights" ],
|
|
||||||
'is_admin' => [ 'admin' => "Can manage almost everything in this application."],
|
|
||||||
'is_moderator' => [ 'moderator' => "Can moderate this application."],
|
|
||||||
'is_user' => [ 'user' => "Is an authenticated user."],
|
|
||||||
'is_anonymous' => [ 'anonymous' => "Is an anonymous user."],
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
|
|
||||||
'lean.autoload' => add([
|
'lean.autoload' => add([
|
||||||
Lean::class,
|
Lean::class,
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
\Lean\Factory\HttpFactoryInterface::class => autowire(\Lean\Factory\HttpFactory::class),
|
||||||
|
|
||||||
Lean::class => autowire(Lean::class),
|
Lean::class => autowire(Lean::class),
|
||||||
|
|
||||||
JavascriptMiddleware::class => create(JavascriptMiddleware::class),
|
JavascriptMiddleware::class => create(JavascriptMiddleware::class),
|
||||||
|
@ -22,6 +22,8 @@ class Application
|
|||||||
|
|
||||||
public array $entities;
|
public array $entities;
|
||||||
|
|
||||||
|
public array $connectionAdapters;
|
||||||
|
|
||||||
public array $events;
|
public array $events;
|
||||||
|
|
||||||
public array $tellJson;
|
public array $tellJson;
|
||||||
@ -68,6 +70,7 @@ class Application
|
|||||||
if (is_array($ulmus = $this->data['ulmus'] ?? false)) {
|
if (is_array($ulmus = $this->data['ulmus'] ?? false)) {
|
||||||
if ($ulmus['entities'] ?? false) {
|
if ($ulmus['entities'] ?? false) {
|
||||||
$this->entities = $ulmus['entities'];
|
$this->entities = $ulmus['entities'];
|
||||||
|
$this->connectionAdapters = $ulmus['adapters'] ?? [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,63 +3,32 @@
|
|||||||
namespace Lean;
|
namespace Lean;
|
||||||
|
|
||||||
use League\Route\Strategy;
|
use League\Route\Strategy;
|
||||||
|
|
||||||
use League\Route\Http\Exception\NotFoundException;
|
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\Container\ContainerInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Server\MiddlewareInterface;
|
use Psr\Http\Server\MiddlewareInterface;
|
||||||
use Picea\Picea;
|
|
||||||
use Psr\Http\Server\RequestHandlerInterface;
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
use function DI\get;
|
use function DI\get;
|
||||||
|
|
||||||
class ApplicationStrategy extends Strategy\ApplicationStrategy {
|
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(
|
public function __construct(
|
||||||
protected Picea $picea,
|
ContainerInterface $di,
|
||||||
protected ContainerInterface $di,
|
) {
|
||||||
) {}
|
$this->setContainer($di);
|
||||||
|
}
|
||||||
|
|
||||||
public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface
|
public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface
|
||||||
{
|
{
|
||||||
return new class($this->picea, $this->di) implements MiddlewareInterface {
|
return $this->getContainer()->get(NotFoundDecoratorInterface::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct(
|
public function getThrowableHandler(): MiddlewareInterface
|
||||||
protected Picea $picea,
|
|
||||||
protected ContainerInterface $di,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
|
||||||
{
|
{
|
||||||
if (php_sapi_name() !== 'cli' and ! defined('STDIN')) {
|
return $this->getContainer()->get(ThrowableHandlerInterface::class);
|
||||||
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 new \Laminas\Diactoros\Response\HtmlResponse($this->picea->renderHtml("lean/error/404", [], $this), 404);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
62
src/ApplicationStrategy/NotFoundDecorator.php
Normal file
62
src/ApplicationStrategy/NotFoundDecorator.php
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
10
src/ApplicationStrategy/NotFoundDecoratorInterface.php
Normal file
10
src/ApplicationStrategy/NotFoundDecoratorInterface.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lean\ApplicationStrategy;
|
||||||
|
|
||||||
|
use Psr\Http\Server\MiddlewareInterface;
|
||||||
|
|
||||||
|
interface NotFoundDecoratorInterface extends MiddlewareInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
22
src/ApplicationStrategy/ThrowableHandler.php
Normal file
22
src/ApplicationStrategy/ThrowableHandler.php
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/ApplicationStrategy/ThrowableHandlerInterface.php
Normal file
10
src/ApplicationStrategy/ThrowableHandlerInterface.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lean\ApplicationStrategy;
|
||||||
|
|
||||||
|
use Psr\Http\Server\MiddlewareInterface;
|
||||||
|
|
||||||
|
interface ThrowableHandlerInterface extends MiddlewareInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -20,8 +20,8 @@ use function file_get_contents;
|
|||||||
#[Route(method: [ "GET", "POST" ])]
|
#[Route(method: [ "GET", "POST" ])]
|
||||||
trait ControllerTrait {
|
trait ControllerTrait {
|
||||||
|
|
||||||
#[Inject]
|
##[Inject]
|
||||||
public \Notes\Breadcrumb\Breadcrumb $breadcrumb;
|
# public \Notes\Breadcrumb\Breadcrumb $breadcrumb;
|
||||||
|
|
||||||
#[Inject]
|
#[Inject]
|
||||||
public Session $session;
|
public Session $session;
|
||||||
@ -147,13 +147,15 @@ trait ControllerTrait {
|
|||||||
#[Ignore]
|
#[Ignore]
|
||||||
public function renderCLI(ServerRequestInterface $request, mixed $data) : ResponseInterface
|
public function renderCLI(ServerRequestInterface $request, mixed $data) : ResponseInterface
|
||||||
{
|
{
|
||||||
if ($data instanceof \JsonSerializable ) {
|
if (! $data instanceof \Stringable) {
|
||||||
|
if ($data instanceof \JsonSerializable) {
|
||||||
return $this->renderJson(
|
return $this->renderJson(
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
elseif ( is_array($data) ) {
|
elseif (is_iterable($data) || is_object($data)) {
|
||||||
var_export($data);
|
return $this->renderText(var_export($data, true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->renderText(
|
return $this->renderText(
|
||||||
|
@ -6,6 +6,7 @@ use Lean\Routing;
|
|||||||
use Notes\Route\Attribute\Method\Route;
|
use Notes\Route\Attribute\Method\Route;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||||
|
use Ulmus\User\Entity\UserInterface;
|
||||||
|
|
||||||
interface RoutingMapRoutes {
|
interface RoutingMapRoutes {
|
||||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void;
|
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void;
|
||||||
|
@ -7,7 +7,7 @@ use Lean\Response\{ DownloadResponse, ImageResponse, FileDownloadResponse, PdfRe
|
|||||||
use Laminas\Diactoros\Response;
|
use Laminas\Diactoros\Response;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
class HttpFactory
|
class HttpFactory implements HttpFactoryInterface
|
||||||
{
|
{
|
||||||
public static function createResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface
|
public static function createResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface
|
||||||
{
|
{
|
||||||
|
22
src/Factory/HttpFactoryInterface.php
Normal file
22
src/Factory/HttpFactoryInterface.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lean\Factory;
|
||||||
|
|
||||||
|
use Laminas\Diactoros\Response\{EmptyResponse, HtmlResponse, JsonResponse, RedirectResponse, TextResponse};
|
||||||
|
use Lean\Response\{ DownloadResponse, ImageResponse, FileDownloadResponse, PdfResponse };
|
||||||
|
use Laminas\Diactoros\Response;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
interface HttpFactoryInterface
|
||||||
|
{
|
||||||
|
public static function createResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface;
|
||||||
|
public static function createRedirectResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface;
|
||||||
|
public static function createHtmlResponse(string $html, int $code = 200, array $headers = []) : ResponseInterface;
|
||||||
|
public static function createTextResponse(string $text, int $code = 200, array $headers = []) : ResponseInterface;
|
||||||
|
public static function createJsonResponse(mixed $data, int $code = 200, array $headers = []) : ResponseInterface;
|
||||||
|
public static function createEmptyResponse(int $code = 204, array $headers = []) : ResponseInterface;
|
||||||
|
public static function createPdfResponse(\Stringable|string $binary, int $code = 200, array $headers = []) : ResponseInterface;
|
||||||
|
public static function createDownloadableResponse(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface;
|
||||||
|
public static function createImageResponse(string $data, int $code = 200, array $headers = []) : ResponseInterface;
|
||||||
|
public static function createFileDownloadResponse(string $path, int $code = 200, array $headers = []) : ResponseInterface;
|
||||||
|
}
|
@ -73,7 +73,9 @@ class Kernel {
|
|||||||
$path = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . getenv($envkey);
|
$path = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . getenv($envkey);
|
||||||
|
|
||||||
if (getenv('DEBUG') && ! file_exists($path)) {
|
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));
|
static::putenv($name, realpath($path));
|
||||||
@ -155,6 +157,7 @@ class Kernel {
|
|||||||
|
|
||||||
# Must be removed from KERNEL !
|
# Must be removed from KERNEL !
|
||||||
$this->container->has('ulmus.caching') and ( Ulmus::$cache = $this->container->get('ulmus.caching') );
|
$this->container->has('ulmus.caching') and ( Ulmus::$cache = $this->container->get('ulmus.caching') );
|
||||||
|
# $this->container->has(AdapterProxy::class) and ( $ )
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
25
src/Lean.php
25
src/Lean.php
@ -77,37 +77,42 @@ class Lean
|
|||||||
|
|
||||||
public function getRoutable() : array
|
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
|
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
|
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
|
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
|
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
|
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
|
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);
|
$this->verifyPathList($list);
|
||||||
|
|
||||||
@ -118,7 +123,7 @@ class Lean
|
|||||||
|
|
||||||
public function getAssetPaths() : array
|
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);
|
$this->verifyPathList($list);
|
||||||
|
|
||||||
@ -140,11 +145,11 @@ class Lean
|
|||||||
{
|
{
|
||||||
switch($reader) {
|
switch($reader) {
|
||||||
case "php":
|
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;
|
break;
|
||||||
|
|
||||||
case "json":
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user