Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f648b47bd | ||
|
|
60d4c7a900 | ||
|
|
2378245dbf | ||
|
|
2cb911ea6f | ||
|
|
16cd95abe2 |
No files matched your search
+25
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mcnd/lean",
|
||||
"description": "A more-than-micro framework for basic apps",
|
||||
"description": "A micro framework for rapid application development (RAD)",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
@@ -24,7 +24,6 @@
|
||||
"guzzlehttp/guzzle": "^7@dev",
|
||||
"swiftmailer/swiftmailer": "^6.2@dev",
|
||||
"mcnd/storage": "dev-master",
|
||||
"mcnd/lean": "dev-master",
|
||||
"mcnd/lean-console": "dev-master",
|
||||
"mcnd/ulmus": "dev-master",
|
||||
"mcnd/picea": "dev-master",
|
||||
@@ -134,5 +133,29 @@
|
||||
"post-update-cmd": [
|
||||
"Lean\\Composer::postUpdate"
|
||||
]
|
||||
},
|
||||
"extra" : {
|
||||
"lean" : {
|
||||
"autoload": {
|
||||
"definitions" : [
|
||||
"meta/definitions/software.php",
|
||||
"meta/definitions/authorize.php",
|
||||
"meta/definitions/cli.php",
|
||||
"meta/definitions/cronard.php",
|
||||
"meta/definitions/email.php",
|
||||
"meta/definitions/event.php",
|
||||
"meta/definitions/http.php",
|
||||
"meta/definitions/language.php",
|
||||
"meta/definitions/negundo.php",
|
||||
"meta/definitions/routes.php",
|
||||
"meta/definitions/software.php",
|
||||
"meta/definitions/storage.php",
|
||||
"meta/definitions/template.php"
|
||||
],
|
||||
"config": [
|
||||
"meta/config.php"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'ulmus' => [
|
||||
'connections' => [
|
||||
'sqlite' => [
|
||||
'adapter' => 'SQLite',
|
||||
'path' => getenv('PROJECT_PATH') . DIRECTORY_SEPARATOR . "var/lean.sqlite3",
|
||||
'pragma_begin' => "journal_mode=WAL",
|
||||
'pragma_close' => "analysis_limit=500,optimize",
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -1,17 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Lean\Factory\HttpFactory;
|
||||
use \Ulmus\User\Middleware\AuthorizeMiddleware;
|
||||
|
||||
use Ulmus\User\{Entity,
|
||||
Lib\Authenticate,
|
||||
Middleware\HeaderAuthenticationMiddleware,
|
||||
Middleware\PostRequestAuthenticationMiddleware,
|
||||
Authorize\PostRequestAuthentication};
|
||||
|
||||
use Picea\Picea;
|
||||
|
||||
use Storage\{ Cookie, Session };
|
||||
|
||||
use function DI\{get, autowire, create};
|
||||
|
||||
return [
|
||||
AuthorizeMiddleware::class => create(AuthorizeMiddleware::class)->constructor(get('authorize.error')),
|
||||
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')),
|
||||
|
||||
PostRequestAuthentication::class => create(PostRequestAuthentication::class)->constructor(get(\Ulmus\User\Lib\Authenticate::class), "email", "email", "password"),
|
||||
|
||||
PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authentication.error'), get(PostRequestAuthentication::class)),
|
||||
|
||||
'authentication.method' => null,
|
||||
|
||||
'authorize.error' => function($c) {
|
||||
return HttpFactory::createJsonResponse([
|
||||
'api.error' => "Authorization failed",
|
||||
'api.datetime' => ( new \DateTime )->format(\DateTime::ATOM),
|
||||
]);
|
||||
return function(array $errorData) {
|
||||
return HttpFactory::createJsonResponse($errorData + [
|
||||
'api.error' => "Authorization failed",
|
||||
'api.datetime' => (new \DateTime)->format(\DateTime::ATOM),
|
||||
]);
|
||||
};
|
||||
},
|
||||
|
||||
'authentication.error' => function($c, Picea $picea) {
|
||||
return function($message) use ($picea) {
|
||||
return HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/500', [
|
||||
'title' => "Authentication failed",
|
||||
'subtitle' => "",
|
||||
'message' => $message,
|
||||
]));
|
||||
};
|
||||
},
|
||||
];
|
||||
@@ -8,7 +8,7 @@ use Mcnd\CLI\CliMiddleware;
|
||||
|
||||
use Notes\CLI\CommandFetcher;
|
||||
|
||||
use Lean\Lean;
|
||||
use Lean\{ Factory, Lean };
|
||||
|
||||
return [
|
||||
CommandFetcher::class => function($c) {
|
||||
@@ -27,7 +27,7 @@ return [
|
||||
|
||||
'cli.response:default' => function($c) {
|
||||
return function() {
|
||||
return new \Laminas\Diactoros\Response\TextResponse("This is the default response from CLI middleware which indicates that no command were registered for this application.\n");
|
||||
return Factory\HttpFactory::createTextResponse("This is the default response from CLI middleware which indicates that no command were registered for this application.\n");
|
||||
};
|
||||
},
|
||||
];
|
||||
@@ -2,19 +2,17 @@
|
||||
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use Laminas\Diactoros\Response\HtmlResponse;
|
||||
|
||||
use Cronard\CronardMiddleware,
|
||||
Notes\Cronard\TaskFetcher;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
use Lean\Lean;
|
||||
use Lean\{ Factory, Lean };
|
||||
|
||||
return [
|
||||
CronardMiddleware::class => function($c) {
|
||||
$cronardMiddleware = new CronardMiddleware($c, getenv('CRON_KEY'), function() : ResponseInterface {
|
||||
return new HtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
|
||||
return Factory\HttpFactory::createHtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
|
||||
}, []);
|
||||
|
||||
return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class));
|
||||
|
||||
@@ -26,7 +26,7 @@ return [
|
||||
Event\EventDefinition::class => function($c) {
|
||||
return new Event\EventDefinition([
|
||||
new class() implements RoutingCompileRoutes {
|
||||
public function execute(Routing $routing, Route|\Notes\Route\Annotation\Method\Route $attribute) : void
|
||||
public function execute(Routing $routing, Route $attribute) : void
|
||||
{
|
||||
if (null !== ($name = $attribute->name ?? null)) {
|
||||
$routing->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, $attribute->methods ?? (array)$attribute->method);
|
||||
@@ -35,7 +35,7 @@ return [
|
||||
},
|
||||
|
||||
new class() implements RoutingMapRoutes {
|
||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route|\Notes\Route\Annotation\Method\Route $attribute) : void
|
||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void
|
||||
{
|
||||
$class = $attribute->class;
|
||||
$method = $attribute->classMethod;
|
||||
|
||||
+11
-16
@@ -3,31 +3,23 @@
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use League\Route\Strategy\ApplicationStrategy,
|
||||
League\Route\Http\Exception\NotFoundException,
|
||||
League\Route\Router;
|
||||
|
||||
use Psr\Http\Message\ResponseFactoryInterface,
|
||||
Psr\Container\ContainerInterface,
|
||||
Psr\Http\Message\ResponseInterface,
|
||||
Psr\Http\Message\ServerRequestInterface,
|
||||
Psr\Http\Server\MiddlewareInterface,
|
||||
Psr\Http\Server\RequestHandlerInterface,
|
||||
Psr\SimpleCache\CacheInterface;
|
||||
|
||||
use TheBugs\JavascriptMiddleware;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
use Cronard\CronardMiddleware;
|
||||
|
||||
use Tuupola\Middleware\HttpBasicAuthentication;
|
||||
|
||||
use Notes\Route\RouteFetcher;
|
||||
|
||||
use Notes\Breadcrumb\Breadcrumb;
|
||||
|
||||
use Ulmus\User\Lib\Authenticate;
|
||||
|
||||
use Storage\SessionMiddleware;
|
||||
|
||||
use Ulmus\User\Middleware\{
|
||||
HeaderAuthenticationMiddleware,
|
||||
PostRequestAuthenticationMiddleware
|
||||
};
|
||||
|
||||
return [
|
||||
Lean\Routing::class => autowire(Lean\Routing::class),
|
||||
|
||||
@@ -57,14 +49,17 @@ return [
|
||||
"dump", "errorHandler", SessionMiddleware::class, CronardMiddleware::class, Mcnd\Event\EventMiddleware::class, Mcnd\CLI\CliMiddleware::class,
|
||||
],
|
||||
|
||||
'app.middlewares' => [],
|
||||
'app.middlewares' => [
|
||||
HeaderAuthenticationMiddleware::class,
|
||||
PostRequestAuthenticationMiddleware::class,
|
||||
],
|
||||
|
||||
'routes.list' => function($c) {
|
||||
return function (ContainerInterface $container) {
|
||||
$router = $container->get(Router::class);
|
||||
|
||||
foreach([ 'routes.middlewares', 'app.middlewares' ] as $key) {
|
||||
if ($container->has('app.middlewares')) {
|
||||
if ( $container->has($key) ) {
|
||||
foreach ($container->get($key) as $i => $middleware) {
|
||||
if ($container->has($middleware)) {
|
||||
$router->middleware($container->get($middleware));
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Taxus\Privilege;
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use Laminas\Diactoros\Response\HtmlResponse;
|
||||
|
||||
use TheBugs\JavascriptMiddleware;
|
||||
|
||||
|
||||
use Cronard\CronardMiddleware,
|
||||
Notes\Cronard\TaskFetcher;
|
||||
|
||||
use Lean\Lean;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
use Storage\Cookie,
|
||||
Storage\Session,
|
||||
Storage\SessionMiddleware;
|
||||
@@ -72,6 +65,13 @@ return [
|
||||
'routes' => [],
|
||||
|
||||
'cronard' => [],
|
||||
|
||||
'taxus' => [
|
||||
[ new Privilege("dev", "Is a developper of this application."), "is_dev" ],
|
||||
[ new Privilege("admin", "Can manage mostly everything from this application."), "is_admin" ],
|
||||
[ new Privilege("user", "Is an authenticated user."), "is_user" ],
|
||||
[ new Privilege("anonymous", "Is an anonymous (unauthenticated) user."), "is_anonymous" ],
|
||||
]
|
||||
],
|
||||
|
||||
Lean::class => autowire(Lean::class),
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
use Ulmus\ConnectionAdapter,
|
||||
Ulmus\Container\AdapterProxy;
|
||||
|
||||
use Storage\Session;
|
||||
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
return [
|
||||
'lean:adapter.sqlite' => function($c) {
|
||||
$adapter = new ConnectionAdapter('sqlite', $c->get('config')['ulmus'], true);
|
||||
$adapter->resolveConfiguration();
|
||||
|
||||
return $adapter;
|
||||
}
|
||||
];
|
||||
@@ -22,29 +22,15 @@ use TheBugs\Email\{ EmailConfiguration, MailerInterface, SwiftMailer };
|
||||
use Taxus\{ Taxus, PermissionGrantInterface };
|
||||
|
||||
return [
|
||||
Entity\User::class => autowire(Entity\User::class),
|
||||
|
||||
Authenticate::class => create(Authenticate::class)->constructor(get(Session::class), get(Cookie::class), get('authentication.method')),
|
||||
\Ulmus\User\Entity\UserInterface::class => autowire(Entity\User::class),
|
||||
|
||||
SecurityHandler::class => create(SecurityHandler::class)->constructor(function() {
|
||||
return new RedirectResponse(getenv("URL_BASE")."/login");
|
||||
return Lean\Factory\HttpFactory::createRedirectResponse(getenv("URL_BASE")."/login");
|
||||
}, get('authentication.unauthorize'), get(Taxus::class)),
|
||||
|
||||
'authentication.method' => null,
|
||||
|
||||
'authentication.error' => function($c, Picea $picea) {
|
||||
return function($message) use ($picea) {
|
||||
return new HtmlResponse($picea->renderHtml('lean/error/500', [
|
||||
'title' => "",
|
||||
'subtitle' => "",
|
||||
'message' => $message,
|
||||
]));
|
||||
};
|
||||
},
|
||||
|
||||
'authentication.unauthorize' => function($c, Picea $picea) {
|
||||
return function($message) use ($picea) {
|
||||
return new HtmlResponse($picea->renderHtml('lean/error/401', [
|
||||
return Lean\Factory\HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/401', [
|
||||
'title' => "",
|
||||
'subtitle' => "",
|
||||
'message' => $message,
|
||||
|
||||
@@ -47,9 +47,11 @@ return array_merge(
|
||||
require("$dir/security.php"),
|
||||
require("$dir/env/" . getenv('APP_ENV') . ".php"),
|
||||
[
|
||||
'config' => function () { return array_replace(
|
||||
require(getenv("META_PATH")."/config.php"),
|
||||
Lean\Lean::autoloadConfigFromComposerExtra(),
|
||||
); }
|
||||
'config' => function () {
|
||||
return array_merge_recursive(
|
||||
Lean\Lean::autoloadConfigFromComposerExtra(),
|
||||
require(getenv("META_PATH")."/config.php")
|
||||
);
|
||||
}
|
||||
]
|
||||
);
|
||||
@@ -5,36 +5,33 @@ namespace %NAMESPACE%\Lib;
|
||||
use Picea\Picea;
|
||||
use Storage\Session;
|
||||
use Ulmus\User\Entity\User;
|
||||
use Ulmus\User\Lib\Authenticate;
|
||||
use Notes\Route\Attribute\Object\Route;
|
||||
use Notes\Security\Attribute\Security;
|
||||
|
||||
use %NAMESPACE%\{ Entity, Lib, Form };
|
||||
|
||||
use Mcnd\Event\EventManager;
|
||||
use Ulmus\User\Entity\UserInterface;
|
||||
|
||||
#[Security(locked: false)]
|
||||
#[Route(method: ['GET', 'POST', ])]
|
||||
trait ControllerTrait {
|
||||
use \Lean\ControllerTrait;
|
||||
|
||||
public ? \Ulmus\User\Entity\User $user;
|
||||
|
||||
protected Authenticate $authenticate;
|
||||
public ? UserInterface $user;
|
||||
|
||||
protected EventManager $eventManager;
|
||||
|
||||
public function __construct(Picea $picea, Session $session, Authenticate $authenticate, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) {
|
||||
$this->initializeController($picea, $session, $authenticate, $breadcrumb, $eventManager);
|
||||
public function __construct(Picea $picea, Session $session, UserInterface $user, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) {
|
||||
$this->initializeController($picea, $session, $user, $breadcrumb, $eventManager);
|
||||
}
|
||||
|
||||
public function initializeController(Picea $picea, Session $session, Authenticate $authenticate, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) {
|
||||
public function initializeController(Picea $picea, Session $session, UserInterface $user, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) {
|
||||
$this->picea = $picea;
|
||||
$this->authenticate = $authenticate;
|
||||
$this->session = $session;
|
||||
$this->eventManager = $eventManager;
|
||||
$this->breadcrumb = $breadcrumb;
|
||||
$this->user = $authenticate->rememberMe( Entity\User::repository() ) ?: new Entity\User();
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Lean;
|
||||
|
||||
|
||||
class Application
|
||||
{
|
||||
public string $name;
|
||||
|
||||
@@ -6,5 +6,5 @@ use Lean\Routing;
|
||||
use Notes\Route\Attribute\Method\Route;
|
||||
|
||||
interface RoutingCompileRoutes {
|
||||
public function execute(Routing $routing, Route|\Notes\Route\Annotation\Method\Route $attribute) : void;
|
||||
public function execute(Routing $routing, Route $attribute) : void;
|
||||
}
|
||||
@@ -8,5 +8,5 @@ use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||
|
||||
interface RoutingMapRoutes {
|
||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route|\Notes\Route\Annotation\Method\Route $attribute) : void;
|
||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void;
|
||||
}
|
||||
@@ -33,9 +33,9 @@ class HttpFactory
|
||||
return new EmptyResponse($code, $headers);
|
||||
}
|
||||
|
||||
public static function createPdfResponse(string $binary, int $code = 200, array $headers = []) : ResponseInterface
|
||||
public static function createPdfResponse(\Stringable $binary, int $code = 200, array $headers = []) : ResponseInterface
|
||||
{
|
||||
return new PdfResponse($binary, $code, $headers);
|
||||
return new PdfResponse((string) $binary, $code, $headers);
|
||||
}
|
||||
|
||||
public static function createDownloadableResponse(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface
|
||||
|
||||
+8
-1
@@ -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));
|
||||
@@ -152,6 +157,8 @@ class Lean
|
||||
|
||||
public static function definitions() : array
|
||||
{
|
||||
return [];
|
||||
|
||||
$path = dirname(__DIR__) . "/meta/definitions/";
|
||||
|
||||
return array_replace(
|
||||
@@ -164,8 +171,8 @@ class Lean
|
||||
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"),
|
||||
require($path . "storage.php"),
|
||||
class_exists(\Picea\Picea::class) ? require($path . "template.php") : [],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user