38 Commits
Author SHA1 Message Date
mcndave 4f648b47bd - quickfix 2023-11-15 19:13:41 -05:00
mcndave 60d4c7a900 - WIP on moving config and definition loading into composer 2023-11-15 19:10:30 -05:00
mcndave 2378245dbf - Removed authentication from controller, now handled by middleware 2023-11-08 06:52:17 -05:00
Dave Mc Nicoll 2cb911ea6f - Fix for HttpFactory (more to come) 2023-11-07 15:02:19 -05:00
mcndave 16cd95abe2 - WIP on adding of HttpFactory and work on authorization from Ulmus/User too 2023-11-03 19:51:39 -04:00
mcndave 1241e188e9 Merge branch 'master' of https://git.mcnd.ca/mcndave/lean 2023-11-03 16:28:52 +00:00
mcndave 08c27e38b0 - Added an HttpFactory and beginning the removal of old annotations from Notes 2023-11-03 16:28:31 +00:00
Dave Mc Nicoll 1a6d730298 - Fixed a bug within extension checking 2023-11-01 11:28:22 -04:00
mcndave 0ad57c87df Merge branch 'master' of https://git.mcnd.ca/mcndave/lean 2023-11-01 09:57:00 -04:00
mcndave 590e9d7631 - Worked i18n dates a bit 2023-11-01 09:56:23 -04:00
mcndave 7e92391113 - Fixed a bug while recovering extension on file having a query 2023-10-31 14:18:28 +00:00
Dave Mc Nicoll 8f0ebfdf80 - Removed getallheaders() polyfill 2023-10-25 14:07:31 +00:00
mcndave 772de0015e - Fixed assets whenever it's not installed 2023-10-18 18:23:58 +00:00
mcndave d8045b5f3c - Fixed assets whenever it's not installed 2023-10-18 18:03:46 +00:00
mcndave bc6880c166 - WIP on Picea's assets 2023-10-17 23:14:59 -04:00
mcndave 4c0cddd617 - Done fixing Container build caching and WIP on Picea's asset 2023-10-17 20:10:42 -04:00
mcndave 4dcc7f407e - WIP on picea-asset AND fixing ApplicationStrategy allowing PHP-DI caching 2023-10-16 13:59:21 -04:00
mcndave 3f92287829 - Merging codes 2023-10-12 18:50:17 +00:00
mcndave 8d22132ef5 - WIP on picea asset 2023-10-12 13:04:58 -04:00
Dave Mc Nicoll 438b5a69c0 - Prepping for Guzzle 7 2023-10-09 14:19:54 -04:00
Dave Mc Nicoll 84b3a16b6e - Prepping for Guzzle 7 2023-10-09 14:05:55 -04:00
Dave Mc Nicoll d30e687e21 Merge branch 'master' of https://git.mcnd.ca/mcndave/lean 2023-10-09 14:02:19 -04:00
Dave Mc Nicoll 4309f46c86 - Migrating to Guzzle 7x 2023-10-09 14:02:08 -04:00
mcndave b6d7e5fad5 - WIP on picea-asset 2023-10-06 19:09:45 -04:00
mcndave 8a5f5f052b - Fixed some bugs within Skeleton's package 2023-09-20 18:42:13 +00:00
mcndave 2e51ff9f4a - WIP on File lib and CLI's definition 2023-09-19 18:54:34 -04:00
Dave Mc Nicoll 777f4af1aa - Defined some packages as optional now 2023-08-21 15:18:39 -04:00
mcndave 09b332bde7 - Removed notes-breadcrumb from requirements 2023-08-21 18:34:33 +00:00
mcndave 41083c767a - Working on CLI modules 2023-07-09 12:37:39 -04:00
Dave Mc Nicoll 52c7407519 Merge branch 'master' of https://git.mcnd.ca/mcndave/lean 2023-05-31 14:41:12 -04:00
Dave Mc Nicoll d402dbeaa0 - Error 500 now throwing the right HTTP code 2023-05-31 14:41:02 -04:00
Dave Mc Nicoll d26a15c0ed - First quickfix of composer again 2023-05-31 18:35:40 +00:00
Dave Mc Nicoll 026a13c766 - First quickfix of composer, more to come 2023-05-31 18:34:16 +00:00
Dave Mc Nicoll 4274a6f4a4 - Removed some outer references 2023-05-31 18:12:38 +00:00
mcndave 4404943f8b Merge branch 'master' of https://git.mcnd.ca/mcndave/lean 2023-05-31 18:11:38 +00:00
mcndave 428e26fbfb - Fixed a redirection-loop 2023-05-31 18:06:19 +00:00
Dave Mc Nicoll e2d2ff72bb Merge branch 'master' of https://git.mcnd.ca/mcndave/lean 2023-05-31 15:54:35 +00:00
Dave Mc Nicoll 94fc8885cf - Switch to Symfony Mailer from SwiftMailer
- Added CSSLSJ new API config
2023-05-31 15:54:06 +00:00
43 changed files with 754 additions and 240 deletions

No files matched your search

+73 -10
View File
@@ -1,6 +1,6 @@
{ {
"name": "mcnd/lean", "name": "mcnd/lean",
"description": "A more-than-micro framework for basic apps", "description": "A micro framework for rapid application development (RAD)",
"type": "library", "type": "library",
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
@@ -10,33 +10,56 @@
} }
], ],
"require": { "require": {
"vlucas/phpdotenv": "^3.4@dev", "php": "^8.2",
"php-di/php-di": "dev-master", "php-di/php-di": "dev-master",
"league/route": "dev-master", "ext-json": "*",
"ext-posix": "*",
"ext-xmlreader": "*",
"ext-fileinfo": "*",
"league/route": "^5.0.0-dev",
"laminas/laminas-diactoros": "2.24.x-dev", "laminas/laminas-diactoros": "2.24.x-dev",
"laminas/laminas-httphandlerrunner": "2.5.x-dev", "laminas/laminas-httphandlerrunner": "2.5.x-dev",
"vlucas/phpdotenv": "^3.4@dev",
"middlewares/whoops": "dev-master",
"guzzlehttp/guzzle": "^7@dev",
"swiftmailer/swiftmailer": "^6.2@dev",
"mcnd/storage": "dev-master", "mcnd/storage": "dev-master",
"mcnd/lean-console": "dev-master",
"mcnd/ulmus": "dev-master", "mcnd/ulmus": "dev-master",
"mcnd/picea": "dev-master", "mcnd/picea": "dev-master",
"mcnd/picea-ui": "dev-master", "mcnd/picea-ui": "dev-master",
"mcnd/cronard": "dev-master", "mcnd/cronard": "dev-master",
"mcnd/tell": "dev-master", "mcnd/tell": "dev-master",
"mcnd/dump": "dev-master", "mcnd/dump": "dev-master",
"mcnd/notes": "dev-master", "mcnd/event": "dev-master",
"mcnd/notes-breadcrumb": "dev-master",
"mcnd/notes-cronard": "dev-master",
"mcnd/notes-event": "dev-master",
"mcnd/notes-tell": "dev-master",
"mcnd/notes-route": "dev-master", "mcnd/notes-route": "dev-master",
"mcnd/notes-security": "dev-master", "mcnd/notes-security": "dev-master",
"mcnd/notes-tell": "dev-master", "mcnd/ulmus-user": "dev-master",
"swiftmailer/swiftmailer": "^6.2@dev", "mcnd/thebugs": "dev-master",
"league/route": "^5.0.0-dev", "mcnd/taxus": "dev-master",
"vlucas/phpdotenv": "^3.4@dev", "psr/simple-cache": "*"
"middlewares/whoops": "dev-master",
"ralouphie/getallheaders": "dev-master"
}, },
"repositories": [ "repositories": [
{
"type": "vcs",
"url": "https://git.mcnd.ca/mcndave/lean-console.git"
},
{ {
"type": "vcs", "type": "vcs",
"url": "https://git.mcnd.ca/mcndave/cronard.git" "url": "https://git.mcnd.ca/mcndave/cronard.git"
}, },
{
"type": "vcs",
"url": "https://git.mcnd.ca/mcndave/event.git"
},
{
"type": "vcs",
"url": "https://git.mcnd.ca/mcndave/the-bugs.git"
},
{ {
"type": "vcs", "type": "vcs",
"url": "https://git.mcnd.ca/mcndave/storage.git" "url": "https://git.mcnd.ca/mcndave/storage.git"
@@ -45,6 +68,10 @@
"type": "vcs", "type": "vcs",
"url": "https://git.mcnd.ca/mcndave/ulmus.git" "url": "https://git.mcnd.ca/mcndave/ulmus.git"
}, },
{
"type": "vcs",
"url": "https://git.mcnd.ca/mcndave/ulmus-user.git"
},
{ {
"type": "vcs", "type": "vcs",
"url": "https://git.mcnd.ca/mcndave/picea.git" "url": "https://git.mcnd.ca/mcndave/picea.git"
@@ -61,10 +88,22 @@
"type": "vcs", "type": "vcs",
"url": "https://git.mcnd.ca/mcndave/notes-route.git" "url": "https://git.mcnd.ca/mcndave/notes-route.git"
}, },
{
"type": "vcs",
"url": "https://git.mcnd.ca/mcndave/notes-cronard.git"
},
{ {
"type": "vcs", "type": "vcs",
"url": "https://git.mcnd.ca/mcndave/notes-security.git" "url": "https://git.mcnd.ca/mcndave/notes-security.git"
}, },
{
"type": "vcs",
"url": "https://git.mcnd.ca/mcndave/notes-breadcrumb.git"
},
{
"type": "vcs",
"url": "https://git.mcnd.ca/mcndave/notes-event.git"
},
{ {
"type": "vcs", "type": "vcs",
"url": "https://git.mcnd.ca/mcndave/notes-tell.git" "url": "https://git.mcnd.ca/mcndave/notes-tell.git"
@@ -94,5 +133,29 @@
"post-update-cmd": [ "post-update-cmd": [
"Lean\\Composer::postUpdate" "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"
]
}
}
} }
} }
+14
View File
@@ -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",
],
],
],
];
+46
View File
@@ -0,0 +1,46 @@
<?php
use Lean\Factory\HttpFactory;
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 [
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 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,
]));
};
},
];
+33
View File
@@ -0,0 +1,33 @@
<?php
use function DI\autowire, DI\create, DI\get;
use Psr\Http\Message\ResponseInterface;
use Mcnd\CLI\CliMiddleware;
use Notes\CLI\CommandFetcher;
use Lean\{ Factory, Lean };
return [
CommandFetcher::class => function($c) {
$fetcher = new CommandFetcher(null, null, $c->get('cli.caching'));
$fetcher->setFolderList(array_map(function($item) {
return $item;
}, $c->get(Lean::class)->getCli()));
return $fetcher;
},
CliMiddleware::class => function($c) {
return new CliMiddleware($c, $c->get('cli.response:default'), $c->get(CommandFetcher::class));
},
'cli.response:default' => function($c) {
return function() {
return Factory\HttpFactory::createTextResponse("This is the default response from CLI middleware which indicates that no command were registered for this application.\n");
};
},
];
+3 -5
View File
@@ -2,20 +2,18 @@
use function DI\autowire, DI\create, DI\get; use function DI\autowire, DI\create, DI\get;
use Laminas\Diactoros\Response\HtmlResponse;
use Cronard\CronardMiddleware, use Cronard\CronardMiddleware,
Notes\Cronard\TaskFetcher; Notes\Cronard\TaskFetcher;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Lean\Lean; use Lean\{ Factory, Lean };
return [ return [
CronardMiddleware::class => function($c) { CronardMiddleware::class => function($c) {
$cronardMiddleware = new CronardMiddleware($c, getenv('CRON_KEY'), function() : ResponseInterface { $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')));
}, [], $c->get(TaskFetcher::class)); }, []);
return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class)); return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class));
}, },
+3 -3
View File
@@ -4,12 +4,12 @@ use function DI\autowire, DI\create, DI\get;
use TheBugs\Email\EmailConfiguration, use TheBugs\Email\EmailConfiguration,
TheBugs\Email\MailerInterface, TheBugs\Email\MailerInterface,
TheBugs\Email\SwiftMailer; TheBugs\Email\SymfonyMailer;
return [ return [
EmailConfiguration::class => function($c) { EmailConfiguration::class => function($c) {
$email = new EmailConfiguration( EmailConfiguration::AUTH_TYPE_SMTP ); $email = new EmailConfiguration( EmailConfiguration::AUTH_TYPE_SMTP );
$email->smtpHost = getenv('SMTP_HOST'); $email->smtpHost = getenv('SMTP_HOSTNAME');
$email->smtpPort = getenv('SMTP_PORT'); $email->smtpPort = getenv('SMTP_PORT');
$email->smtpUsername = getenv('SMTP_USERNAME'); $email->smtpUsername = getenv('SMTP_USERNAME');
$email->smtpPassword = getenv('SMTP_PASSWORD'); $email->smtpPassword = getenv('SMTP_PASSWORD');
@@ -20,5 +20,5 @@ return [
return $email; return $email;
}, },
MailerInterface::class => autowire(SwiftMailer::class), MailerInterface::class => autowire(SymfonyMailer::class),
]; ];
+3 -2
View File
@@ -26,7 +26,7 @@ return [
Event\EventDefinition::class => function($c) { Event\EventDefinition::class => function($c) {
return new Event\EventDefinition([ return new Event\EventDefinition([
new class() implements RoutingCompileRoutes { 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)) { if (null !== ($name = $attribute->name ?? null)) {
$routing->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, $attribute->methods ?? (array)$attribute->method); $routing->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, $attribute->methods ?? (array)$attribute->method);
@@ -35,10 +35,11 @@ return [
}, },
new class() implements RoutingMapRoutes { 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; $class = $attribute->class;
$method = $attribute->classMethod; $method = $attribute->classMethod;
$object = $container->get($class);
$request = $request->withAttribute('lean.route', $attribute); $request = $request->withAttribute('lean.route', $attribute);
+3 -3
View File
@@ -6,7 +6,7 @@ use Negundo\Client\{ SoftwareConfig, Dump, Task, NegundoMiddleware };
return [ return [
SoftwareConfig::class => create(SoftwareConfig::class)->constructor(getenv('NEGUNDO_HASH'), getenv('NEGUNDO_SERVER')), SoftwareConfig::class => create(SoftwareConfig::class)->constructor(getenv('NEGUNDO_HASH'), getenv('NEGUNDO_SERVER')),
# NegundoMiddleware::class => create(NegundoMiddleware::class)->constructor(get(SoftwareConfig::class)), NegundoMiddleware::class => autowire(NegundoMiddleware::class),
Dump::class => create(Dump::class)->constructor(get(SoftwareConfig::class)), Dump::class => autowire(Dump::class),
Task::class => create(Task::class)->constructor(get(SoftwareConfig::class)), Task::class => autowire(Task::class),
]; ];
+21 -47
View File
@@ -3,31 +3,23 @@
use function DI\autowire, DI\create, DI\get; use function DI\autowire, DI\create, DI\get;
use League\Route\Strategy\ApplicationStrategy, use League\Route\Strategy\ApplicationStrategy,
League\Route\Http\Exception\NotFoundException,
League\Route\Router; League\Route\Router;
use Psr\Http\Message\ResponseFactoryInterface, use Psr\Container\ContainerInterface;
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 Cronard\CronardMiddleware; use Cronard\CronardMiddleware;
use Tuupola\Middleware\HttpBasicAuthentication;
use Notes\Route\RouteFetcher; use Notes\Route\RouteFetcher;
use Notes\Breadcrumb\Breadcrumb; use Notes\Breadcrumb\Breadcrumb;
use Ulmus\User\Lib\Authenticate;
use Storage\SessionMiddleware; use Storage\SessionMiddleware;
use Ulmus\User\Middleware\{
HeaderAuthenticationMiddleware,
PostRequestAuthenticationMiddleware
};
return [ return [
Lean\Routing::class => autowire(Lean\Routing::class), Lean\Routing::class => autowire(Lean\Routing::class),
@@ -51,50 +43,32 @@ return [
return $breadcrumb; return $breadcrumb;
}, },
ApplicationStrategy::class => function($c) { ApplicationStrategy::class => autowire(\Lean\ApplicationStrategy::class),
return new class($c->get(Picea\Picea::class)) extends ApplicationStrategy {
public Picea\Picea $picea; 'routes.middlewares' => [
"dump", "errorHandler", SessionMiddleware::class, CronardMiddleware::class, Mcnd\Event\EventMiddleware::class, Mcnd\CLI\CliMiddleware::class,
],
public function __construct(Picea\Picea $picea) { 'app.middlewares' => [
$this->picea = $picea; HeaderAuthenticationMiddleware::class,
} PostRequestAuthenticationMiddleware::class,
],
public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface
{
return new class($this->picea) implements MiddlewareInterface {
protected Picea\Picea $picea;
public function __construct(Picea\Picea $picea) {
$this->picea = $picea;
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
return new Laminas\Diactoros\Response\HtmlResponse($this->picea->renderHtml("lean/error/404", [], $this), 404);
}
};
}
};
},
'routes.middlewares' => [ "dump", "errorHandler", SessionMiddleware::class, CronardMiddleware::class, Mcnd\Event\EventMiddleware::class, HttpBasicAuthentication::class ],
'routes.list' => function($c) { 'routes.list' => function($c) {
return function (ContainerInterface $container) { return function (ContainerInterface $container) {
$router = $container->get(Router::class); $router = $container->get(Router::class);
foreach($container->get('routes.middlewares') as $i => $middleware) { foreach([ 'routes.middlewares', 'app.middlewares' ] as $key) {
if ( $container->has($middleware) ) { if ( $container->has($key) ) {
$router->middleware($container->get($middleware)); foreach ($container->get($key) as $i => $middleware) {
if ($container->has($middleware)) {
$router->middleware($container->get($middleware));
}
}
} }
} }
$routing = $container->get(Lean\Routing::class); $routing = $container->get(Lean\Routing::class);
$routing->registerRoute($container, getenv('URL_BASE')); $routing->registerRoute($container, getenv('URL_BASE'));
return $router; return $router;
+20 -10
View File
@@ -1,22 +1,18 @@
<?php <?php
use Taxus\Privilege;
use function DI\autowire, DI\create, DI\get; use function DI\autowire, DI\create, DI\get;
use Laminas\Diactoros\Response\HtmlResponse;
use TheBugs\JavascriptMiddleware; use TheBugs\JavascriptMiddleware;
use Cronard\CronardMiddleware,
Notes\Cronard\TaskFetcher;
use Lean\Lean; use Lean\Lean;
use Psr\Http\Message\ResponseInterface;
use Storage\Cookie, use Storage\Cookie,
Storage\Session, Storage\Session,
Storage\SessionMiddleware; Storage\SessionMiddleware;
$dir = dirname(__DIR__, 2);
return [ return [
'lean.default' => [ 'lean.default' => [
'picea' => [ 'picea' => [
@@ -28,11 +24,18 @@ return [
'order' => 10, 'order' => 10,
], ],
[ [
'path' => getenv("PROJECT_PATH") . implode(DIRECTORY_SEPARATOR, [ "", "vendor", "mcnd" , "lean" , "view" ]), 'path' => implode(DIRECTORY_SEPARATOR, [ $dir, "view", '' ]),
'order' => 99, 'order' => 99,
], ],
], ],
'asset' => [
[
'path' => implode(DIRECTORY_SEPARATOR, [ getenv("PROJECT_PATH"), "asset", '' ]),
'order' => 10
]
],
'extensions' => [], 'extensions' => [],
], ],
@@ -62,6 +65,13 @@ return [
'routes' => [], 'routes' => [],
'cronard' => [], '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), Lean::class => autowire(Lean::class),
@@ -82,11 +92,11 @@ return [
$gitdir = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . ".git" . DIRECTORY_SEPARATOR; $gitdir = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . ".git" . DIRECTORY_SEPARATOR;
if ( file_exists($gitdir . "HEAD") ) { if ( file_exists($gitdir . "HEAD") ) {
if (false !== ($currentBranch = file_get_contents($gitdir . "HEAD"))) { if (false !== ($currentBranch = file_get_contents($gitdir . "HEAD"))) {
$file = explode(": ", $currentBranch)[1]; $file = explode(": ", $currentBranch)[1];
$path = $gitdir . str_replace("/", DIRECTORY_SEPARATOR, trim($file, " \t\n\r")); $path = $gitdir . str_replace("/", DIRECTORY_SEPARATOR, trim($file, " \t\n\r"));
return trim(file_get_contents($path), " \t\n\r"); return file_exists($path) ? trim(file_get_contents($path), " \t\n\r") : null;
} }
} }
+19
View File
@@ -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;
}
];
+35 -41
View File
@@ -2,23 +2,47 @@
use function DI\autowire, DI\create, DI\get; use function DI\autowire, DI\create, DI\get;
use Laminas\Diactoros\Response\HtmlResponse; use Picea\{
Language\LanguageRegistration,
Caching\Cache,
Caching\Opcache,
Compiler,
Compiler\Context,
Compiler\BaseContext,
FileFetcher,
Method\Request};
use Picea\Extension\{ LanguageHandlerInterface, LanguageExtension, TitleExtension, NumberExtension, UrlExtension };
use Picea\{ Picea, Caching\Cache, Caching\Opcache, Compiler, Compiler\Context, Compiler\BaseContext, FileFetcher, Language\DefaultRegistrations, Method\Request };
use Picea\Extension\{ LanguageHandler, LanguageExtension, TitleExtension, NumberExtension, UrlExtension };
use Picea\Ui\{ Method, Ui }; use Picea\Ui\{ Method, Ui };
return [ return [
Picea::class => function($c) { Picea\Picea::class => function($c) {
return new Picea($c->get(Context::class), $c->get(Cache::class), $c->get(Compiler::class), null, $c->get(FileFetcher::class), null, getenv("DEBUG")); return new Picea\Picea($c->get(Context::class), $c->get(Cache::class), $c->get(Compiler::class), null, $c->get(FileFetcher::class), null, getenv("DEBUG"));
}, },
Context::class => function($c) { Context::class => function($c) {
return new BaseContext( $c->get(Lean\Lean::class)->getPiceaContext() ); return new BaseContext($c->get(Lean\Lean::class)->getPiceaContext());
}, },
Compiler::class => function($c) { Ui::class => autowire(Ui::class),
return new Compiler(new class(array_merge([
Compiler::class => autowire(Compiler::class),
Request::class => autowire(Request::class),
Method\Form::class => autowire(Method\Form::class),
Method\Pagination::class => autowire(Method\Pagination::class),
LanguageExtension::class => create(LanguageExtension::class)->constructor(get(LanguageHandlerInterface::class)),
LanguageHandlerInterface::class => autowire(\Lean\LanguageHandler::class),
LanguageRegistration::class => create(\Lean\PiceaDefaultRegistration::class)->constructor(get('picea.extensions'), [], [], get(Ui::class), null),
'picea.extensions' => function(\Psr\Container\ContainerInterface $c) {
return array_merge([
$c->get(LanguageExtension::class), $c->get(LanguageExtension::class),
$c->get(TitleExtension::class), $c->get(TitleExtension::class),
$c->get(NumberExtension::class), $c->get(NumberExtension::class),
@@ -27,45 +51,15 @@ return [
$c->get(Method\Pagination::class), $c->get(Method\Pagination::class),
$c->get(Request::class), $c->get(Request::class),
], class_exists(\Taxus\Picea\Extension::class) ? [ $c->get(\Taxus\Picea\Extension::class) ] : [], ], class_exists(\Taxus\Picea\Extension::class) ? [ $c->get(\Taxus\Picea\Extension::class) ] : [],
array_map(fn($class) => $c->get($class), $c->get(Lean\Lean::class)->getPiceaExtensions() ))) extends DefaultRegistrations { array_map(fn($class) => $c->get($class), $c->get(Lean\Lean::class)->getPiceaExtensions())
);
public function registerAll(Compiler $compiler) : void
{
parent::registerAll($compiler);
( new Ui() )->registerFormExtension($compiler);
}
});
},
Request::class => autowire(Request::class),
Method\Form::class => autowire(Method\Form::class),
Method\Pagination::class => autowire(Method\Pagination::class),
LanguageExtension::class => create(LanguageExtension::class)->constructor(get(LanguageHandler::class)),
LanguageHandler::class => function($c) {
return new class( $c->get(Tell\I18n::class) ) implements LanguageHandler {
public Tell\I18n $tell;
public function __construct(Tell\I18n $tell) {
$this->tell = $tell;
}
public function languageFromKey(string $key, array $variables = []) #: array|string
{
return $this->tell->fromKey($key, $variables) ?: "";
}
};
}, },
TitleExtension::class => autowire(TitleExtension::class), TitleExtension::class => autowire(TitleExtension::class),
NumberExtension::class => autowire(NumberExtension::class), NumberExtension::class => autowire(NumberExtension::class),
UrlExtension::class => create(UrlExtension::class)->constructor(getenv("URL_BASE"), get('git.commit'), getenv('APP_URL'), (bool) getenv('FORCE_SSL')), UrlExtension::class => create(UrlExtension::class)->constructor(getenv("URL_BASE"), get('git.commit'), explode(',', getenv('APP_URL')), (bool) getenv('FORCE_SSL')),
Cache::class => create(Opcache::class)->constructor(getenv("CACHE_PATH"), get(Context::class)), Cache::class => create(Opcache::class)->constructor(getenv("CACHE_PATH"), get(Context::class)),
+6
View File
@@ -1,4 +1,10 @@
{ {
"moment": {
"today": "today",
"week": "week"
},
"month": { "month": {
"list": [ "list": [
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "Décember" "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "Décember"
+5
View File
@@ -1,4 +1,9 @@
{ {
"moment": {
"today": "aujourd'hui",
"week": "semaine"
},
"month": { "month": {
"list": [ "list": [
"Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"
+4 -13
View File
@@ -1,11 +1,11 @@
APP_ENV = dev APP_ENV = dev
DEBUG = 1 DEBUG = 1
KEYS = "dev:dev" KEYS = "dev"
CRON_KEY = dev CRON_KEY = dev
# Route # Route
URL_BASE = "" URL_BASE = ""
APP_URL = "dev.cslsj.qc.ca" APP_URL = "dev.mcnd.ca"
# Path # Path
CACHE_DIR = "var/cache" CACHE_DIR = "var/cache"
@@ -22,18 +22,9 @@ DEFAULT_LOCAL = "fr_CA.UTF-8"
DEFAULT_TIME = "fr.UTF-8" DEFAULT_TIME = "fr.UTF-8"
DEFAULT_TIME_FALLBACK = "french.UTF-8" DEFAULT_TIME_FALLBACK = "french.UTF-8"
# MS Authentication
# MS_OAUTH_CLIENT_ID = ""
# MS_OAUTH_CLIENT_SECRET = ""
# MS Graph
# MS_GRAPH_CLIENT_ID = ""
# MS_GRAPH_CLIENT_SECRET = ""
# MS_GRAPH_ACCESS_TOKEN_URL = ""
# Database # Database
DATABASE_PORT = "3306" DATABASE_PORT = ""
DATABASE_HOST = "appsdb.cslsj.qc.ca" DATABASE_HOST = ""
DATABASE_NAME = "" DATABASE_NAME = ""
DATABASE_USERNAME = "" DATABASE_USERNAME = ""
DATABASE_PASSWORD = "" DATABASE_PASSWORD = ""
Executable
+9
View File
@@ -0,0 +1,9 @@
#!/bin/php
<?php
try {
require_once(__DIR__."/src/Kernel.php");
}
catch(\Throwable $t) {
echo sprintf("%s [ %s ]" , $t->getMessage(), var_export($t->getTrace(), true));
}
+12
View File
@@ -30,6 +30,18 @@ return [
'charset' => getenv("DATABASE_CHARSET"), 'charset' => getenv("DATABASE_CHARSET"),
], ],
], ],
'sqlite' => [
'adapter' => getenv("SQLITE_ADAPTER"),
'path' => getenv('PROJECT_PATH') . DIRECTORY_SEPARATOR . getenv("SQLITE_PATH"),
'pragma' => explode(',', getenv("SQLITE_PRAGMA")),
'pragma_begin' => array_merge(
explode(',', getenv("SQLITE_PRAGMA_BEGIN")), explode(',', getenv('DEBUG') ? getenv("SQLITE_PRAGMA_DEBUG_BEGIN") : "")
),
'pragma_close' => array_merge(
explode(',', getenv("SQLITE_PRAGMA_CLOSE")), explode(',', getenv('DEBUG') ? getenv("SQLITE_PRAGMA_DEBUG_CLOSE") : "")
),
],
] ]
] ]
]; ];
+4 -18
View File
@@ -22,27 +22,15 @@ use TheBugs\Email\{ EmailConfiguration, MailerInterface, SwiftMailer };
use Taxus\{ Taxus, PermissionGrantInterface }; use Taxus\{ Taxus, PermissionGrantInterface };
return [ return [
Entity\User::class => autowire(Entity\User::class), \Ulmus\User\Entity\UserInterface::class => autowire(Entity\User::class),
Authenticate::class => create(Authenticate::class)->constructor(get(Session::class), get(Cookie::class), get('authentication.method')),
SecurityHandler::class => create(SecurityHandler::class)->constructor(function() { 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)), }, get('authentication.unauthorize'), get(Taxus::class)),
'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) { 'authentication.unauthorize' => function($c, Picea $picea) {
return function($message) use ($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' => "", 'title' => "",
'subtitle' => "", 'subtitle' => "",
'message' => $message, 'message' => $message,
@@ -52,7 +40,7 @@ return [
EmailConfiguration::class => function($c) { EmailConfiguration::class => function($c) {
$email = new EmailConfiguration( EmailConfiguration::AUTH_TYPE_SMTP ); $email = new EmailConfiguration( EmailConfiguration::AUTH_TYPE_SMTP );
$email->smtpHost = getenv('SMTP_HOST'); $email->smtpHost = getenv('SMTP_HOSTNAME');
$email->smtpPort = getenv('SMTP_PORT'); $email->smtpPort = getenv('SMTP_PORT');
$email->smtpUsername = getenv('SMTP_USERNAME'); $email->smtpUsername = getenv('SMTP_USERNAME');
$email->smtpPassword = getenv('SMTP_PASSWORD'); $email->smtpPassword = getenv('SMTP_PASSWORD');
@@ -63,6 +51,4 @@ return [
return $email; return $email;
}, },
PermissionGrantInterface::class => create(%NAMESPACE%\PrivilegeGrantAccess::class)->constructor(get(ServerRequestInterface::class), get(Session::class)),
]; ];
+17 -5
View File
@@ -7,15 +7,14 @@ $dir = getenv("META_PATH") . "/definitions";
return array_merge( return array_merge(
Lean\Lean::definitions(), Lean\Lean::definitions(),
Lean\Console\Lean::definitions(), Lean\Lean::autoloadDefinitionsFromComposerExtra(),
[ [
'%APPKEY%' => [ '%APPKEY%' => [
'picea' => [ 'picea' => [
'context' => "%ESCAPED_NAMESPACE%\\View", 'context' => "%ESCAPED_NAMESPACE%\\View",
'asset' => [],
'extensions' => [ 'extensions' => [],
],
], ],
@@ -34,12 +33,25 @@ return array_merge(
'cronard' => [ 'cronard' => [
'%ESCAPED_NAMESPACE%\\Controller' => implode(DIRECTORY_SEPARATOR, [ getenv("PROJECT_PATH"), 'src', 'Controller', '' ]), '%ESCAPED_NAMESPACE%\\Controller' => implode(DIRECTORY_SEPARATOR, [ getenv("PROJECT_PATH"), 'src', 'Controller', '' ]),
], ],
'cli' => [
'%ESCAPED_NAMESPACE%\\Controller' => implode(DIRECTORY_SEPARATOR, [ getenv("PROJECT_PATH"), 'src', 'Controller', '' ]),
],
], ],
'app.middlewares' => [],
], ],
require("$dir/auth.php"), require("$dir/auth.php"),
require("$dir/storage.php"), require("$dir/storage.php"),
require("$dir/security.php"), require("$dir/security.php"),
require("$dir/env/" . getenv('APP_ENV') . ".php"), require("$dir/env/" . getenv('APP_ENV') . ".php"),
[ 'config' => function () { return require(getenv("META_PATH")."/config.php"); } ] [
'config' => function () {
return array_merge_recursive(
Lean\Lean::autoloadConfigFromComposerExtra(),
require(getenv("META_PATH")."/config.php")
);
}
]
); );
+2 -1
View File
@@ -15,5 +15,6 @@ return [
'breadcrumbs.caching' => create(Kash\ArrayCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.breadcrumbs", 30), 'breadcrumbs.caching' => create(Kash\ArrayCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.breadcrumbs", 30),
'ulmus.caching' => create(Kash\ArrayCache::class)->constructor( get(Kash\CacheInvalidator::class), "ulmus.entities", 30), 'ulmus.caching' => create(Kash\ArrayCache::class)->constructor( get(Kash\CacheInvalidator::class), "ulmus.entities", 30),
'cronard.caching' => create(Kash\ArrayCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.cronards", 30), 'cronard.caching' => create(Kash\ArrayCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.cronards", 30),
'events.caching' => create(Kash\ArrayCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.events", random_int(3600, 7200)), 'events.caching' => create(Kash\ArrayCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.events", 30),
'cli.caching' => create(Kash\ArrayCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.cli", 30),
]; ];
+2 -1
View File
@@ -40,7 +40,7 @@ return [
'subtitle' => "Êtes-vous connecté avec le bon compte ?", 'subtitle' => "Êtes-vous connecté avec le bon compte ?",
'message' => $exception->getMessage(), 'message' => $exception->getMessage(),
'exception' => $exception, 'exception' => $exception,
])); ]), 500);
}; };
}, },
@@ -49,4 +49,5 @@ return [
'ulmus.caching' => create(Kash\ApcuCache::class)->constructor( get(Kash\CacheInvalidator::class), "ulmus.entities", random_int(3600, 7200)), 'ulmus.caching' => create(Kash\ApcuCache::class)->constructor( get(Kash\CacheInvalidator::class), "ulmus.entities", random_int(3600, 7200)),
'cronard.caching' => create(Kash\ApcuCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.cronards", random_int(3600, 7200)), 'cronard.caching' => create(Kash\ApcuCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.cronards", random_int(3600, 7200)),
'events.caching' => create(Kash\ApcuCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.events", random_int(3600, 7200)), 'events.caching' => create(Kash\ApcuCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.events", random_int(3600, 7200)),
'cli.caching' => create(Kash\ApcuCache::class)->constructor( get(Kash\CacheInvalidator::class), "lean.cli", random_int(3600, 7200)),
]; ];
+3 -3
View File
@@ -1,13 +1,13 @@
<?php <?php
use function DI\autowire, DI\create, DI\get;
use Storage\Session; use Storage\Session;
use Taxus\{ Privilege, Taxus, PermissionGrantInterface, DefaultPermissionGrant }; use Taxus\{ Privilege, Taxus, PermissionGrantInterface, DefaultPermissionGrant };
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use function DI\autowire, DI\create, DI\get;
return [ return [
Taxus::class => function ($c) { Taxus::class => function ($c) {
return ( new Taxus( $c->get(PermissionGrantInterface::class) ) )->add( return ( new Taxus( $c->get(PermissionGrantInterface::class) ) )->add(
@@ -18,5 +18,5 @@ return [
); );
}, },
PermissionGrantInterface::class => create(DefaultPermissionGrant::class)->constructor(get(ServerRequestInterface::class), get(Session::class)), PermissionGrantInterface::class => create(%NAMESPACE%\PrivilegeGrantAccess::class)->constructor(get(ServerRequestInterface::class), get(Session::class)),
]; ];
-2
View File
@@ -14,8 +14,6 @@ return [
$adapter = new ConnectionAdapter('default', $c->get('config')['ulmus'], true); $adapter = new ConnectionAdapter('default', $c->get('config')['ulmus'], true);
$adapter->resolveConfiguration(); $adapter->resolveConfiguration();
$adapter->connect();
return $adapter; return $adapter;
}, },
+2 -1
View File
@@ -4,11 +4,12 @@ namespace %NAMESPACE%\Controller;
use Psr\Http\Message\{ServerRequestInterface, ResponseInterface }; use Psr\Http\Message\{ServerRequestInterface, ResponseInterface };
use Notes\Route\Attribute\Method\Route;
use %NAMESPACE%\{ Lib, Entity, Form, }; use %NAMESPACE%\{ Lib, Entity, Form, };
use function %NAMESPACE%\View\{ _, lang, url, route, form }; use function %NAMESPACE%\View\{ _, lang, url, route, form };
#[Language("%APPKEY%.home")]
class Home { class Home {
use Lib\ControllerTrait; use Lib\ControllerTrait;
+1 -1
View File
@@ -3,7 +3,7 @@
namespace %NAMESPACE%\Entity; namespace %NAMESPACE%\Entity;
use Ulmus\Entity\Field\Datetime; use Ulmus\Entity\Field\Datetime;
use Ulmus\{Attribute\Obj\Table; use Ulmus\{Attribute\Obj\Table};
use %NAMESPACE%\Lib; use %NAMESPACE%\Lib;
+8 -10
View File
@@ -5,35 +5,33 @@ namespace %NAMESPACE%\Lib;
use Picea\Picea; use Picea\Picea;
use Storage\Session; use Storage\Session;
use Ulmus\User\Entity\User; use Ulmus\User\Entity\User;
use Ulmus\User\Lib\Authenticate;
use Notes\Route\Attribute\Object\Route; use Notes\Route\Attribute\Object\Route;
use Notes\Security\Attribute\Security; use Notes\Security\Attribute\Security;
use %NAMESPACE%\Entity;
use %NAMESPACE%\{ Entity, Lib, Form };
use Mcnd\Event\EventManager; use Mcnd\Event\EventManager;
use Ulmus\User\Entity\UserInterface;
#[Security(locked: false)] #[Security(locked: false)]
#[Route(method: ['GET', 'POST', ])] #[Route(method: ['GET', 'POST', ])]
trait ControllerTrait { trait ControllerTrait {
use \Lean\ControllerTrait; use \Lean\ControllerTrait;
public ? \Ulmus\User\Entity\User $user; public ? UserInterface $user;
protected Authenticate $authenticate;
protected EventManager $eventManager; protected EventManager $eventManager;
public function __construct(Picea $picea, Session $session, Authenticate $authenticate, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) { public function __construct(Picea $picea, Session $session, UserInterface $user, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) {
$this->initializeController($picea, $session, $authenticate, $breadcrumb, $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->picea = $picea;
$this->authenticate = $authenticate;
$this->session = $session; $this->session = $session;
$this->eventManager = $eventManager; $this->eventManager = $eventManager;
$this->breadcrumb = $breadcrumb; $this->breadcrumb = $breadcrumb;
$this->user = $authenticate->rememberMe( Entity\User::repository() ) ?: new Entity\User(); $this->user = $user;
} }
} }
+2 -10
View File
@@ -2,11 +2,8 @@
namespace %NAMESPACE%\Middleware; namespace %NAMESPACE%\Middleware;
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\{ RequestHandlerInterface, MiddlewareInterface };
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ResponseInterface;
use Storage\Session; use Storage\Session;
class Authentication implements MiddlewareInterface { class Authentication implements MiddlewareInterface {
@@ -23,9 +20,6 @@ class Authentication implements MiddlewareInterface {
$this->session = $session; $this->session = $session;
} }
#[param ServerRequestInterface $request]
#[param RequestHandlerInterface $handler]
#[return ResponseInterface]
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
{ {
$user = $this->session->get( $this->sessionUserVariable() ); $user = $this->session->get( $this->sessionUserVariable() );
@@ -37,8 +31,6 @@ class Authentication implements MiddlewareInterface {
return $handler->handle($request); return $handler->handle($request);
} }
#[param string|null sessionUserVariable]
#[return mixed]
public function sessionUserVariable(?string $set = null) : string public function sessionUserVariable(?string $set = null) : string
{ {
return $set !== null ? $this->sessionUserVariable = $set : $this->sessionUserVariable; return $set !== null ? $this->sessionUserVariable = $set : $this->sessionUserVariable;
+1 -1
View File
@@ -25,7 +25,7 @@ class PrivilegeGrantAccess implements PermissionGrantInterface {
*/ */
public function is_dev() : bool public function is_dev() : bool
{ {
return false; return getenv('DEBUG');
} }
public function is_admin(User $user) : bool public function is_admin(User $user) : bool
-1
View File
@@ -5,7 +5,6 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>{% section "head.title" %}{{ title() }} — {{ lang('application_name') }}{% endsection %}</title> <title>{% section "head.title" %}{{ title() }} — {{ lang('application_name') }}{% endsection %}</title>
</style>
</head> </head>
{% endsection %} {% endsection %}
+4
View File
@@ -6,4 +6,8 @@
<div class="main"> <div class="main">
Hello World :) ! Hello World :) !
</div> </div>
<div>
<a href="{% route 'lean.console:home' %}">Accéder à la console LEAN</a>
</div>
{% endsection %} {% endsection %}
+13 -2
View File
@@ -1,9 +1,7 @@
<?php <?php
namespace Lean; namespace Lean;
class Application class Application
{ {
public string $name; public string $name;
@@ -12,10 +10,14 @@ class Application
public array $piceaExtensions; public array $piceaExtensions;
public array $piceaAssets;
public array $views; public array $views;
public array $routes; public array $routes;
public array $cli;
public array $cronard; public array $cronard;
public array $entities; public array $entities;
@@ -45,6 +47,10 @@ class Application
$this->piceaExtensions = $picea['extensions']; $this->piceaExtensions = $picea['extensions'];
} }
if ($picea['asset'] ?? false ) {
$this->piceaAssets = $picea['asset'];
}
if ($picea['view'] ?? false) { if ($picea['view'] ?? false) {
$this->views = $picea['view']; $this->views = $picea['view'];
} }
@@ -73,10 +79,15 @@ class Application
if (is_array($data['cronard'] ?? false)) { if (is_array($data['cronard'] ?? false)) {
$this->cronard = $data['cronard']; $this->cronard = $data['cronard'];
} }
if (is_array($data['events'] ?? false)) { if (is_array($data['events'] ?? false)) {
$this->events = $data['events']; $this->events = $data['events'];
} }
if (is_array($data['cli'] ?? false)) {
$this->cli = $data['cli'];
}
return $this; return $this;
} }
} }
+61
View File
@@ -0,0 +1,61 @@
<?php
namespace Lean;
use League\Route\Strategy;
use League\Route\Http\Exception\NotFoundException;
use Picea\Asset\Asset;
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,
) {}
public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface
{
return new class($this->picea, $this->di) implements MiddlewareInterface {
public function __construct(
protected Picea $picea,
protected ContainerInterface $di,
) { }
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
return $this->throw404($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);
}
};
}
}
+27 -4
View File
@@ -69,18 +69,41 @@ class Composer
new CacheInvalidator($path, true); new CacheInvalidator($path, true);
} }
if ( file_exists($container = static::createPath('var/cache/di/CompiledContainer.php')) ) {
unlink($container);
}
} }
protected static function readComposerJson(Event $event) : ? array public static function readComposerLock() : false|array
{ {
static $content = null;
$path = static::createPath('composer.lock');
if (! file_exists($path) ) {
throw new \UnexpectedValueException("Composer file 'composer.lock' could not be found within your project's root folder.");
}
return $content ??= file_exists($path) ? json_decode(file_get_contents($path), true) : false;
}
public static function readComposerJson() : false|array
{
static $content = null;
$path = static::createPath('composer.json'); $path = static::createPath('composer.json');
return file_exists($path) ? json_decode(file_get_contents($path), true) : null; if (! file_exists($path) ) {
throw new \UnexpectedValueException("Composer file 'composer.json' could not be found within your project's root folder.");
}
return $content ??= file_exists($path) ? json_decode(file_get_contents($path), true) : false;
} }
protected static function getNamespaceFromAutoload(Event $event) : ? string protected static function getNamespaceFromAutoload(Event $event) : ? string
{ {
if ( null !== $composerJson = static::readComposerJson($event) ) { if ( false !== $composerJson = static::readComposerJson() ) {
if ( $psr4 = $composerJson['autoload']['psr-4'] ?? false ) { if ( $psr4 = $composerJson['autoload']['psr-4'] ?? false ) {
foreach($psr4 as $ns => $directory) { foreach($psr4 as $ns => $directory) {
if ($directory === 'src/') { if ($directory === 'src/') {
@@ -103,6 +126,6 @@ class Composer
protected static function createPath(... $path) : string protected static function createPath(... $path) : string
{ {
return implode(DIRECTORY_SEPARATOR, array_merge([ $_SERVER['PWD'] ], $path)); return implode(DIRECTORY_SEPARATOR, array_merge([ $_SERVER['PWD'] ?? getenv('PROJECT_PATH') ], $path));
} }
} }
+51 -34
View File
@@ -2,33 +2,19 @@
namespace Lean; namespace Lean;
use Lean\Response\{FileDownloadResponse, PdfResponse, ImageResponse, DownloadResponse}; use Lean\Factory\HttpFactory;
use Notes\Route\Attribute\Object\Route;
use Picea, use Notes\Security\Attribute\Security;
Picea\Ui\Method\FormContext; use Picea, Picea\Ui\Method\FormContext;
use Psr\Http\Message\ServerRequestInterface;
use Storage\Session;
use Laminas\Diactoros\Response\{EmptyResponse, HtmlResponse, TextResponse, RedirectResponse, JsonResponse};
use Ulmus\EntityCollection;
use Psr\Http\Message\ResponseInterface;
use TheBugs\Email\MailerInterface; use TheBugs\Email\MailerInterface;
use Storage\Session;
use Notes\Cronard\Annotation\Method\Cronard, use Psr\Http\Message\{ ServerRequestInterface, ResponseInterface };
Notes\Breadcrumb\Annotation\Method\Breadcrumb,
Notes\Route\Annotation\Object\Route as RouteParam,
Notes\Route\Annotation\Method\Route,
Notes\Security\Annotation\Security,
Notes\Security\Annotation\Taxus,
Notes\Tell\Annotation\Language;
use function file_get_contents; use function file_get_contents;
#[\Notes\Security\Attribute\Security(locked: true)] #[Security(locked: true)]
#[\Notes\Route\Attribute\Object\Route(method: [ "GET", "POST", "DELETE" ])] #[Route(method: [ "GET", "POST", "DELETE" ])]
trait ControllerTrait { trait ControllerTrait {
public ? \Notes\Breadcrumb\Breadcrumb $breadcrumb; public ? \Notes\Breadcrumb\Breadcrumb $breadcrumb;
@@ -51,7 +37,11 @@ trait ControllerTrait {
public function renderRawView(string $view, ?array $variables = null) : string public function renderRawView(string $view, ?array $variables = null) : string
{ {
return $this->picea->renderHtml($view, $variables ?? [], $this); if ( null === $content = $this->picea->renderHtml($view, $variables ?? [], $this) ) {
throw new \RuntimeException("Picea's renderHtml() returned NULL as result ; an error occurred within your template `$view`.");
}
return $content;
} }
public function renderView(string $view, ?array $variables = null) : ResponseInterface public function renderView(string $view, ?array $variables = null) : ResponseInterface
@@ -74,47 +64,74 @@ trait ControllerTrait {
} }
protected function redirect(string $url, int $code = 302, array $headers = []) { protected function redirect(string $url, int $code = 302, array $headers = []) {
return new RedirectResponse($url, $code, $headers); return HttpFactory::createRedirectResponse($url, $code, $headers);
} }
public static function renderNothing(int $code = 204, array $headers = []) : ResponseInterface public static function renderNothing(int $code = 204, array $headers = []) : ResponseInterface
{ {
return new EmptyResponse($code, $headers); return HttpFactory::createEmptyResponse($code, $headers);
} }
public static function renderText(string $html, int $code = 200, array $headers = []) : ResponseInterface public static function renderText(string $text, int $code = 200, array $headers = []) : ResponseInterface
{ {
return new TextResponse($html, $code, $headers); return HttpFactory::createTextResponse($text, $code, $headers);
} }
public static function renderHtml(string $html, int $code = 200, array $headers = []) : ResponseInterface public static function renderHtml(string $html, int $code = 200, array $headers = []) : ResponseInterface
{ {
return new HtmlResponse($html, $code, $headers); return HttpFactory::createHtmlResponse($html, $code, $headers);
} }
public static function renderJson(mixed $data, int $code = 200, array $headers = []) : ResponseInterface public static function renderJson(mixed $data, int $code = 200, array $headers = []) : ResponseInterface
{ {
return new JsonResponse($data, $code, $headers); return HttpFactory::createJsonResponse($data, $code, $headers);
} }
public function renderPdf($rawdata, int $status = 200, array $headers = []) : PdfResponse public function renderPdf($rawdata, int $status = 200, array $headers = []) : ResponseInterface
{ {
return new PdfResponse($rawdata, $status, $headers); return HttpFactory::createPdfResponse($rawdata, $status, $headers);
} }
public static function renderDownloadable(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface public static function renderDownloadable(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface
{ {
return new DownloadResponse($data, $filename, $code, $headers); return HttpFactory::createDownloadableResponse($data, $filename, $code, $headers);
} }
public static function renderImage(string $data, int $code = 200, array $headers = []) : ResponseInterface public static function renderImage(string $data, int $code = 200, array $headers = []) : ResponseInterface
{ {
return new ImageResponse($data, $code, $headers); return HttpFactory::createImageResponse($data, $code, $headers);
} }
public static function renderAsset(string $path, int $code = 200, array $headers = []) : ResponseInterface public static function renderAsset(string $path, int $code = 200, array $headers = []) : ResponseInterface
{ {
return new FileDownloadResponse($path, $code, $headers); return HttpFactory::createFileDownloadResponse($path, $code, $headers);
}
public function renderMarkdown(string $filepath, int $code = 200, array $headers = []) : ResponseInterface
{
if ( ! class_exists(CommonMarkConverter::class)) {
throw new \BadFunctionCallException("League\CommonMark seems to be missing, please install dependency before trying to render Markdown content");
}
$markdown = ( new CommonMarkConverter() )->convertToHtml(file_get_contents($filepath));
return $this->renderView("docs", get_defined_vars());
}
public function renderCLI(ServerRequestInterface $request, mixed $data) : ResponseInterface
{
if ($data instanceof \JsonSerializable ) {
return $this->renderJson(
$data
);
}
elseif ( is_array($data) ) {
var_export($data);
}
return $this->renderText(
$data . PHP_EOL
);
} }
public function fromResponse(ResponseInterface $response) public function fromResponse(ResponseInterface $response)
+1 -1
View File
@@ -6,5 +6,5 @@ use Lean\Routing;
use Notes\Route\Attribute\Method\Route; use Notes\Route\Attribute\Method\Route;
interface RoutingCompileRoutes { interface RoutingCompileRoutes {
public function execute(Routing $routing, Route|\Notes\Route\Annotation\Method\Route $attribute) : void; public function execute(Routing $routing, Route $attribute) : void;
} }
+1 -1
View File
@@ -8,5 +8,5 @@ use Psr\Container\ContainerInterface;
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface }; use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
interface RoutingMapRoutes { 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;
} }
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace Lean\Factory;
use Laminas\Diactoros\Response\{EmptyResponse, HtmlResponse, JsonResponse, RedirectResponse, TextResponse};
use Lean\Response\{ DownloadResponse, ImageResponse, FileDownloadResponse, PdfResponse };
use Psr\Http\Message\ResponseInterface;
class HttpFactory
{
public static function createRedirectResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface
{
return new RedirectResponse($url, $code, $headers);
}
public static function createHtmlResponse(string $html, int $code = 200, array $headers = []) : ResponseInterface
{
return new HtmlResponse($html, $code, $headers);
}
public static function createTextResponse(string $text, int $code = 200, array $headers = []) : ResponseInterface
{
return new TextResponse($text, $code, $headers);
}
public static function createJsonResponse(mixed $data, int $code = 200, array $headers = []) : ResponseInterface
{
return new JsonResponse($data, $code, $headers);
}
public static function createEmptyResponse(int $code = 204, array $headers = []) : ResponseInterface
{
return new EmptyResponse($code, $headers);
}
public static function createPdfResponse(\Stringable $binary, int $code = 200, array $headers = []) : ResponseInterface
{
return new PdfResponse((string) $binary, $code, $headers);
}
public static function createDownloadableResponse(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface
{
return new DownloadResponse($data, $filename, $code, $headers);
}
public static function createImageResponse(string $data, int $code = 200, array $headers = []) : ResponseInterface
{
return new ImageResponse($data, $code, $headers);
}
public static function createFileDownloadResponse(string $path, int $code = 200, array $headers = []) : ResponseInterface
{
return new FileDownloadResponse($path, $code, $headers);
}
}
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace Lean;
class File
{
public static function tail(string $path, int $lines = 10) : false|array
{
$handle = fopen($path, "r");
$counter = $lines;
$pos = -2;
$beginning = false;
$text = array();
while ($counter && ! $beginning) {
$t = "";
while ($t !== PHP_EOL) {
if(fseek($handle, $pos, SEEK_END) == -1) {
$beginning = true;
break;
}
$t = fgetc($handle);
$pos --;
}
$counter --;
if ($beginning) {
rewind($handle);
}
$text[$lines - $counter - 1] = fgets($handle);
}
fclose ($handle);
return array_reverse($text);
}
}
+11 -2
View File
@@ -110,8 +110,17 @@ class Kernel {
if (getenv("APP_ENV") === "prod") { if (getenv("APP_ENV") === "prod") {
if (getenv("CACHE_PATH")) { if (getenv("CACHE_PATH")) {
# $containerBuilder->enableCompilation(getenv("CACHE_PATH") . "/di/"); # check if ACPU is there first, $containerBuilder->enableDefinitionCache();
# $containerBuilder->writeProxiesToFile(true);
$containerBuilder->enableCompilation(getenv("CACHE_PATH") . "/di/");
# No proxies yet... $containerBuilder->writeProxiesToFile(true, getenv("CACHE_PATH") . "/di/");
}
}
else {
$compiled = getenv("CACHE_PATH") . "/di/CompiledContainer.php";
if ( file_exists($compiled) ) {
unlink($compiled);
} }
} }
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace Lean;
use Picea\Extension\LanguageHandlerInterface;
use Tell;
class LanguageHandler implements LanguageHandlerInterface {
public function __construct(
public Tell\I18n $tell
) {}
public function languageFromKey(string $key, array $variables = []) #: array|string
{
return $this->tell->fromKey($key, $variables) ?: "";
}
}
+90 -5
View File
@@ -83,11 +83,21 @@ class Lean
return array_merge(...array_map(fn($app) => $app->cronard ?? [], $this->applications)); return array_merge(...array_map(fn($app) => $app->cronard ?? [], $this->applications));
} }
public function getCLI() : array
{
return array_merge(...array_map(fn($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($app) => $app->events ?? [], $this->applications));
} }
public function getTaxusPrivileges() : array
{
return array_merge(...array_map(fn($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($app) => $app->entities ?? [], $this->applications));
@@ -97,11 +107,33 @@ class Lean
{ {
$list = array_merge(...array_map(fn($app) => $app->views ?? [], $this->applications)); $list = array_merge(...array_map(fn($app) => $app->views ?? [], $this->applications));
$this->verifyPathList($list);
uasort($list, fn($i1, $i2) => $i1['order'] <=> $i2['order'] ); uasort($list, fn($i1, $i2) => $i1['order'] <=> $i2['order'] );
return $list; return $list;
} }
public function getAssetPaths() : array
{
$list = array_merge(...array_map(fn($app) => $app->piceaAssets ?? [], $this->applications));
$this->verifyPathList($list);
uasort($list, fn($i1, $i2) => $i1['order'] <=> $i2['order'] );
return $list;
}
protected function verifyPathList(array $list) : void
{
foreach($list as $item) {
if (! isset($item['order']) ) {
throw new \RuntimeException(sprintf("An error occured while verifying a path list (%s)", json_encode($item, \JSON_PRETTY_PRINT)));
}
}
}
public function getI18n(string $reader) : ? array public function getI18n(string $reader) : ? array
{ {
switch($reader) { switch($reader) {
@@ -125,19 +157,72 @@ class Lean
public static function definitions() : array public static function definitions() : array
{ {
return [];
$path = dirname(__DIR__) . "/meta/definitions/"; $path = dirname(__DIR__) . "/meta/definitions/";
return array_merge( return array_replace(
require($path . "cronard.php"), 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 . "email.php"),
require($path . "event.php"), require($path . "event.php"),
require($path . "http.php"), require($path . "http.php"),
require($path . "language.php"), require($path . "language.php"),
require($path . "negundo.php"), class_exists(\Negundo\Client\NegundoMiddleware::class) ? require($path . "negundo.php") : [],
require($path . "routes.php"), require($path . "routes.php"),
# require($path . "security.php"),
require($path . "software.php"), require($path . "software.php"),
require($path . "template.php"), require($path . "storage.php"),
class_exists(\Picea\Picea::class) ? require($path . "template.php") : [],
); );
} }
public static function autoloadDefinitionsFromComposerExtra() : array
{
$list = [];
foreach(Composer::readComposerLock()['packages'] as $package) {
foreach($package['extra']['lean']['autoload']['definitions'] ?? [] as $autoload) {
$list = array_replace($list, static::loadFromPackage($package, $autoload));
}
}
return $list;
}
public static function autoloadConfigFromComposerExtra() : array
{
$list = [];
foreach(Composer::readComposerLock()['packages'] as $package) {
foreach($package['extra']['lean']['autoload']['config'] ?? [] as $autoload) {
$list = array_merge_recursive($list, static::loadFromPackage($package, $autoload));
}
}
return $list;
}
protected static function loadFromPackage(array $package, array|string $autoload) : false|array
{
$list = [];
if (is_string($autoload)) {
$vendor = getenv('VENDOR_DIR') ? getenv('VENDOR_PATH') : dirname(__DIR__, 3);
$file = $vendor . DIRECTORY_SEPARATOR . $package['name'] . DIRECTORY_SEPARATOR . $autoload;
if ( ! file_exists($file) ) {
throw new \InvalidArgumentException(sprintf("Given autoload file `%s` from package `%s` was not found or is unreachable", $autoload, $package['name']));
}
return require($file);
}
else {
$func = implode('::', array_merge([ key($autoload) ], $autoload));
return call_user_func($func);
}
return false;
}
} }
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Lean;
use Picea\Compiler;
use Picea\Language\DefaultRegistrations;
use Picea\{ Ui\Ui, Asset\Asset };
class PiceaDefaultRegistration extends DefaultRegistrations {
public function __construct(
protected array $extensions,
protected array $syntaxes,
protected array $controlStructures,
public null|Ui $ui,
public null|Asset $asset,
) {
parent::__construct($this->extensions, $this->syntaxes, $this->controlStructures);
}
public function registerAll(Compiler $compiler) : void
{
parent::registerAll($compiler);
$this->ui AND $this->ui->registerFormExtension($compiler);
$this->asset AND $this->asset->registerExtension($compiler);
}
}
-3
View File
@@ -8,9 +8,6 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato|Ubuntu%20Mono"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato|Ubuntu%20Mono">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
<link rel="stylesheet" href='{% asset "asset/css/bulma.extension.css" %}'>
<link rel="stylesheet" href="https://cdn.eckinox.net/fontawesome/latest/css/fontawesome-all.min.css">
<style> <style>
body {background:#272822} body {background:#272822}