From 552afff483f25d7c7bbbac0bee46b350fdb00a7e Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 20 Jan 2026 16:48:13 -0500 Subject: [PATCH] more --- protected/src/Classes/BaseController.php | 16 +++--- .../src/Providers/RouteServiceProvider.php | 23 ++++---- protected/src/Services/on_App.php | 2 +- protected/src/Views/OnError/404Page.php | 52 +++++++++++++++++++ 4 files changed, 74 insertions(+), 19 deletions(-) create mode 100644 protected/src/Views/OnError/404Page.php diff --git a/protected/src/Classes/BaseController.php b/protected/src/Classes/BaseController.php index 2dd3152..2d21a1b 100644 --- a/protected/src/Classes/BaseController.php +++ b/protected/src/Classes/BaseController.php @@ -12,12 +12,16 @@ namespace Project\Classes; use IOcornerstone\Framework\Http\HttpFactory; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; +use IOcornerstone\Framework\{ + HtmlDocument, + View +}; class BaseController { public string $page_output = ''; // To keep views working...without Dynamic Variable Error! public static $params; // To keep Routes working... - public $http; + private $http; public $view; public $html; protected string $footer = ""; @@ -26,9 +30,9 @@ class BaseController public function __construct( public ServerRequestInterface $request ) { - $this->http = new HttpFactory(); -// $this->view = new \CodeHydrater\view(); -// $this->html = new \CodeHydrater\html_document(); + $this->http = new HttpFactory(); + $this->view = new View(); + $this->html = new HtmlDocument(); // If the child controller has an init() method, call it automatically if (method_exists($this, 'init')) { @@ -55,7 +59,7 @@ class BaseController $this->authors = ""; } - $this->html->set_footer($this->footer); - $this->html->set_author($this->authors); + $this->html->setFooter($this->footer); + $this->html->setAuthor($this->authors); } } diff --git a/protected/src/Providers/RouteServiceProvider.php b/protected/src/Providers/RouteServiceProvider.php index 289b3d1..acb9a60 100644 --- a/protected/src/Providers/RouteServiceProvider.php +++ b/protected/src/Providers/RouteServiceProvider.php @@ -22,22 +22,21 @@ final class RouteServiceProvider { $router->get('/posts{id:int?}', [CTRL\App\PostController::class, 'show']); -/* -$authMiddleware = function(ServerRequestInterface $request, RequestHandlerInterface $next) { - $token = $request->getHeaderLine('Authorization'); - if ($token !== 'secret') { - return (new HttpFactory())->createResponse(401, [], 'Unauthorized'); - } - return $next->handle($request); -}; - -$router->add('GET', '/dashboard', $handler, [$authMiddleware]); -*/ - $apiHandler = function(ServerRequestInterface $request, ?RequestHandlerInterface $next = null) use ($router) { + $apiHandler = function(ServerRequestInterface $request, ?RequestHandlerInterface $next = null) use ($router) { $id = $request->getAttribute('id'); // null or int return (new HttpFactory())->createResponse(200, [], "User ID#{$id}"); }; + + $authMiddleware = function(ServerRequestInterface $request, RequestHandlerInterface $next) { + $token = $request->getHeaderLine('Authorization'); + if ($token !== 'secret') { + return (new HttpFactory())->createResponse(401, [], 'Unauthorized'); + } + return $next->handle($request); + }; + + $router->add('GET', '/dashboard/{id:int}', $apiHandler, [$authMiddleware]); $router->add('GET', '/hello', function () { return (new HttpFactory())->createResponse(200, [], 'Hello World'); diff --git a/protected/src/Services/on_App.php b/protected/src/Services/on_App.php index c690786..10dac01 100644 --- a/protected/src/Services/on_App.php +++ b/protected/src/Services/on_App.php @@ -11,7 +11,7 @@ declare(strict_types=1); namespace IOcornerstone; use IOcornerstone\Framework\Registry as Reg; -use IOcornerstone\Framework\App; +use IOcornerstone\Framework\Http\App\App; use Psr\Http\Message\ResponseInterface; Reg::get('container')->set(App::class, function($c): App diff --git a/protected/src/Views/OnError/404Page.php b/protected/src/Views/OnError/404Page.php new file mode 100644 index 0000000..c87aeac --- /dev/null +++ b/protected/src/Views/OnError/404Page.php @@ -0,0 +1,52 @@ + + + + + + + + + + 404 Page not found! + + + +
+ Page not found. +

404 Page not found!

+

Our apologies for the temporary inconvenience.

+
+ + +