From 446ee29afc7c2b390993a97226858b8f5ece047b Mon Sep 17 00:00:00 2001 From: Wazabii Date: Tue, 19 Dec 2023 20:52:43 +0100 Subject: [PATCH 01/28] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 38 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 0629f1537704fa6b62aef02f241c82c4162016ec Mon Sep 17 00:00:00 2001 From: Wazabii Date: Wed, 27 Dec 2023 14:41:22 +0100 Subject: [PATCH 02/28] Improved examples --- .../Controllers/Examples/DynamicPages.php | 63 ------------------- app/Http/Controllers/Examples/Pages.php | 32 ++++++++-- app/Http/Controllers/Private/Pages.php | 2 +- app/Http/Middlewares/HelloWorld.php | 57 +++++++++++++++++ app/Libraries/Foundation | 2 +- app/Libraries/Http | 2 +- app/Libraries/Output | 2 +- resources/partials/ingress.php | 7 +++ .../partials/{breadcrumb.php => text.php} | 6 +- resources/views/main.php | 4 -- 10 files changed, 97 insertions(+), 80 deletions(-) delete mode 100755 app/Http/Controllers/Examples/DynamicPages.php create mode 100755 app/Http/Middlewares/HelloWorld.php create mode 100755 resources/partials/ingress.php rename resources/partials/{breadcrumb.php => text.php} (66%) diff --git a/app/Http/Controllers/Examples/DynamicPages.php b/app/Http/Controllers/Examples/DynamicPages.php deleted file mode 100755 index a8e4fc4..0000000 --- a/app/Http/Controllers/Examples/DynamicPages.php +++ /dev/null @@ -1,63 +0,0 @@ -url = $url; - $this->container = $container; - $this->json = $json; - - // Build navigation - $this->nav = $nav->get(); - - // Load http request - $this->validateRequest = $nav->validate($this->url->withType(["pages"])->getVars()); - - // Show nav / or in DomManipulation middleware - $this->container->get("view")->setPartial("navigation", [ - "nav" => $this->nav - ]); - } - - /** - * Load dynamic page - * @Route[GET:/{page:[^/]+}] - * @param ResponseInterface $response - * @return ResponseInterface - */ - public function pages(ResponseInterface $response): ResponseInterface - { - // Validate dynamic page - if ($this->validateRequest->status() !== 200) { - $this->container->get("head")->getElement("title")->setValue("404 Could not find the page"); - $this->container->get("head")->getElement("description")->attr("content", "404 Could not find the page"); - return $response->withStatus(404); - } - - $this->container->get("head")->getElement("title")->setValue("Lorem ipsum"); - $this->container->get("head")->getElement("description")->attr("content", "Changed!"); - // Database values - $this->container->get("view")->setPartial("breadcrumb", [ - "name" => "Some data", - "content" => "Some data from the database" - ]); - - return $response; - } -} diff --git a/app/Http/Controllers/Examples/Pages.php b/app/Http/Controllers/Examples/Pages.php index ef46aed..cb8ecdc 100755 --- a/app/Http/Controllers/Examples/Pages.php +++ b/app/Http/Controllers/Examples/Pages.php @@ -9,12 +9,11 @@ class Pages extends BaseController { - protected $url; - protected $responder; - protected $users; + protected $provider; public function __construct(Provider $provider) { + $this->provider = $provider; } /** @@ -31,12 +30,26 @@ public function start(ResponseInterface $response, RequestInterface $request): R //$this->head()->getElement("title")->setValue("Welcome to my awesome app"); //$this->head()->getElement("description")->attr("content", "Some text about my awesome app"); - $this->view()->setPartial("breadcrumb", [ - "tagline" => getenv("APP_NAME"), + + $this->provider->view()->setPartial("main.ingress", [ + "tagline" => "Ingress view partial", "name" => "Welcome to MaplePHP", "content" => "Get ready to build you first application." ]); + $this->provider->view()->setPartial("main.text", [ + "tagline" => "Text view partial A", + "name" => "Lorem ipsum dolor", + "content" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam id sapien dui. Nullam gravida bibendum finibus. Pellentesque a elementum augue. Aliquam malesuada et neque ac varius. Nam id eros eros. Ut ut mattis ex. Aliquam molestie tortor quis ultrices euismod. Quisque blandit pellentesque purus, in posuere ex mollis ac." + ]); + + $this->provider->view()->setPartial("main.text.textB", [ + "tagline" => "Text view partial B", + "name" => "Lorem ipsum dolor", + "content" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam id sapien dui. Nullam gravida bibendum finibus. Pellentesque a elementum augue. Aliquam malesuada et neque ac varius. Nam id eros eros. Ut ut mattis ex. Aliquam molestie tortor quis ultrices euismod. Quisque blandit pellentesque purus, in posuere ex mollis ac." + ]); + + // Auto clear cache on update and on a future pulish date! // withLastModified will only work with the middleware "LastModifiedHandler" // It will tho automatically be turned off IF session is open to make sure no important @@ -54,7 +67,14 @@ public function start(ResponseInterface $response, RequestInterface $request): R */ public function about(ResponseInterface $response, RequestInterface $request): ResponseInterface { - $this->view()->setPartial("breadcrumb", [ + + // $this->view() is the same as $this->provider when extending to the BaseController!; + $this->view()->setPartial("main.ingress", [ + "tagline" => "Layered structure MVC framework", + "name" => "MaplePHP" + ]); + + $this->view()->setPartial("main.text", [ "tagline" => "Layered structure MVC framework", "name" => "MaplePHP", "content" => "MaplePHP is a layered structure PHP framework that has been meticulously crafted to " . diff --git a/app/Http/Controllers/Private/Pages.php b/app/Http/Controllers/Private/Pages.php index 56d08d1..7fb83f0 100755 --- a/app/Http/Controllers/Private/Pages.php +++ b/app/Http/Controllers/Private/Pages.php @@ -39,7 +39,7 @@ public function logout(ResponseInterface $response, RequestInterface $request) */ public function profile(ResponseInterface $response, RequestInterface $request) { - $this->view()->setPartial("breadcrumb", [ + $this->view()->setPartial("main.ingress", [ "tagline" => getenv("APP_NAME"), "name" => "Welcome " . $this->user()->firstname, "content" => "Get ready to build you first application." diff --git a/app/Http/Middlewares/HelloWorld.php b/app/Http/Middlewares/HelloWorld.php new file mode 100755 index 0000000..53b34c8 --- /dev/null +++ b/app/Http/Middlewares/HelloWorld.php @@ -0,0 +1,57 @@ +provider = $provider; + } + + /** + * Will load before the controllers + * @param ResponseInterface $response + * @param RequestInterface $request + * @return ResponseInterface|void + */ + public function before(ResponseInterface $response, RequestInterface $request) + { + // Bind array data to the provider/container. + $this->provider->set("helloWorld", [ + "tagline" => getenv("APP_NAME"), + "name" => "Hello world", + "content" => "The HelloWord middleware has taking over the ingress view." + ]); + // You can now access the helloWorld data in your controller with "$this->provider->helloWorld()" + } + + /** + * Custom Before middleware (Will load before the controllers) + * @param ResponseInterface $response + * @param RequestInterface $request + * @return ResponseInterface|void + */ + public function yourCustomMethod(ResponseInterface $response, RequestInterface $request) + { + } + + /** + * Will load after the controllers + * @param ResponseInterface $response + * @param RequestInterface $request + * @return ResponseInterface|void + */ + public function after(ResponseInterface $response, RequestInterface $request) + { + // This will take over the ingress view in at partial main location. + $this->provider->view()->setPartial("main.ingress", $this->provider->helloWorld()); + } +} diff --git a/app/Libraries/Foundation b/app/Libraries/Foundation index f50a1a3..6572bdf 160000 --- a/app/Libraries/Foundation +++ b/app/Libraries/Foundation @@ -1 +1 @@ -Subproject commit f50a1a3ae7408b95f1d6d3d8480a54d0a3b6f389 +Subproject commit 6572bdf60c2dde098ce6a5fcf849c2ce4d222fbc diff --git a/app/Libraries/Http b/app/Libraries/Http index 1ae4c0e..b817a5e 160000 --- a/app/Libraries/Http +++ b/app/Libraries/Http @@ -1 +1 @@ -Subproject commit 1ae4c0e43190fa2a6a649b65bc7cbbfbec458fa4 +Subproject commit b817a5ed3853a2bbeeb175822af5ddd99c1233ce diff --git a/app/Libraries/Output b/app/Libraries/Output index a095213..8021d82 160000 --- a/app/Libraries/Output +++ b/app/Libraries/Output @@ -1 +1 @@ -Subproject commit a095213c428ce3c21c63c193190255db3992846f +Subproject commit 8021d82cc739fd2dd5715b6d30dc105bbd0b3616 diff --git a/resources/partials/ingress.php b/resources/partials/ingress.php new file mode 100755 index 0000000..907e28e --- /dev/null +++ b/resources/partials/ingress.php @@ -0,0 +1,7 @@ +
+
+ tagline("Dom")->create("h6")->attr("class", "title"); ?> +

name; ?>

+

content; ?>

+
+
\ No newline at end of file diff --git a/resources/partials/breadcrumb.php b/resources/partials/text.php similarity index 66% rename from resources/partials/breadcrumb.php rename to resources/partials/text.php index 2d8735a..28ed0e4 100755 --- a/resources/partials/breadcrumb.php +++ b/resources/partials/text.php @@ -1,9 +1,9 @@ -
-
+
+
tagline("Dom")->create("h6")->attr("class", "title"); ?>

name; ?>

content; ?>

-
+
diff --git a/resources/views/main.php b/resources/views/main.php index 5c39995..bfc9071 100755 --- a/resources/views/main.php +++ b/resources/views/main.php @@ -1,7 +1,3 @@ - - -partial("breadcrumb")->get(); ?> partial("main")->get(); ?> partial("form")->get(); ?> -
\ No newline at end of file From 098e2d9f1817fb2325cf5e634eb56f1b87ae6617 Mon Sep 17 00:00:00 2001 From: Wazabii Date: Wed, 27 Dec 2023 14:45:51 +0100 Subject: [PATCH 03/28] Improved examples --- app/Libraries/Foundation | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Libraries/Foundation b/app/Libraries/Foundation index 6572bdf..e4f3ee5 160000 --- a/app/Libraries/Foundation +++ b/app/Libraries/Foundation @@ -1 +1 @@ -Subproject commit 6572bdf60c2dde098ce6a5fcf849c2ce4d222fbc +Subproject commit e4f3ee576fbad85699cedcca7bffe0e6a2935c39 From b0f523050594f9e726ed50ef5dc22c770f9da8bd Mon Sep 17 00:00:00 2001 From: Wazabii Date: Wed, 27 Dec 2023 15:02:42 +0100 Subject: [PATCH 04/28] Minor change in install heading --- config/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/app.php b/config/app.php index 5cb07a8..ab1a89d 100755 --- a/config/app.php +++ b/config/app.php @@ -17,7 +17,7 @@ 'public_dir' => 'public/', 'version' => '4.0.0', 'bundle' => $this->getenv("NONCE"), - 'maintainer' => 'Daniel Ronkainen ' + 'maintainer' => 'John Doe ' ], 'session' => [ "time" => 360, // minutes From ef407ec9fdb55e73f9e15f0ba313f18ce7c996e1 Mon Sep 17 00:00:00 2001 From: Wazabii Date: Thu, 28 Dec 2023 14:15:14 +0100 Subject: [PATCH 05/28] Major template improvements --- app/Http/Middlewares/.gitkeep | 1 - app/Http/Middlewares/Document.php | 67 +++++++++++++++++++++++ app/Http/Middlewares/Nav.php | 74 ++++++++++++++++++++++++++ app/Http/Routes/web.php | 20 +++---- app/Libraries/DTO | 2 +- app/Libraries/Foundation | 2 +- app/Libraries/Handler | 2 +- app/Libraries/Output | 2 +- config/app.php | 8 ++- config/navigation.php | 42 +++++++++++++++ public/index.php | 3 ++ resources/index.php | 16 ++---- resources/partials/document/footer.php | 15 ++++++ resources/partials/document/head.php | 6 +++ 14 files changed, 228 insertions(+), 32 deletions(-) delete mode 100755 app/Http/Middlewares/.gitkeep create mode 100755 app/Http/Middlewares/Document.php create mode 100755 app/Http/Middlewares/Nav.php create mode 100755 config/navigation.php create mode 100755 resources/partials/document/footer.php create mode 100755 resources/partials/document/head.php diff --git a/app/Http/Middlewares/.gitkeep b/app/Http/Middlewares/.gitkeep deleted file mode 100755 index 67f8245..0000000 --- a/app/Http/Middlewares/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -This file is used to keep the directory structure \ No newline at end of file diff --git a/app/Http/Middlewares/Document.php b/app/Http/Middlewares/Document.php new file mode 100755 index 0000000..21bc070 --- /dev/null +++ b/app/Http/Middlewares/Document.php @@ -0,0 +1,67 @@ +provider = $provider; + } + + /** + * Will load before the controllers + * @param ResponseInterface $response + * @param RequestInterface $request + * @return ResponseInterface|void + */ + public function before(ResponseInterface $response, RequestInterface $request) + { + } + + /** + * Add head to the document + * @param ResponseInterface $response + * @param RequestInterface $request + * @return ResponseInterface|void + */ + public function head(ResponseInterface $response, RequestInterface $request) + { + // Partial in document director + // The exclamation character will disable thrown error, if you remove the partial template file. + $this->provider->view()->setPartial("head.!document/head"); + + } + + /** + * Add footer to the document + * @param ResponseInterface $response + * @param RequestInterface $request + * @return ResponseInterface|void + */ + public function footer(ResponseInterface $response, RequestInterface $request) + { + // Partial in document director + // The exclamation character will disable thrown error, if you remove the partial template file. + $this->provider->view()->setPartial("footer.!document/footer"); + + } + + /** + * Will load after the controllers + * @param ResponseInterface $response + * @param RequestInterface $request + * @return ResponseInterface|void + */ + public function after(ResponseInterface $response, RequestInterface $request) + { + + } +} diff --git a/app/Http/Middlewares/Nav.php b/app/Http/Middlewares/Nav.php new file mode 100755 index 0000000..bba67f5 --- /dev/null +++ b/app/Http/Middlewares/Nav.php @@ -0,0 +1,74 @@ +provider = $provider; + $this->nav = $nav; + } + + /** + * Before controllers + * @param ResponseInterface $response + * @param RequestInterface $request + * @return ResponseInterface|void + */ + public function before(ResponseInterface $response, RequestInterface $request) + { + + // You can use this middelware to create an dynamic navigation + // The id is not required, but will create it´s own id with increment, starting from 1 if not filled in. + // The id is used to select parent! + $this->nav->add([ + "id" => 1, + "name" => "Start", + "slug" => "", + "parent" => 0, + "title" => "Meta title start", + "description" => "Meta description start" + + ])->add([ + "id" => 2, + "name" => "Contact", + "slug" => "contact", + "parent" => 0, + "title" => "Meta title contact", + "description" => "Meta description contact" + ]); + + // Will build the navigation + return parent::before($response, $request); + } + + /** + * After controllers + * @param ResponseInterface $response + * @param RequestInterface $request + * @return void + */ + public function after(ResponseInterface $response, RequestInterface $request) + { + } + + +} diff --git a/app/Http/Routes/web.php b/app/Http/Routes/web.php index 40a7215..79c6c66 100755 --- a/app/Http/Routes/web.php +++ b/app/Http/Routes/web.php @@ -32,9 +32,8 @@ // Open up a SESSION $routes->group(function ($routes) { - // With session now open we can handle the Login form and it's requests - + // Public login area $routes->group(function ($routes) { @@ -47,20 +46,13 @@ // Login request $routes->post("/{page:login}", ['Http\Controllers\Private\Login', "login"]); - // Forgot + // Forgot password $routes->get("/{page:login}/{type:forgot}", ['Http\Controllers\Private\Login', 'forgotPasswordForm']); $routes->post("/{page:login}/{type:forgot}", ['Http\Controllers\Private\Login', 'forgotPasswordPost']); // Change password - $routes->get("/{page:login}/{type:reset}/{token:[^/]+}", [ - 'Http\Controllers\Private\Login', - "resetPasswordForm" - ]); - - $routes->post("/{page:login}/{type:reset}/{token:[^/]+}", [ - 'Http\Controllers\Private\Login', - "resetPasswordPost" - ]); + $routes->get("/{page:login}/{type:reset}/{token:[^/]+}", ['Http\Controllers\Private\Login', "resetPasswordForm"]); + $routes->post("/{page:login}/{type:reset}/{token:[^/]+}", ['Http\Controllers\Private\Login', "resetPasswordPost"]); }, [ [MaplePHP\Foundation\Auth\Middleware\LoggedIn::class, "publicZone"], @@ -79,6 +71,7 @@ }, [ [MaplePHP\Foundation\Auth\Middleware\LoggedIn::class, "privateZone"] ]); + }, [ MaplePHP\Foundation\Auth\Middleware\SessionStart::class ]); @@ -86,5 +79,6 @@ }, [ MaplePHP\Foundation\Cache\Middleware\LastModified::class, MaplePHP\Foundation\Nav\Middleware\Navigation::class, - MaplePHP\Foundation\Dom\Middleware\Meta::class + MaplePHP\Foundation\Dom\Middleware\Meta::class, + [Http\Middlewares\Document::class, ["head", "footer"]], ]); diff --git a/app/Libraries/DTO b/app/Libraries/DTO index 0bb381d..2bf72c7 160000 --- a/app/Libraries/DTO +++ b/app/Libraries/DTO @@ -1 +1 @@ -Subproject commit 0bb381d6a8e5224fd28f8241b25b26ff32ff273a +Subproject commit 2bf72c7fbb0d3f4fdd800af61d1eea3338f4570c diff --git a/app/Libraries/Foundation b/app/Libraries/Foundation index e4f3ee5..2e7f6c7 160000 --- a/app/Libraries/Foundation +++ b/app/Libraries/Foundation @@ -1 +1 @@ -Subproject commit e4f3ee576fbad85699cedcca7bffe0e6a2935c39 +Subproject commit 2e7f6c76175ee3927673e544a23f1051663809ae diff --git a/app/Libraries/Handler b/app/Libraries/Handler index bd984a6..2fd347b 160000 --- a/app/Libraries/Handler +++ b/app/Libraries/Handler @@ -1 +1 @@ -Subproject commit bd984a62b63a416e4220666e2b9f58ea557053de +Subproject commit 2fd347b11a655cd3d9d6b23e8bce72442fbb0f02 diff --git a/app/Libraries/Output b/app/Libraries/Output index 8021d82..7b2a634 160000 --- a/app/Libraries/Output +++ b/app/Libraries/Output @@ -1 +1 @@ -Subproject commit 8021d82cc739fd2dd5715b6d30dc105bbd0b3616 +Subproject commit 7b2a6345d2163d5fe642bf9d27cc70a820290bf7 diff --git a/config/app.php b/config/app.php index ab1a89d..f458d5d 100755 --- a/config/app.php +++ b/config/app.php @@ -13,12 +13,18 @@ 'debug' => 1, 'charset' => 'UTF-8', 'ssl' => 1, - 'lang' => 'sv', + 'lang' => 'en', 'public_dir' => 'public/', 'version' => '4.0.0', 'bundle' => $this->getenv("NONCE"), 'maintainer' => 'John Doe ' ], + 'configs' => [ + 'database', + 'navigation', + 'providers', + 'routers' + ], 'session' => [ "time" => 360, // minutes "ssl" => 1 // Strict: SSL only flag diff --git a/config/navigation.php b/config/navigation.php new file mode 100755 index 0000000..507da94 --- /dev/null +++ b/config/navigation.php @@ -0,0 +1,42 @@ + [ + 'main' => [ + [ + "id" => 1, + "name" => "Start", + "slug" => "", + "parent" => 0, + "title" => false, + "description" => "Lorem ipsum dolor" + ], + [ + "id" => 2, + "name" => "About", + "slug" => "about", + "parent" => 0, + "title" => "About us", + "description" => "Lorem ipsum dolor" + ], + [ + "id" => 3, + "name" => "Contact", + "slug" => "contact", + "parent" => 0, + "title" => "Contact us", + "description" => "Lorem ipsum dolor" + ] + ] + ] +]; diff --git a/public/index.php b/public/index.php index b765439..610dbe2 100755 --- a/public/index.php +++ b/public/index.php @@ -1,4 +1,7 @@ -"> + - "> - - container->has("head")) { - echo $obj->container->get("head")->execute(); - } ?> - getCss("style.css?bundle=" . getenv("APP_BUNDLE")); ?>"> + partial("head")->get(); ?> partial("navigation")->get(); ?>
view()->get($args); ?>
-
-
- container->has("foot")) { - echo $obj->container->get("foot")->execute(); - } ?> - + partial("footer")->get(); ?> \ No newline at end of file diff --git a/resources/partials/document/footer.php b/resources/partials/document/footer.php new file mode 100755 index 0000000..1fee2ea --- /dev/null +++ b/resources/partials/document/footer.php @@ -0,0 +1,15 @@ + +
+ provider()->date()->format("Y"); ?> provider()->env("APP_NAME"); ?> +
+
+ +provider()->has("foot")) { + echo $this->provider()->get("foot")->execute(); +} +// Get url to development or production javascript file +$src = $this->provider()->get("url")->getJs("main.js", $this->provider()->env("APP_ENV")->compare("production")); +?> + \ No newline at end of file diff --git a/resources/partials/document/head.php b/resources/partials/document/head.php new file mode 100755 index 0000000..0872268 --- /dev/null +++ b/resources/partials/document/head.php @@ -0,0 +1,6 @@ +"> + +provider()->has("head")) { + echo $this->provider()->get("head")->execute(); +} ?> +getCss("style.css?bundle=" . getenv("APP_BUNDLE")); ?>"> \ No newline at end of file From 047c436476f7efb2557597981b0ee6708740e052 Mon Sep 17 00:00:00 2001 From: Wazabii Date: Thu, 28 Dec 2023 14:35:19 +0100 Subject: [PATCH 06/28] Minor patch --- app/Libraries/Foundation | 2 +- public/index.php | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/Libraries/Foundation b/app/Libraries/Foundation index 2e7f6c7..113d6ae 160000 --- a/app/Libraries/Foundation +++ b/app/Libraries/Foundation @@ -1 +1 @@ -Subproject commit 2e7f6c76175ee3927673e544a23f1051663809ae +Subproject commit 113d6aed74fb03e21ae4414a51ddf88d01823f52 diff --git a/public/index.php b/public/index.php index 610dbe2..b765439 100755 --- a/public/index.php +++ b/public/index.php @@ -1,7 +1,4 @@ Date: Mon, 1 Jan 2024 11:50:56 +0100 Subject: [PATCH 07/28] Nav improvements --- app/Http/Controllers/Examples/Pages.php | 34 +++++++-- app/Http/Middlewares/Document.php | 24 ++++++- app/Http/Middlewares/Nav.php | 5 +- app/Http/Routes/web.php | 15 ++-- app/Libraries/Foundation | 2 +- app/Libraries/Handler | 2 +- app/Libraries/Nest | 2 +- app/Libraries/Output | 2 +- config/navigation.php | 71 +++++++++++++------ resources/partials/document/footer.php | 5 +- .../partials/{ => document}/navigation.php | 4 +- resources/partials/ingress.php | 2 +- resources/partials/text.php | 1 - 13 files changed, 118 insertions(+), 51 deletions(-) rename resources/partials/{ => document}/navigation.php (78%) diff --git a/app/Http/Controllers/Examples/Pages.php b/app/Http/Controllers/Examples/Pages.php index cb8ecdc..98ee8d8 100755 --- a/app/Http/Controllers/Examples/Pages.php +++ b/app/Http/Controllers/Examples/Pages.php @@ -9,6 +9,7 @@ class Pages extends BaseController { + protected $provider; public function __construct(Provider $provider) @@ -24,13 +25,6 @@ public function __construct(Provider $provider) */ public function start(ResponseInterface $response, RequestInterface $request): ResponseInterface { - // Overwrite default meta - // Meta is propagated by Models/Navbar and then meta it self in the middleware "DomManipulation" where - // some standard DOM element is preset. - //$this->head()->getElement("title")->setValue("Welcome to my awesome app"); - //$this->head()->getElement("description")->attr("content", "Some text about my awesome app"); - - $this->provider->view()->setPartial("main.ingress", [ "tagline" => "Ingress view partial", "name" => "Welcome to MaplePHP", @@ -68,6 +62,10 @@ public function start(ResponseInterface $response, RequestInterface $request): R public function about(ResponseInterface $response, RequestInterface $request): ResponseInterface { + // Overwrite the default meta value + //$this->head()->getElement("title")->setValue("Welcome to my awesome app"); + //$this->head()->getElement("description")->attr("content", "Some text about my awesome app"); + // $this->view() is the same as $this->provider when extending to the BaseController!; $this->view()->setPartial("main.ingress", [ "tagline" => "Layered structure MVC framework", @@ -90,6 +88,28 @@ public function about(ResponseInterface $response, RequestInterface $request): R return $response; } + + /** + * The about page (see router) + * @param ResponseInterface $response PSR-7 Response + * @param RequestInterface $request PSR-7 Request + * @return ResponseInterface + */ + public function policy(ResponseInterface $response, RequestInterface $request): ResponseInterface + { + $this->view()->setPartial("main.text.integrity", [ + "name" => "Integrity policy", + "content" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam id sapien dui. Nullam gravida bibendum finibus. Pellentesque a elementum augue. Aliquam malesuada et neque ac varius. Nam id eros eros. Ut ut mattis ex. Aliquam molestie tortor quis ultrices euismod. Quisque blandit pellentesque purus, in posuere ex mollis ac." + ]); + + $this->view()->setPartial("main.text.cookie", [ + "name" => "Cookies", + "content" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam id sapien dui. Nullam gravida bibendum finibus. Pellentesque a elementum augue. Aliquam malesuada et neque ac varius. Nam id eros eros. Ut ut mattis ex. Aliquam molestie tortor quis ultrices euismod. Quisque blandit pellentesque purus, in posuere ex mollis ac." + ]); + + return $response; + } + /** * Will be invoked if method in router is missing * @param ResponseInterface $response diff --git a/app/Http/Middlewares/Document.php b/app/Http/Middlewares/Document.php index 21bc070..8518f32 100755 --- a/app/Http/Middlewares/Document.php +++ b/app/Http/Middlewares/Document.php @@ -6,14 +6,17 @@ use MaplePHP\Http\Interfaces\ResponseInterface; use MaplePHP\Http\Interfaces\RequestInterface; use MaplePHP\Foundation\Http\Provider; +use MaplePHP\Foundation\Nav\Navbar; class Document implements MiddlewareInterface { private $provider; + private $nav; - public function __construct(Provider $provider) + public function __construct(Provider $provider, Navbar $nav) { $this->provider = $provider; + $this->nav = $nav; } /** @@ -40,6 +43,21 @@ public function head(ResponseInterface $response, RequestInterface $request) } + /** + * Add head to the document + * @param ResponseInterface $response + * @param RequestInterface $request + * @return ResponseInterface|void + */ + public function navigation(ResponseInterface $response, RequestInterface $request) + { + // Partial in document director + // The exclamation character will disable thrown error, if you remove the partial template file. + $this->provider->view()->setPartial("navigation.!document/navigation", [ + "nav" => $this->nav->get() + ]); + } + /** * Add footer to the document * @param ResponseInterface $response @@ -50,7 +68,9 @@ public function footer(ResponseInterface $response, RequestInterface $request) { // Partial in document director // The exclamation character will disable thrown error, if you remove the partial template file. - $this->provider->view()->setPartial("footer.!document/footer"); + $this->provider->view()->setPartial("footer.!document/footer", [ + "nav" => $this->nav->get() + ]); } diff --git a/app/Http/Middlewares/Nav.php b/app/Http/Middlewares/Nav.php index bba67f5..a6bf0d6 100755 --- a/app/Http/Middlewares/Nav.php +++ b/app/Http/Middlewares/Nav.php @@ -39,7 +39,7 @@ public function before(ResponseInterface $response, RequestInterface $request) // You can use this middelware to create an dynamic navigation // The id is not required, but will create it´s own id with increment, starting from 1 if not filled in. // The id is used to select parent! - $this->nav->add([ + $this->nav->add("main", [ "id" => 1, "name" => "Start", "slug" => "", @@ -47,7 +47,7 @@ public function before(ResponseInterface $response, RequestInterface $request) "title" => "Meta title start", "description" => "Meta description start" - ])->add([ + ])->add("main", [ "id" => 2, "name" => "Contact", "slug" => "contact", @@ -68,6 +68,7 @@ public function before(ResponseInterface $response, RequestInterface $request) */ public function after(ResponseInterface $response, RequestInterface $request) { + } diff --git a/app/Http/Routes/web.php b/app/Http/Routes/web.php index 79c6c66..a754104 100755 --- a/app/Http/Routes/web.php +++ b/app/Http/Routes/web.php @@ -17,25 +17,26 @@ */ $routes->group(function ($routes) { + // Will handle all HTTP request errors $routes->map("*", '[/{any:.*}]', ['Http\Controllers\HttpRequestError', "handleError"]); // Regular static example pages $routes->get("/", ['Http\Controllers\Examples\Pages', "start"]); $routes->get("/{page:about}", ['Http\Controllers\Examples\Pages', "about"]); + $routes->get("/{page:policy}", ['Http\Controllers\Examples\Pages', "policy"]); // Contact page with form $routes->get("/{page:contact}", ['Http\Controllers\Examples\ExampleForm', "contactFrom"]); $routes->get("/{page:contact}/{model:modal}", ['Http\Controllers\Examples\ExampleForm', "contactFormModal"]); $routes->post("/{page:contact}", ['Http\Controllers\Examples\ExampleForm', "post"]); - // Open up a SESSION $routes->group(function ($routes) { // With session now open we can handle the Login form and it's requests - // Public login area $routes->group(function ($routes) { + // Public login area // Regular page with form $routes->get("/{page:login}", ['Http\Controllers\Private\Login', "form"]); @@ -58,15 +59,14 @@ [MaplePHP\Foundation\Auth\Middleware\LoggedIn::class, "publicZone"], ]); - - // Private area (The user is logged in) $routes->group(function ($routes) { - // Logout the user - $routes->get("/{page:logout}", ['Http\Controllers\Private\Pages', "logout"]); + // Private area (The user is logged in) // Profile page $routes->get("/{profile:profile}", ['Http\Controllers\Private\Pages', "profile"]); + // Logout the user + $routes->get("/{page:logout}", ['Http\Controllers\Private\Pages', "logout"]); }, [ [MaplePHP\Foundation\Auth\Middleware\LoggedIn::class, "privateZone"] @@ -77,8 +77,7 @@ ]); }, [ + [Http\Middlewares\Document::class, ["after" => ["head", "navigation", "footer"]]], MaplePHP\Foundation\Cache\Middleware\LastModified::class, - MaplePHP\Foundation\Nav\Middleware\Navigation::class, MaplePHP\Foundation\Dom\Middleware\Meta::class, - [Http\Middlewares\Document::class, ["head", "footer"]], ]); diff --git a/app/Libraries/Foundation b/app/Libraries/Foundation index 113d6ae..ef993b5 160000 --- a/app/Libraries/Foundation +++ b/app/Libraries/Foundation @@ -1 +1 @@ -Subproject commit 113d6aed74fb03e21ae4414a51ddf88d01823f52 +Subproject commit ef993b55d05d06ab9a9a9441a6eb49b916b25b32 diff --git a/app/Libraries/Handler b/app/Libraries/Handler index 2fd347b..b0b7dad 160000 --- a/app/Libraries/Handler +++ b/app/Libraries/Handler @@ -1 +1 @@ -Subproject commit 2fd347b11a655cd3d9d6b23e8bce72442fbb0f02 +Subproject commit b0b7dadcc6134ab6e130dd02c83f05b853415e00 diff --git a/app/Libraries/Nest b/app/Libraries/Nest index 136a800..0a35343 160000 --- a/app/Libraries/Nest +++ b/app/Libraries/Nest @@ -1 +1 @@ -Subproject commit 136a8005f92d09a8fcc764bbfe8c4b24929361b4 +Subproject commit 0a35343a4b5292719db9ec9b3b536fcaf15e9513 diff --git a/app/Libraries/Output b/app/Libraries/Output index 7b2a634..49f616b 160000 --- a/app/Libraries/Output +++ b/app/Libraries/Output @@ -1 +1 @@ -Subproject commit 7b2a6345d2163d5fe642bf9d27cc70a820290bf7 +Subproject commit 49f616b3b353e885914eade31f865a1a1d849f64 diff --git a/config/navigation.php b/config/navigation.php index 507da94..c1f03a0 100755 --- a/config/navigation.php +++ b/config/navigation.php @@ -12,30 +12,55 @@ */ return [ 'navigation' => [ - 'main' => [ - [ - "id" => 1, - "name" => "Start", - "slug" => "", - "parent" => 0, - "title" => false, - "description" => "Lorem ipsum dolor" + 'config' => [ + 'maxLevel' => 0, // Maximum levels (0 = unlimited) + 'nestingSlug' => false, // Should slugs be nested? E.g. /about-us/history vs /history + 'where' => [] // Select data that should be visible. E.g. ['menu' => 1] will hide all that dooe not match + ], + 'data' => [ + "main" => [ + [ + "id" => 1, + "name" => "Start", + "slug" => "", + "parent" => 0, + "title" => false, + "description" => "Lorem ipsum dolor" + ], + [ + "id" => 2, + "name" => "About", + "slug" => "about", + "parent" => 0, + "title" => "About us", + "description" => "Lorem ipsum dolor" + ], + [ + "id" => 3, + "name" => "Contact", + "slug" => "contact", + "parent" => 0, + "title" => "Contact us", + "description" => "Lorem ipsum dolor" + ] ], - [ - "id" => 2, - "name" => "About", - "slug" => "about", - "parent" => 0, - "title" => "About us", - "description" => "Lorem ipsum dolor" - ], - [ - "id" => 3, - "name" => "Contact", - "slug" => "contact", - "parent" => 0, - "title" => "Contact us", - "description" => "Lorem ipsum dolor" + "footer" => [ + [ + "id" => 1, + "name" => "Integrity policy", + "slug" => "policy", + "parent" => 0, + "title" => "Integrity policy", + "description" => "Lorem ipsum dolor" + ], + [ + "id" => 2, + "name" => "Cookies", + "slug" => "policy", + "parent" => 0, + "title" => "Cookie policy", + "description" => "Lorem ipsum dolor" + ] ] ] ] diff --git a/resources/partials/document/footer.php b/resources/partials/document/footer.php index 1fee2ea..3f47b5f 100755 --- a/resources/partials/document/footer.php +++ b/resources/partials/document/footer.php @@ -1,5 +1,8 @@ -