From 60d4c7a900493417d96667176cebda4d5871540c Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 15 Nov 2023 19:10:30 -0500 Subject: [PATCH 01/12] - WIP on moving config and definition loading into composer --- composer.json | 26 +++++++++++++++++++++++++- meta/config.php | 14 ++++++++++++++ meta/definitions/software.php | 8 ++++++++ meta/definitions/storage.php | 19 +++++++++++++++++++ src/Lean.php | 9 ++++++++- 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 meta/config.php create mode 100644 meta/definitions/storage.php diff --git a/composer.json b/composer.json index 8316d52..645d93c 100644 --- a/composer.json +++ b/composer.json @@ -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": [ @@ -134,5 +134,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" + ] + } + } } } diff --git a/meta/config.php b/meta/config.php new file mode 100644 index 0000000..d1e8b59 --- /dev/null +++ b/meta/config.php @@ -0,0 +1,14 @@ + [ + 'connections' => [ + 'sqlite' => [ + 'adapter' => 'SQLite', + 'path' => getenv('PROJECT_PATH') . DIRECTORY_SEPARATOR . "var/lean.sqlite3", + 'pragma_begin' => "journal_mode=WAL", + 'pragma_close' => "analysis_limit=500,optimize", + ], + ], + ], +]; \ No newline at end of file diff --git a/meta/definitions/software.php b/meta/definitions/software.php index 56bbc16..ebb1344 100644 --- a/meta/definitions/software.php +++ b/meta/definitions/software.php @@ -1,5 +1,6 @@ [], '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), diff --git a/meta/definitions/storage.php b/meta/definitions/storage.php new file mode 100644 index 0000000..329a014 --- /dev/null +++ b/meta/definitions/storage.php @@ -0,0 +1,19 @@ + function($c) { + $adapter = new ConnectionAdapter('sqlite', $c->get('config')['ulmus'], true); + $adapter->resolveConfiguration(); + + return $adapter; + } +]; diff --git a/src/Lean.php b/src/Lean.php index a2d62d8..eecad36 100644 --- a/src/Lean.php +++ b/src/Lean.php @@ -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") : [], ); } From 4f648b47bd721c2011b59aa28847b190330b27d3 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 15 Nov 2023 19:13:41 -0500 Subject: [PATCH 02/12] - quickfix --- composer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 645d93c..70aebd2 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -151,7 +150,7 @@ "meta/definitions/routes.php", "meta/definitions/software.php", "meta/definitions/storage.php", - "meta/definitions/template.php", + "meta/definitions/template.php" ], "config": [ "meta/config.php" @@ -159,4 +158,4 @@ } } } -} +} \ No newline at end of file From f3c4cbd95ac823f27a294d58f75b3a418c204ac3 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 15 Nov 2023 22:11:17 -0500 Subject: [PATCH 03/12] - WIP on leaning lean a bit --- composer.json | 3 -- meta/config.php | 2 +- meta/definitions/cli.php | 33 ------------ meta/definitions/cronard.php | 30 ----------- meta/definitions/language.php | 1 - meta/definitions/negundo.php | 12 ----- meta/definitions/software.php | 8 +-- meta/definitions/template.php | 61 ++--------------------- skeleton/meta/definitions/definitions.php | 12 +++-- skeleton/meta/definitions/security.php | 5 +- skeleton/meta/definitions/storage.php | 1 + src/Application.php | 35 +++++++++---- src/Lean.php | 18 +------ 13 files changed, 41 insertions(+), 180 deletions(-) delete mode 100644 meta/definitions/cli.php delete mode 100644 meta/definitions/cronard.php delete mode 100644 meta/definitions/negundo.php diff --git a/composer.json b/composer.json index 70aebd2..7c292d5 100644 --- a/composer.json +++ b/composer.json @@ -140,13 +140,10 @@ "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", diff --git a/meta/config.php b/meta/config.php index d1e8b59..7e5ad72 100644 --- a/meta/config.php +++ b/meta/config.php @@ -3,7 +3,7 @@ return [ 'ulmus' => [ 'connections' => [ - 'sqlite' => [ + 'lean' => [ 'adapter' => 'SQLite', 'path' => getenv('PROJECT_PATH') . DIRECTORY_SEPARATOR . "var/lean.sqlite3", 'pragma_begin' => "journal_mode=WAL", diff --git a/meta/definitions/cli.php b/meta/definitions/cli.php deleted file mode 100644 index 903aedf..0000000 --- a/meta/definitions/cli.php +++ /dev/null @@ -1,33 +0,0 @@ - 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"); - }; - }, -]; diff --git a/meta/definitions/cronard.php b/meta/definitions/cronard.php deleted file mode 100644 index ee1fc5c..0000000 --- a/meta/definitions/cronard.php +++ /dev/null @@ -1,30 +0,0 @@ - function($c) { - $cronardMiddleware = new CronardMiddleware($c, getenv('CRON_KEY'), function() : ResponseInterface { - 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)); - }, - - TaskFetcher::class => function($c) { - $fetcher = new TaskFetcher(null, null, $c->get('cronard.caching')); - - $fetcher->setFolderList(array_map(function($item) { - return $item; - }, $c->get(Lean::class)->getCronard())); - - return $fetcher; - }, -]; diff --git a/meta/definitions/language.php b/meta/definitions/language.php index f72b077..2438eaa 100644 --- a/meta/definitions/language.php +++ b/meta/definitions/language.php @@ -19,7 +19,6 @@ return [ return $i18n; }, - # TODO -- accept folders from Lean Apps Tell\Reader\PhpReader::class => function($c) { return new Tell\Reader\PhpReader($c->get(Lean\Lean::class)->getI18n('php'), false); }, diff --git a/meta/definitions/negundo.php b/meta/definitions/negundo.php deleted file mode 100644 index 67fb3ee..0000000 --- a/meta/definitions/negundo.php +++ /dev/null @@ -1,12 +0,0 @@ - create(SoftwareConfig::class)->constructor(getenv('NEGUNDO_HASH'), getenv('NEGUNDO_SERVER')), - NegundoMiddleware::class => autowire(NegundoMiddleware::class), - Dump::class => autowire(Dump::class), - Task::class => autowire(Task::class), -]; diff --git a/meta/definitions/software.php b/meta/definitions/software.php index ebb1344..c6b8605 100644 --- a/meta/definitions/software.php +++ b/meta/definitions/software.php @@ -1,6 +1,5 @@ [], - '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" ], - ] + 'taxus' => [], ], Lean::class => autowire(Lean::class), diff --git a/meta/definitions/template.php b/meta/definitions/template.php index e799323..46a4d8b 100644 --- a/meta/definitions/template.php +++ b/meta/definitions/template.php @@ -2,68 +2,13 @@ use function DI\autowire, DI\create, DI\get; -use Picea\{ - Language\LanguageRegistration, - Caching\Cache, - Caching\Opcache, - Compiler, - Compiler\Context, - Compiler\BaseContext, - FileFetcher, - Method\Request}; +use Picea\{ Language\LanguageRegistration, }; -use Picea\Extension\{ LanguageHandlerInterface, LanguageExtension, TitleExtension, NumberExtension, UrlExtension }; +use Picea\Extension\{ LanguageHandlerInterface, }; -use Picea\Ui\{ Method, Ui }; +use Picea\Ui\{ Ui }; return [ - Picea\Picea::class => function($c) { - 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) { - return new BaseContext($c->get(Lean\Lean::class)->getPiceaContext()); - }, - - Ui::class => autowire(Ui::class), - - 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(TitleExtension::class), - $c->get(NumberExtension::class), - $c->get(UrlExtension::class), - $c->get(Method\Form::class), - $c->get(Method\Pagination::class), - $c->get(Request::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()) - ); - }, - - TitleExtension::class => autowire(TitleExtension::class), - - NumberExtension::class => autowire(NumberExtension::class), - - 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)), - - FileFetcher::class => function($c) { - return new FileFetcher($c->get(Lean\Lean::class)->getViewPaths()); - }, ]; \ No newline at end of file diff --git a/skeleton/meta/definitions/definitions.php b/skeleton/meta/definitions/definitions.php index ed85eec..c237b22 100644 --- a/skeleton/meta/definitions/definitions.php +++ b/skeleton/meta/definitions/definitions.php @@ -1,12 +1,12 @@ "%ESCAPED_NAMESPACE%\\View", 'asset' => [], 'extensions' => [], - ], 'ulmus' => [ @@ -37,6 +36,13 @@ return array_merge( 'cli' => [ '%ESCAPED_NAMESPACE%\\Controller' => implode(DIRECTORY_SEPARATOR, [ getenv("PROJECT_PATH"), 'src', 'Controller', '' ]), ], + + '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" ], + ] ], 'app.middlewares' => [], diff --git a/skeleton/meta/definitions/security.php b/skeleton/meta/definitions/security.php index 7647b7f..531fff1 100644 --- a/skeleton/meta/definitions/security.php +++ b/skeleton/meta/definitions/security.php @@ -11,10 +11,7 @@ use function DI\autowire, DI\create, DI\get; return [ Taxus::class => function ($c) { return ( new Taxus( $c->get(PermissionGrantInterface::class) ) )->add( - [ 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" ], + $c->get(Lean\Lean::class)->getTaxusPrivileges() ); }, diff --git a/skeleton/meta/definitions/storage.php b/skeleton/meta/definitions/storage.php index 8b485dc..b0336d4 100644 --- a/skeleton/meta/definitions/storage.php +++ b/skeleton/meta/definitions/storage.php @@ -19,6 +19,7 @@ return [ AdapterProxy::class => function (ContainerInterface $c) { return new AdapterProxy( + $c->get('lean:adapter.sqlite'), $c->get(ConnectionAdapter::class) ); }, diff --git a/src/Application.php b/src/Application.php index f242282..424c727 100644 --- a/src/Application.php +++ b/src/Application.php @@ -28,6 +28,8 @@ class Application public array $tellPhp; + public array $taxus; + public array $data = []; public function __construct(string $name) { @@ -38,7 +40,14 @@ class Application { $this->data = array_replace($this->data, $data); - if (is_array($picea = $data['picea'] ?? false)) { + $this->loadData(); + + return $this; + } + + public function loadData() : static + { + if (is_array($picea = $this->data['picea'] ?? false)) { if ($picea['context'] ?? false ) { $this->piceaContext = $picea['context']; } @@ -56,13 +65,13 @@ class Application } } - if (is_array($ulmus = $data['ulmus'] ?? false)) { + if (is_array($ulmus = $this->data['ulmus'] ?? false)) { if ($ulmus['entities'] ?? false) { $this->entities = $ulmus['entities']; } } - if (is_array($tell = $data['tell'] ?? false)) { + if (is_array($tell = $this->data['tell'] ?? false)) { if ($tell['json'] ?? false) { $this->tellJson = $tell['json']; } @@ -72,20 +81,24 @@ class Application } } - if (is_array($data['routes'] ?? false)) { - $this->routes = $data['routes']; + if (is_array($this->data['routes'] ?? false)) { + $this->routes = $this->data['routes']; } - if (is_array($data['cronard'] ?? false)) { - $this->cronard = $data['cronard']; + if (is_array($this->data['cronard'] ?? false)) { + $this->cronard = $this->data['cronard']; } - if (is_array($data['events'] ?? false)) { - $this->events = $data['events']; + if (is_array($this->data['events'] ?? false)) { + $this->events = $this->data['events']; } - if (is_array($data['cli'] ?? false)) { - $this->cli = $data['cli']; + if (is_array($this->data['cli'] ?? false)) { + $this->cli = $this->data['cli']; + } + + if (is_array($this->data['taxus'] ?? false)) { + $this->taxus = $this->data['taxus']; } return $this; diff --git a/src/Lean.php b/src/Lean.php index eecad36..0a01724 100644 --- a/src/Lean.php +++ b/src/Lean.php @@ -155,26 +155,10 @@ class Lean return null; } + #[\Deprecated("Definitions are now loaded automatically from composer extra array.")] public static function definitions() : array { return []; - - $path = dirname(__DIR__) . "/meta/definitions/"; - - return array_replace( - require($path . "authorize.php"), - class_exists(\Mcnd\CLI\CliMiddleware::class) ? require($path . "cli.php") : [], - class_exists(\Cronard\CronardMiddleware::class) ? require($path . "cronard.php") : [], - require($path . "email.php"), - require($path . "event.php"), - require($path . "http.php"), - require($path . "language.php"), - class_exists(\Negundo\Client\NegundoMiddleware::class) ? require($path . "negundo.php") : [], - require($path . "routes.php"), - require($path . "software.php"), - require($path . "storage.php"), - class_exists(\Picea\Picea::class) ? require($path . "template.php") : [], - ); } public static function autoloadDefinitionsFromComposerExtra() : array From 7b0a0cf333ae7e45c8ce63625d8df633633e6e44 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 08:16:33 -0500 Subject: [PATCH 04/12] - Work on removing Guzzle from dependencies --- composer.json | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/composer.json b/composer.json index 8316d52..528d74d 100644 --- a/composer.json +++ b/composer.json @@ -21,20 +21,15 @@ "laminas/laminas-httphandlerrunner": "2.5.x-dev", "vlucas/phpdotenv": "^3.4@dev", "middlewares/whoops": "dev-master", - "guzzlehttp/guzzle": "^7@dev", + "ralouphie/getallheaders": "dev-master", "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/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", @@ -49,10 +44,6 @@ "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/event.git" @@ -73,14 +64,6 @@ "type": "vcs", "url": "https://git.mcnd.ca/mcndave/ulmus-user.git" }, - { - "type": "vcs", - "url": "https://git.mcnd.ca/mcndave/picea.git" - }, - { - "type": "vcs", - "url": "https://git.mcnd.ca/mcndave/picea-ui.git" - }, { "type": "vcs", "url": "https://git.mcnd.ca/mcndave/notes.git" @@ -89,18 +72,10 @@ "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-breadcrumb.git" - }, { "type": "vcs", "url": "https://git.mcnd.ca/mcndave/notes-event.git" From 06741d09c0b188ca9da1885c1cec9ba24a064374 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 09:16:55 -0500 Subject: [PATCH 05/12] - Fixed regression removing getallheaders --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bfb2e84..37438f1 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "laminas/laminas-httphandlerrunner": "2.5.x-dev", "vlucas/phpdotenv": "^3.4@dev", "middlewares/whoops": "dev-master", - "ralouphie/getallheaders": "dev-master", + "ralouphie/getallheaders": "^3@dev", "swiftmailer/swiftmailer": "^6.2@dev", "mcnd/storage": "dev-master", "mcnd/lean-console": "dev-master", From e8c3cf01c9adda65aa0372fdf03d62108c0b5704 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 13:58:22 -0500 Subject: [PATCH 06/12] - WIP on leaning the framework a bit --- composer.json | 8 -------- 1 file changed, 8 deletions(-) diff --git a/composer.json b/composer.json index 37438f1..5b6d72c 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,6 @@ "laminas/laminas-httphandlerrunner": "2.5.x-dev", "vlucas/phpdotenv": "^3.4@dev", "middlewares/whoops": "dev-master", - "ralouphie/getallheaders": "^3@dev", - "swiftmailer/swiftmailer": "^6.2@dev", "mcnd/storage": "dev-master", "mcnd/lean-console": "dev-master", "mcnd/ulmus": "dev-master", @@ -30,7 +28,6 @@ "mcnd/dump": "dev-master", "mcnd/event": "dev-master", "mcnd/notes-event": "dev-master", - "mcnd/notes-tell": "dev-master", "mcnd/notes-route": "dev-master", "mcnd/notes-security": "dev-master", "mcnd/ulmus-user": "dev-master", @@ -79,10 +76,6 @@ "type": "vcs", "url": "https://git.mcnd.ca/mcndave/notes-event.git" }, - { - "type": "vcs", - "url": "https://git.mcnd.ca/mcndave/notes-tell.git" - }, { "type": "vcs", "url": "https://git.mcnd.ca/mcndave/tell.git" @@ -113,7 +106,6 @@ "lean" : { "autoload": { "definitions" : [ - "meta/definitions/software.php", "meta/definitions/authorize.php", "meta/definitions/email.php", "meta/definitions/event.php", From 5f0deef7f854ab4a082f8a0ec76c63574690d24b Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 19:48:22 +0000 Subject: [PATCH 07/12] - Prepping for Notes merging --- composer.json | 15 --------------- src/Routing.php | 1 - 2 files changed, 16 deletions(-) diff --git a/composer.json b/composer.json index 5b6d72c..c3ef202 100644 --- a/composer.json +++ b/composer.json @@ -27,9 +27,6 @@ "mcnd/tell": "dev-master", "mcnd/dump": "dev-master", "mcnd/event": "dev-master", - "mcnd/notes-event": "dev-master", - "mcnd/notes-route": "dev-master", - "mcnd/notes-security": "dev-master", "mcnd/ulmus-user": "dev-master", "mcnd/thebugs": "dev-master", "mcnd/taxus": "dev-master", @@ -64,18 +61,6 @@ "type": "vcs", "url": "https://git.mcnd.ca/mcndave/notes.git" }, - { - "type": "vcs", - "url": "https://git.mcnd.ca/mcndave/notes-route.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/tell.git" diff --git a/src/Routing.php b/src/Routing.php index 2b9fd4a..8095452 100644 --- a/src/Routing.php +++ b/src/Routing.php @@ -41,7 +41,6 @@ class Routing { public Router $router, public RouteFetcher $fetcher, public SecurityHandler $security, - public LanguageHandler $language, public Taxus $taxus, public EventManager $eventManager, ) { } From bc55a2ab898440083c9e2dbc93f3aaa8b1282b20 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 19:48:55 +0000 Subject: [PATCH 08/12] - Removed lean/console from requirements --- composer.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/composer.json b/composer.json index c3ef202..634ee44 100644 --- a/composer.json +++ b/composer.json @@ -33,10 +33,6 @@ "psr/simple-cache": "*" }, "repositories": [ - { - "type": "vcs", - "url": "https://git.mcnd.ca/mcndave/lean-console.git" - }, { "type": "vcs", "url": "https://git.mcnd.ca/mcndave/event.git" From 9b795b857a292af0f5f722004002d6f1352ea8a3 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 22:05:05 -0500 Subject: [PATCH 09/12] WIP on liteing the framework --- composer.json | 6 +---- meta/definitions/event.php | 15 ++++++++---- meta/definitions/security.php | 22 ------------------ skeleton/.env | 6 +++++ src/ControllerTrait.php | 4 ++-- src/Factory/HttpFactory.php | 6 +++++ src/Routing.php | 44 ++++++++--------------------------- 7 files changed, 36 insertions(+), 67 deletions(-) delete mode 100644 meta/definitions/security.php diff --git a/composer.json b/composer.json index 634ee44..5c73572 100644 --- a/composer.json +++ b/composer.json @@ -27,9 +27,9 @@ "mcnd/tell": "dev-master", "mcnd/dump": "dev-master", "mcnd/event": "dev-master", - "mcnd/ulmus-user": "dev-master", "mcnd/thebugs": "dev-master", "mcnd/taxus": "dev-master", + "mcnd/notes": "dev-master", "psr/simple-cache": "*" }, "repositories": [ @@ -49,10 +49,6 @@ "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/notes.git" diff --git a/meta/definitions/event.php b/meta/definitions/event.php index 36bd99d..84c081f 100644 --- a/meta/definitions/event.php +++ b/meta/definitions/event.php @@ -25,11 +25,16 @@ return [ Event\EventDefinition::class => function($c) { return new Event\EventDefinition([ - new class() implements RoutingCompileRoutes { + + new class($c->has(\Picea\Extension\UrlExtension::class) ? $c->get(\Picea\Extension\UrlExtension::class) : null) implements RoutingCompileRoutes { + public function __construct( + protected ? \Picea\Extension\UrlExtension $extension, + ) {} + 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); + $this->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, $attribute->methods ?? (array)$attribute->method); } } }, @@ -45,7 +50,9 @@ return [ # Checking if user needs to be logged if ( $container->has(SecurityHandler::class) ){ - if ( $redirect = $container->get(SecurityHandler::class)->verify($class, $method) ) { + $securityHandler = $container->get(SecurityHandler::class); + + if ( $redirect = $securityHandler->verify($class, $method) ) { if ( empty($object->user) || ! $object->user->logged ) { $routing->session->set('redirectedFrom', (string) $request->getUri()); $routing->response = $redirect; @@ -54,7 +61,7 @@ return [ } } - if ( $container->has(Taxus::class) ) { + if ( $securityHandler->isLocked($class, $method) && $container->has(Taxus::class) ) { if ( $forbidden = $container->get(SecurityHandler::class)->taxus($class, $method, $object->user ?? null) ) { $routing->response = $forbidden; diff --git a/meta/definitions/security.php b/meta/definitions/security.php deleted file mode 100644 index 1cc4c09..0000000 --- a/meta/definitions/security.php +++ /dev/null @@ -1,22 +0,0 @@ - function ($c) { - return ( new Taxus( $c->get(PermissionGrantInterface::class) ) )->add( - [ 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" ], - ); - }, - - PermissionGrantInterface::class => create(DefaultPermissionGrant::class)->constructor(get(ServerRequestInterface::class), get(Session::class)), -]; diff --git a/skeleton/.env b/skeleton/.env index b9cc2c8..7d73d77 100644 --- a/skeleton/.env +++ b/skeleton/.env @@ -23,6 +23,12 @@ DEFAULT_TIME = "fr.UTF-8" DEFAULT_TIME_FALLBACK = "french.UTF-8" # Database +#SQLITE_PATH = "var/home.sqlite3" +#SQLITE_ADAPTER = "SQLite" +#SQLITE_PRAGMA_BEGIN = "foreign_keys=ON,synchronous=NORMAL" +#SQLITE_PRAGMA_DEBUG_BEGIN = "journal_mode=WAL" +#SQLITE_PRAGMA_CLOSE = "analysis_limit=500,optimize" + DATABASE_PORT = "" DATABASE_HOST = "" DATABASE_NAME = "" diff --git a/src/ControllerTrait.php b/src/ControllerTrait.php index ea0b2be..adfc2a8 100644 --- a/src/ControllerTrait.php +++ b/src/ControllerTrait.php @@ -13,8 +13,8 @@ use Psr\Http\Message\{ ServerRequestInterface, ResponseInterface }; use function file_get_contents; -#[Security(locked: true)] -#[Route(method: [ "GET", "POST", "DELETE" ])] +#[Security(locked: true, realm: "Protected Area")] +#[Route(method: [ "GET", "POST" ])] trait ControllerTrait { public ? \Notes\Breadcrumb\Breadcrumb $breadcrumb; diff --git a/src/Factory/HttpFactory.php b/src/Factory/HttpFactory.php index 6f32edc..33324db 100644 --- a/src/Factory/HttpFactory.php +++ b/src/Factory/HttpFactory.php @@ -4,10 +4,16 @@ namespace Lean\Factory; use Laminas\Diactoros\Response\{EmptyResponse, HtmlResponse, JsonResponse, RedirectResponse, TextResponse}; use Lean\Response\{ DownloadResponse, ImageResponse, FileDownloadResponse, PdfResponse }; +use Laminas\Diactoros\Response; use Psr\Http\Message\ResponseInterface; class HttpFactory { + public static function createResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface + { + return new Response($url, $code, $headers); + } + public static function createRedirectResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface { return new RedirectResponse($url, $code, $headers); diff --git a/src/Routing.php b/src/Routing.php index 8095452..eb07ca6 100644 --- a/src/Routing.php +++ b/src/Routing.php @@ -2,9 +2,6 @@ namespace Lean; -use Notes\Annotation; -use Taxus\Taxus; - use League\Route\RouteGroup, League\Route\Router; @@ -14,54 +11,33 @@ use Psr\Http\Message\ServerRequestInterface, use Notes\Route\RouteFetcher; -use Notes\Security\SecurityHandler; - -use Notes\Tell\LanguageHandler; - -use Picea\Picea, - Picea\Extension\UrlExtension; - -use Storage\Cookie, - Storage\Session; - use Mcnd\Event\EventManager; -use function DI\autowire, DI\create; - class Routing { - public Annotation $selectedRoute; - public ResponseInterface $response; public function __construct( - public Session $session, - public Cookie $cookie, - public UrlExtension $extension, public Router $router, public RouteFetcher $fetcher, - public SecurityHandler $security, - public Taxus $taxus, public EventManager $eventManager, ) { } public function registerRoute(ContainerInterface $container, string $urlBase) { $this->router->group(rtrim($urlBase, "/"), function (RouteGroup $route) use ($container) { - foreach($this->fetcher->compile() as $annotation) { - $this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $annotation); + foreach($this->fetcher->compile() as $attribute) { + $this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $attribute); - /* @deprecated annotation->method will become standard when using native attributes */ - foreach((array) ( $annotation->method ?? $annotation->methods ) as $method) { - # Mapping every URLs from annotations in searched folders (Api, Controller, etc...) - $route->map(strtoupper($method), $annotation->getRoute(), function (ServerRequestInterface $request, array $arguments) use ( - $container, $route, $annotation - ) : ResponseInterface - { - $class = $annotation->class; - $method = $annotation->classMethod; + # Mapping every URLs from attributes in searched folders (Api, Controller, etc...) + foreach((array) $attribute->method as $method) { + $route->map(strtoupper($method), $attribute->getRoute(), function (ServerRequestInterface $request, array $arguments) use ( + $container, $route, $attribute + ) : ResponseInterface { + $class = $attribute->class; + $method = $attribute->classMethod; $object = $container->get($class); - $this->eventManager->execute(Event\RoutingMapRoutes::class, $this, $container, $request, $annotation); + $this->eventManager->execute(Event\RoutingMapRoutes::class, $this, $container, $request, $attribute); $container->set(ServerRequestInterface::class, $request); From 6c58586823bb5382f27427490d2471dfc51c41f2 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 22:32:50 -0500 Subject: [PATCH 10/12] - Moved storage into console, where it belongs --- composer.json | 1 - meta/definitions/storage.php | 19 ------------------- 2 files changed, 20 deletions(-) delete mode 100644 meta/definitions/storage.php diff --git a/composer.json b/composer.json index 5c73572..5772d7d 100644 --- a/composer.json +++ b/composer.json @@ -90,7 +90,6 @@ "meta/definitions/language.php", "meta/definitions/routes.php", "meta/definitions/software.php", - "meta/definitions/storage.php", "meta/definitions/template.php" ], "config": [ diff --git a/meta/definitions/storage.php b/meta/definitions/storage.php deleted file mode 100644 index 329a014..0000000 --- a/meta/definitions/storage.php +++ /dev/null @@ -1,19 +0,0 @@ - function($c) { - $adapter = new ConnectionAdapter('sqlite', $c->get('config')['ulmus'], true); - $adapter->resolveConfiguration(); - - return $adapter; - } -]; From 30d0e8a14d32c068afd1d1278da196f0c82de4f7 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 23:35:37 -0500 Subject: [PATCH 11/12] - fixed a missed bug while migrating code from Routing event --- meta/config.php | 13 +------------ meta/definitions/event.php | 5 ++++- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/meta/config.php b/meta/config.php index 7e5ad72..b993871 100644 --- a/meta/config.php +++ b/meta/config.php @@ -1,14 +1,3 @@ [ - 'connections' => [ - 'lean' => [ - 'adapter' => 'SQLite', - 'path' => getenv('PROJECT_PATH') . DIRECTORY_SEPARATOR . "var/lean.sqlite3", - 'pragma_begin' => "journal_mode=WAL", - 'pragma_close' => "analysis_limit=500,optimize", - ], - ], - ], -]; \ No newline at end of file +return []; \ No newline at end of file diff --git a/meta/definitions/event.php b/meta/definitions/event.php index 84c081f..e052a74 100644 --- a/meta/definitions/event.php +++ b/meta/definitions/event.php @@ -54,7 +54,10 @@ return [ if ( $redirect = $securityHandler->verify($class, $method) ) { if ( empty($object->user) || ! $object->user->logged ) { - $routing->session->set('redirectedFrom', (string) $request->getUri()); + if ($container->has(Session::class)) { + $container->get(Session::class)->set('redirectedFrom', (string)$request->getUri()); + } + $routing->response = $redirect; return; From ff4c94f8202e8ed3f277f28e69c7832a0d58f2f4 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 20 Nov 2023 11:58:01 -0500 Subject: [PATCH 12/12] - Removed authentication middlewares --- meta/definitions/event.php | 5 +++-- meta/definitions/routes.php | 4 ++-- meta/definitions/storage.php | 12 ++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 meta/definitions/storage.php diff --git a/meta/definitions/event.php b/meta/definitions/event.php index e052a74..bfa78a9 100644 --- a/meta/definitions/event.php +++ b/meta/definitions/event.php @@ -24,9 +24,10 @@ return [ }, Event\EventDefinition::class => function($c) { - return new Event\EventDefinition([ + $ext = $c->has(\Picea\Extension\UrlExtension::class) ? $c->get(\Picea\Extension\UrlExtension::class) : null; - new class($c->has(\Picea\Extension\UrlExtension::class) ? $c->get(\Picea\Extension\UrlExtension::class) : null) implements RoutingCompileRoutes { + return new Event\EventDefinition([ + new class($ext) implements RoutingCompileRoutes { public function __construct( protected ? \Picea\Extension\UrlExtension $extension, ) {} diff --git a/meta/definitions/routes.php b/meta/definitions/routes.php index 8cae467..e8bfc8b 100644 --- a/meta/definitions/routes.php +++ b/meta/definitions/routes.php @@ -50,8 +50,8 @@ return [ ], 'app.middlewares' => [ - HeaderAuthenticationMiddleware::class, - PostRequestAuthenticationMiddleware::class, + # HeaderAuthenticationMiddleware::class, + # PostRequestAuthenticationMiddleware::class, ], 'routes.list' => function($c) { diff --git a/meta/definitions/storage.php b/meta/definitions/storage.php new file mode 100644 index 0000000..6020ee7 --- /dev/null +++ b/meta/definitions/storage.php @@ -0,0 +1,12 @@ + function($c) { + $adapter = new ConnectionAdapter('sqlite', $c->get('config')['ulmus'], true); + $adapter->resolveConfiguration(); + + return $adapter; + } +];