From fd95e8db91fda3162c6c7682383440802d301b8b Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 12 May 2023 18:55:16 +0000 Subject: [PATCH 1/7] - Small error made on latest push --- skeleton/meta/definitions/env/prod.php | 2 -- view/lean/widget/popup.phtml | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 view/lean/widget/popup.phtml diff --git a/skeleton/meta/definitions/env/prod.php b/skeleton/meta/definitions/env/prod.php index a4b653e..5a705fb 100644 --- a/skeleton/meta/definitions/env/prod.php +++ b/skeleton/meta/definitions/env/prod.php @@ -5,8 +5,6 @@ use Picea\Picea; #use CSLSJ\Debogueur\DebogueurMiddleware; use Negundo\Client\{ NegundoMiddleware, SoftwareConfig }; -use - use Laminas\Diactoros\Response\HtmlResponse; use Psr\Http\Server\MiddlewareInterface, diff --git a/view/lean/widget/popup.phtml b/view/lean/widget/popup.phtml new file mode 100644 index 0000000..e710722 --- /dev/null +++ b/view/lean/widget/popup.phtml @@ -0,0 +1,19 @@ + + + \ No newline at end of file From 8390506361ae6edd4977835babf0fc578e825b42 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 30 May 2023 15:37:03 -0400 Subject: [PATCH 2/7] - Added an event manager for Lean's route dispatching --- meta/definitions/event.php | 64 ++++++++++++++++++++- skeleton/meta/definitions/env/prod.php | 3 - skeleton/src/Kernel.php | 2 - skeleton/var/tmp/.gitkeep | 0 src/ControllerTrait.php | 2 +- src/Event/RoutingCompileRoutes.php | 10 ++++ src/Event/RoutingMapRoutes.php | 12 ++++ src/Routing.php | 79 ++++++-------------------- 8 files changed, 102 insertions(+), 70 deletions(-) create mode 100644 skeleton/var/tmp/.gitkeep create mode 100644 src/Event/RoutingCompileRoutes.php create mode 100644 src/Event/RoutingMapRoutes.php diff --git a/meta/definitions/event.php b/meta/definitions/event.php index fa8cb15..581e838 100644 --- a/meta/definitions/event.php +++ b/meta/definitions/event.php @@ -1,17 +1,77 @@ autowire(Event\EventManager::class), Event\EventMiddleware::class => function($c) { $mw = new Event\EventMiddleware($c, $c->get(Event\EventManager::class)); + $mw->fromAttributes($c->get(Notes\Event\EventFetcher::class)); + $mw->fromDefinition($c->get(Event\EventDefinition::class)); - return $mw->fromAttributes($c->get(Notes\Event\EventFetcher::class)); + return $mw; + }, + + 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 + { + if (null !== ($name = $attribute->name ?? null)) { + $routing->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, $attribute->methods ?? (array)$attribute->method); + } + } + }, + + new class() implements RoutingMapRoutes { + public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route|\Notes\Route\Annotation\Method\Route $attribute) : void + { + $class = $attribute->class; + $method = $attribute->classMethod; + + $request = $request->withAttribute('lean.route', $attribute); + + # Checking if user needs to be logged + if ( $container->has(SecurityHandler::class) ){ + if ( $redirect = $container->get(SecurityHandler::class)->verify($class, $method) ) { + if ( empty($object->user) || ! $object->user->logged ) { + $routing->session->set('redirectedFrom', (string) $request->getUri()); + $routing->response = $redirect; + + return; + } + } + + if ( $container->has(Taxus::class) ) { + if ( $forbidden = $container->get(SecurityHandler::class)->taxus($class, $method, $object->user ?? null) ) { + $routing->response = $forbidden; + + return; + } + } + } + + if ($container->has(Picea::class)) { + $container->get(Picea::class)->globalVariables['route'] = $attribute; + } + + if ($container->has(Session::class)) { + $container->get(Session::class)->set("lean.route", $attribute); + } + } + }, + ]); }, Notes\Event\EventFetcher::class => function($c) { diff --git a/skeleton/meta/definitions/env/prod.php b/skeleton/meta/definitions/env/prod.php index a4b653e..fea6aa1 100644 --- a/skeleton/meta/definitions/env/prod.php +++ b/skeleton/meta/definitions/env/prod.php @@ -2,11 +2,8 @@ use Picea\Picea; -#use CSLSJ\Debogueur\DebogueurMiddleware; use Negundo\Client\{ NegundoMiddleware, SoftwareConfig }; -use - use Laminas\Diactoros\Response\HtmlResponse; use Psr\Http\Server\MiddlewareInterface, diff --git a/skeleton/src/Kernel.php b/skeleton/src/Kernel.php index adff807..7bfccd4 100644 --- a/skeleton/src/Kernel.php +++ b/skeleton/src/Kernel.php @@ -29,8 +29,6 @@ new class(dirname(__DIR__)) extends \Lean\Kernel { protected function serviceContainer() : self { - # $this->container->get(ConnectionAdapter::class); - return parent::serviceContainer(); } diff --git a/skeleton/var/tmp/.gitkeep b/skeleton/var/tmp/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/ControllerTrait.php b/src/ControllerTrait.php index fdca39b..9f866c6 100644 --- a/src/ControllerTrait.php +++ b/src/ControllerTrait.php @@ -92,7 +92,7 @@ trait ControllerTrait { return new HtmlResponse($html, $code, $headers); } - public static function renderJson(/*\JsonSerializable|array*/ $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); } diff --git a/src/Event/RoutingCompileRoutes.php b/src/Event/RoutingCompileRoutes.php new file mode 100644 index 0000000..5eda957 --- /dev/null +++ b/src/Event/RoutingCompileRoutes.php @@ -0,0 +1,10 @@ +session = $session; - $this->cookie = $cookie; - $this->extension = $extension; - $this->fetcher = $routeFetcher; - $this->security = $security; - $this->language = $language; - $this->router = $router; - $this->taxus = $taxus; - } + 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) { - # Register routes to the UrlExtension from picea (handling url, route and asset extensions) - if ( null !== ( $name = $annotation->name ?? null ) ) { - $this->extension->registerRoute($name, $annotation->getRoute(), $annotation->class, $annotation->classMethod, $annotation->methods ?? (array) $annotation->method); - } + $this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $annotation); + /* @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 ( @@ -84,34 +60,13 @@ class Routing { { $class = $annotation->class; $method = $annotation->classMethod; - - # $container->set($class, autowire($class)->method($method, $request)); - $object = $container->get($class); - # Checking if user needs to be logged - if ( ( $redirect = $this->security->verify($class, $method) ) && ( empty($object->user) || ! $object->user->logged ) ) { - $this->session->redirectedFrom = (string) $request->getUri(); - - return $redirect; - } - - if ( $forbidden = $this->security->taxus($class, $method, $object->user ?? null) ) { - return $forbidden; - } - - # @TODO of course, this as to go ; moving to a simple callback method soon which can then be fed by Picea - if ( $container->has(Picea::class) ) { - $container->get(Picea::class)->globalVariables['route'] = $annotation; - } - - $request = $request->withAttribute('lean.route', $annotation); - - $this->session->set("lean.route", $annotation); + $this->eventManager->execute(Event\RoutingMapRoutes::class, $this, $container, $request, $annotation); $container->set(ServerRequestInterface::class, $request); - return $object->$method($request, $arguments); + return $this->response ?? $object->$method($request, $arguments); }); } } From 94fc8885cf60f4c40a38efe4a9ae0f9b5d4d7f56 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 31 May 2023 15:54:06 +0000 Subject: [PATCH 3/7] - Switch to Symfony Mailer from SwiftMailer - Added CSSLSJ new API config --- meta/definitions/email.php | 6 +++--- skeleton/.env | 4 ++++ skeleton/meta/config.php | 8 ++++++++ skeleton/meta/definitions/auth.php | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/meta/definitions/email.php b/meta/definitions/email.php index 22901ab..508c168 100644 --- a/meta/definitions/email.php +++ b/meta/definitions/email.php @@ -4,12 +4,12 @@ use function DI\autowire, DI\create, DI\get; use TheBugs\Email\EmailConfiguration, TheBugs\Email\MailerInterface, - TheBugs\Email\SwiftMailer; + TheBugs\Email\SymfonyMailer; return [ EmailConfiguration::class => function($c) { $email = new EmailConfiguration( EmailConfiguration::AUTH_TYPE_SMTP ); - $email->smtpHost = getenv('SMTP_HOST'); + $email->smtpHost = getenv('SMTP_HOSTNAME'); $email->smtpPort = getenv('SMTP_PORT'); $email->smtpUsername = getenv('SMTP_USERNAME'); $email->smtpPassword = getenv('SMTP_PASSWORD'); @@ -20,5 +20,5 @@ return [ return $email; }, - MailerInterface::class => autowire(SwiftMailer::class), + MailerInterface::class => autowire(SymfonyMailer::class), ]; diff --git a/skeleton/.env b/skeleton/.env index 57ff9c5..cf8e6b3 100644 --- a/skeleton/.env +++ b/skeleton/.env @@ -22,6 +22,10 @@ DEFAULT_LOCAL = "fr_CA.UTF-8" DEFAULT_TIME = "fr.UTF-8" DEFAULT_TIME_FALLBACK = "french.UTF-8" +CSSLSJ_API_URL = "http://api-dev.cslsj.qc.ca" +CSSLSJ_API_USERNAME = "dev" +CSSLSJ_API_PASSWORD = "dev" + # MS Authentication # MS_OAUTH_CLIENT_ID = "" # MS_OAUTH_CLIENT_SECRET = "" diff --git a/skeleton/meta/config.php b/skeleton/meta/config.php index 99fbb40..68fd37f 100644 --- a/skeleton/meta/config.php +++ b/skeleton/meta/config.php @@ -17,6 +17,14 @@ return [ 'application_name' => "", ], + 'api' => [ + 'auth' => [ + 'type' => \CSLSJ\Api\AuthType::AUTH_HEADER_BASIC, + 'username' => getenv('CSSLSJ_API_USERNAME'), + 'password' => getenv('CSSLSJ_API_PASSWORD'), + ] + ], + 'ulmus' => [ 'connections' => [ 'default' => [ diff --git a/skeleton/meta/definitions/auth.php b/skeleton/meta/definitions/auth.php index c07a3d9..5b29ebe 100644 --- a/skeleton/meta/definitions/auth.php +++ b/skeleton/meta/definitions/auth.php @@ -50,9 +50,13 @@ return [ }; }, + CSLSJ\Api\Client::class => create(CSLSJ\Api\Client::class)->constructor(get('api.authentication'), getenv('CSSLSJ_API_URL')), + + 'api.authentication' => function ($c) { return $c->get('config')['api']['auth']; }, + EmailConfiguration::class => function($c) { $email = new EmailConfiguration( EmailConfiguration::AUTH_TYPE_SMTP ); - $email->smtpHost = getenv('SMTP_HOST'); + $email->smtpHost = getenv('SMTP_HOSTNAME'); $email->smtpPort = getenv('SMTP_PORT'); $email->smtpUsername = getenv('SMTP_USERNAME'); $email->smtpPassword = getenv('SMTP_PASSWORD'); From 428e26fbfba55d6ad6a351020c7465457b697bd8 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 31 May 2023 18:06:19 +0000 Subject: [PATCH 4/7] - Fixed a redirection-loop --- composer.json | 32 +++++++++++++++++++++++--------- meta/definitions/event.php | 1 + meta/definitions/template.php | 2 +- skeleton/.env | 17 ++++------------- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index f88b59a..fa4732d 100644 --- a/composer.json +++ b/composer.json @@ -10,27 +10,41 @@ } ], "require": { - "vlucas/phpdotenv": "^3.4@dev", + "php": "^8.2", "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-httphandlerrunner": "2.5.x-dev", + "vlucas/phpdotenv": "^3.4@dev", + "middlewares/whoops": "dev-master", + "ralouphie/getallheaders": "dev-master", + "guzzlehttp/guzzle": "^6.3@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", "mcnd/picea-ui": "dev-master", "mcnd/cronard": "dev-master", "mcnd/tell": "dev-master", "mcnd/dump": "dev-master", - "mcnd/notes": "dev-master", + "mcnd/event": "dev-master", + "mcnd/notes-cronard": "dev-master", + "mcnd/notes-event": "dev-master", + "mcnd/notes-tell": "dev-master", "mcnd/notes-route": "dev-master", "mcnd/notes-security": "dev-master", - "mcnd/notes-tell": "dev-master", - "swiftmailer/swiftmailer": "^6.2@dev", - "league/route": "^5.0.0-dev", - "vlucas/phpdotenv": "^3.4@dev", - "middlewares/whoops": "dev-master", - "ralouphie/getallheaders": "dev-master" + "mcnd/ulmus-user": "dev-master", + "mcnd/thebugs": "dev-master", + "mcnd/taxus": "dev-master", + "mcnd/imagine": "dev-master", + "mcnd/notes-breadcrumb": "dev-master", + "psr/simple-cache": "*" }, "repositories": [ { diff --git a/meta/definitions/event.php b/meta/definitions/event.php index 581e838..2e5fdd6 100644 --- a/meta/definitions/event.php +++ b/meta/definitions/event.php @@ -39,6 +39,7 @@ return [ { $class = $attribute->class; $method = $attribute->classMethod; + $object = $container->get($class); $request = $request->withAttribute('lean.route', $attribute); diff --git a/meta/definitions/template.php b/meta/definitions/template.php index 8aa3b7b..95d3d81 100644 --- a/meta/definitions/template.php +++ b/meta/definitions/template.php @@ -65,7 +65,7 @@ return [ 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)), diff --git a/skeleton/.env b/skeleton/.env index 57ff9c5..b9cc2c8 100644 --- a/skeleton/.env +++ b/skeleton/.env @@ -1,11 +1,11 @@ APP_ENV = dev DEBUG = 1 -KEYS = "dev:dev" +KEYS = "dev" CRON_KEY = dev # Route URL_BASE = "" -APP_URL = "dev.cslsj.qc.ca" +APP_URL = "dev.mcnd.ca" # Path CACHE_DIR = "var/cache" @@ -22,18 +22,9 @@ DEFAULT_LOCAL = "fr_CA.UTF-8" DEFAULT_TIME = "fr.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_PORT = "3306" -DATABASE_HOST = "appsdb.cslsj.qc.ca" +DATABASE_PORT = "" +DATABASE_HOST = "" DATABASE_NAME = "" DATABASE_USERNAME = "" DATABASE_PASSWORD = "" From 4274a6f4a42d6354b9f02f707d1150678d6817b5 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 31 May 2023 18:12:38 +0000 Subject: [PATCH 5/7] - Removed some outer references --- skeleton/meta/config.php | 8 -------- skeleton/meta/definitions/auth.php | 4 ---- 2 files changed, 12 deletions(-) diff --git a/skeleton/meta/config.php b/skeleton/meta/config.php index 68fd37f..99fbb40 100644 --- a/skeleton/meta/config.php +++ b/skeleton/meta/config.php @@ -17,14 +17,6 @@ return [ 'application_name' => "", ], - 'api' => [ - 'auth' => [ - 'type' => \CSLSJ\Api\AuthType::AUTH_HEADER_BASIC, - 'username' => getenv('CSSLSJ_API_USERNAME'), - 'password' => getenv('CSSLSJ_API_PASSWORD'), - ] - ], - 'ulmus' => [ 'connections' => [ 'default' => [ diff --git a/skeleton/meta/definitions/auth.php b/skeleton/meta/definitions/auth.php index 5b29ebe..9405214 100644 --- a/skeleton/meta/definitions/auth.php +++ b/skeleton/meta/definitions/auth.php @@ -50,10 +50,6 @@ return [ }; }, - CSLSJ\Api\Client::class => create(CSLSJ\Api\Client::class)->constructor(get('api.authentication'), getenv('CSSLSJ_API_URL')), - - 'api.authentication' => function ($c) { return $c->get('config')['api']['auth']; }, - EmailConfiguration::class => function($c) { $email = new EmailConfiguration( EmailConfiguration::AUTH_TYPE_SMTP ); $email->smtpHost = getenv('SMTP_HOSTNAME'); From 026a13c7667ddadb8338f8973e056a7c6a123cd4 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 31 May 2023 18:34:16 +0000 Subject: [PATCH 6/7] - First quickfix of composer, more to come --- composer.json | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fa4732d..77eddee 100644 --- a/composer.json +++ b/composer.json @@ -42,15 +42,22 @@ "mcnd/ulmus-user": "dev-master", "mcnd/thebugs": "dev-master", "mcnd/taxus": "dev-master", - "mcnd/imagine": "dev-master", "mcnd/notes-breadcrumb": "dev-master", "psr/simple-cache": "*" }, "repositories": [ + { + "type": "vcs", + "url": "https://git.mcnd.ca/mcndave/lean-console.git" + }, { "type": "vcs", "url": "https://git.mcnd.ca/mcndave/cronard.git" }, + { + "type": "vcs", + "url": "https://git.mcnd.ca/mcndave/the-bugs.git" + }, { "type": "vcs", "url": "https://git.mcnd.ca/mcndave/storage.git" @@ -59,6 +66,10 @@ "type": "vcs", "url": "https://git.mcnd.ca/mcndave/ulmus.git" }, + { + "type": "vcs", + "url": "https://git.mcnd.ca/mcndave/ulmus-user.git" + }, { "type": "vcs", "url": "https://git.mcnd.ca/mcndave/picea.git" @@ -75,10 +86,18 @@ "type": "vcs", "url": "https://git.mcnd.ca/mcndave/notes-route.git" }, + { + "type": "vcs", + "url": "https://git.mcnd.ca/mcndave/notes-cronard.git" + }, { "type": "vcs", "url": "https://git.mcnd.ca/mcndave/notes-security.git" }, + { + "type": "vcs", + "url": "https://git.mcnd.ca/mcndave/notes-event.git" + }, { "type": "vcs", "url": "https://git.mcnd.ca/mcndave/notes-tell.git" From d26a15c0eda62f45723880fc0a0f854603bc1859 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 31 May 2023 18:35:40 +0000 Subject: [PATCH 7/7] - First quickfix of composer again --- composer.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 77eddee..7fd0d08 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ "mcnd/tell": "dev-master", "mcnd/dump": "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", @@ -42,7 +43,6 @@ "mcnd/ulmus-user": "dev-master", "mcnd/thebugs": "dev-master", "mcnd/taxus": "dev-master", - "mcnd/notes-breadcrumb": "dev-master", "psr/simple-cache": "*" }, "repositories": [ @@ -54,6 +54,10 @@ "type": "vcs", "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" @@ -94,6 +98,10 @@ "type": "vcs", "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"