Merge branch 'master' of https://git.mcnd.ca/mcndave/lean
This commit is contained in:
commit
a9db9cd846
20 files changed
+125
-292
No files matched your search
+24
-11
@@ -28,6 +28,8 @@ class Application
|
||||
|
||||
public array $tellPhp;
|
||||
|
||||
public array $taxus;
|
||||
|
||||
public array $data = [];
|
||||
|
||||
public function __construct(string $name) {
|
||||
@@ -38,7 +40,14 @@ class Application
|
||||
{
|
||||
$this->data = array_replace($this->data, $data);
|
||||
|
||||
if (is_array($picea = $data['picea'] ?? false)) {
|
||||
$this->loadData();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function loadData() : static
|
||||
{
|
||||
if (is_array($picea = $this->data['picea'] ?? false)) {
|
||||
if ($picea['context'] ?? false ) {
|
||||
$this->piceaContext = $picea['context'];
|
||||
}
|
||||
@@ -56,13 +65,13 @@ class Application
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($ulmus = $data['ulmus'] ?? false)) {
|
||||
if (is_array($ulmus = $this->data['ulmus'] ?? false)) {
|
||||
if ($ulmus['entities'] ?? false) {
|
||||
$this->entities = $ulmus['entities'];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($tell = $data['tell'] ?? false)) {
|
||||
if (is_array($tell = $this->data['tell'] ?? false)) {
|
||||
if ($tell['json'] ?? false) {
|
||||
$this->tellJson = $tell['json'];
|
||||
}
|
||||
@@ -72,20 +81,24 @@ class Application
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($data['routes'] ?? false)) {
|
||||
$this->routes = $data['routes'];
|
||||
if (is_array($this->data['routes'] ?? false)) {
|
||||
$this->routes = $this->data['routes'];
|
||||
}
|
||||
|
||||
if (is_array($data['cronard'] ?? false)) {
|
||||
$this->cronard = $data['cronard'];
|
||||
if (is_array($this->data['cronard'] ?? false)) {
|
||||
$this->cronard = $this->data['cronard'];
|
||||
}
|
||||
|
||||
if (is_array($data['events'] ?? false)) {
|
||||
$this->events = $data['events'];
|
||||
if (is_array($this->data['events'] ?? false)) {
|
||||
$this->events = $this->data['events'];
|
||||
}
|
||||
|
||||
if (is_array($data['cli'] ?? false)) {
|
||||
$this->cli = $data['cli'];
|
||||
if (is_array($this->data['cli'] ?? false)) {
|
||||
$this->cli = $this->data['cli'];
|
||||
}
|
||||
|
||||
if (is_array($this->data['taxus'] ?? false)) {
|
||||
$this->taxus = $this->data['taxus'];
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -13,8 +13,8 @@ use Psr\Http\Message\{ ServerRequestInterface, ResponseInterface };
|
||||
|
||||
use function file_get_contents;
|
||||
|
||||
#[Security(locked: true)]
|
||||
#[Route(method: [ "GET", "POST", "DELETE" ])]
|
||||
#[Security(locked: true, realm: "Protected Area")]
|
||||
#[Route(method: [ "GET", "POST" ])]
|
||||
trait ControllerTrait {
|
||||
public ? \Notes\Breadcrumb\Breadcrumb $breadcrumb;
|
||||
|
||||
|
||||
@@ -4,10 +4,16 @@ 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;
|
||||
|
||||
class HttpFactory
|
||||
{
|
||||
public static function createResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface
|
||||
{
|
||||
return new Response($url, $code, $headers);
|
||||
}
|
||||
|
||||
public static function createRedirectResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface
|
||||
{
|
||||
return new RedirectResponse($url, $code, $headers);
|
||||
|
||||
+8
-17
@@ -93,6 +93,11 @@ class Lean
|
||||
return array_merge(...array_map(fn($app) => $app->events ?? [], $this->applications));
|
||||
}
|
||||
|
||||
public function getTaxusPrivileges() : array
|
||||
{
|
||||
return array_merge(...array_map(fn($app) => $app->taxus ?? [], $this->applications));
|
||||
}
|
||||
|
||||
public function getEntities() : array
|
||||
{
|
||||
return array_merge(...array_map(fn($app) => $app->entities ?? [], $this->applications));
|
||||
@@ -150,24 +155,10 @@ class Lean
|
||||
return null;
|
||||
}
|
||||
|
||||
#[\Deprecated("Definitions are now loaded automatically from composer extra array.")]
|
||||
public static function definitions() : array
|
||||
{
|
||||
$path = dirname(__DIR__) . "/meta/definitions/";
|
||||
|
||||
return array_merge(
|
||||
require($path . "authorize.php"),
|
||||
class_exists(\Mcnd\CLI\CliMiddleware::class) ? require($path . "cli.php") : [],
|
||||
class_exists(\Cronard\CronardMiddleware::class) ? require($path . "cronard.php") : [],
|
||||
require($path . "email.php"),
|
||||
require($path . "event.php"),
|
||||
require($path . "http.php"),
|
||||
require($path . "language.php"),
|
||||
class_exists(\Negundo\Client\NegundoMiddleware::class) ? require($path . "negundo.php") : [],
|
||||
require($path . "routes.php"),
|
||||
# require($path . "security.php"),
|
||||
require($path . "software.php"),
|
||||
class_exists(\Picea\Picea::class) ? require($path . "template.php") : [],
|
||||
);
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function autoloadDefinitionsFromComposerExtra() : array
|
||||
@@ -218,4 +209,4 @@ class Lean
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-35
@@ -2,9 +2,6 @@
|
||||
|
||||
namespace Lean;
|
||||
|
||||
use Notes\Annotation;
|
||||
use Taxus\Taxus;
|
||||
|
||||
use League\Route\RouteGroup,
|
||||
League\Route\Router;
|
||||
|
||||
@@ -14,55 +11,33 @@ use Psr\Http\Message\ServerRequestInterface,
|
||||
|
||||
use Notes\Route\RouteFetcher;
|
||||
|
||||
use Notes\Security\SecurityHandler;
|
||||
|
||||
use Notes\Tell\LanguageHandler;
|
||||
|
||||
use Picea\Picea,
|
||||
Picea\Extension\UrlExtension;
|
||||
|
||||
use Storage\Cookie,
|
||||
Storage\Session;
|
||||
|
||||
use Mcnd\Event\EventManager;
|
||||
|
||||
use function DI\autowire, DI\create;
|
||||
|
||||
class Routing {
|
||||
|
||||
public Annotation $selectedRoute;
|
||||
|
||||
public ResponseInterface $response;
|
||||
|
||||
public function __construct(
|
||||
public Session $session,
|
||||
public Cookie $cookie,
|
||||
public UrlExtension $extension,
|
||||
public Router $router,
|
||||
public RouteFetcher $fetcher,
|
||||
public SecurityHandler $security,
|
||||
public LanguageHandler $language,
|
||||
public Taxus $taxus,
|
||||
public EventManager $eventManager,
|
||||
) { }
|
||||
|
||||
public function registerRoute(ContainerInterface $container, string $urlBase) {
|
||||
$this->router->group(rtrim($urlBase, "/"), function (RouteGroup $route) use ($container) {
|
||||
foreach($this->fetcher->compile() as $annotation) {
|
||||
$this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $annotation);
|
||||
foreach($this->fetcher->compile() as $attribute) {
|
||||
$this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $attribute);
|
||||
|
||||
/* @deprecated annotation->method will become standard when using native attributes */
|
||||
foreach((array) ( $annotation->method ?? $annotation->methods ) as $method) {
|
||||
# Mapping every URLs from annotations in searched folders (Api, Controller, etc...)
|
||||
$route->map(strtoupper($method), $annotation->getRoute(), function (ServerRequestInterface $request, array $arguments) use (
|
||||
$container, $route, $annotation
|
||||
) : ResponseInterface
|
||||
{
|
||||
$class = $annotation->class;
|
||||
$method = $annotation->classMethod;
|
||||
# Mapping every URLs from attributes in searched folders (Api, Controller, etc...)
|
||||
foreach((array) $attribute->method as $method) {
|
||||
$route->map(strtoupper($method), $attribute->getRoute(), function (ServerRequestInterface $request, array $arguments) use (
|
||||
$container, $route, $attribute
|
||||
) : ResponseInterface {
|
||||
$class = $attribute->class;
|
||||
$method = $attribute->classMethod;
|
||||
$object = $container->get($class);
|
||||
|
||||
$this->eventManager->execute(Event\RoutingMapRoutes::class, $this, $container, $request, $annotation);
|
||||
$this->eventManager->execute(Event\RoutingMapRoutes::class, $this, $container, $request, $attribute);
|
||||
|
||||
$container->set(ServerRequestInterface::class, $request);
|
||||
|
||||
|
||||
Reference in new issue
Block a user