Robert 2 weeks ago
parent b858b3efff
commit 552afff483
  1. 16
      protected/src/Classes/BaseController.php
  2. 23
      protected/src/Providers/RouteServiceProvider.php
  3. 2
      protected/src/Services/on_App.php
  4. 52
      protected/src/Views/OnError/404Page.php

@ -12,12 +12,16 @@ namespace Project\Classes;
use IOcornerstone\Framework\Http\HttpFactory; use IOcornerstone\Framework\Http\HttpFactory;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use IOcornerstone\Framework\{
HtmlDocument,
View
};
class BaseController class BaseController
{ {
public string $page_output = ''; // To keep views working...without Dynamic Variable Error! public string $page_output = ''; // To keep views working...without Dynamic Variable Error!
public static $params; // To keep Routes working... public static $params; // To keep Routes working...
public $http; private $http;
public $view; public $view;
public $html; public $html;
protected string $footer = ""; protected string $footer = "";
@ -26,9 +30,9 @@ class BaseController
public function __construct( public function __construct(
public ServerRequestInterface $request public ServerRequestInterface $request
) { ) {
$this->http = new HttpFactory(); $this->http = new HttpFactory();
// $this->view = new \CodeHydrater\view(); $this->view = new View();
// $this->html = new \CodeHydrater\html_document(); $this->html = new HtmlDocument();
// If the child controller has an init() method, call it automatically // If the child controller has an init() method, call it automatically
if (method_exists($this, 'init')) { if (method_exists($this, 'init')) {
@ -55,7 +59,7 @@ class BaseController
$this->authors = ""; $this->authors = "";
} }
$this->html->set_footer($this->footer); $this->html->setFooter($this->footer);
$this->html->set_author($this->authors); $this->html->setAuthor($this->authors);
} }
} }

@ -22,22 +22,21 @@ final class RouteServiceProvider
{ {
$router->get('/posts{id:int?}', [CTRL\App\PostController::class, 'show']); $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 $id = $request->getAttribute('id'); // null or int
return (new HttpFactory())->createResponse(200, [], "User ID#{$id}"); 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 () { $router->add('GET', '/hello', function () {
return (new HttpFactory())->createResponse(200, [], 'Hello World'); return (new HttpFactory())->createResponse(200, [], 'Hello World');

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace IOcornerstone; namespace IOcornerstone;
use IOcornerstone\Framework\Registry as Reg; use IOcornerstone\Framework\Registry as Reg;
use IOcornerstone\Framework\App; use IOcornerstone\Framework\Http\App\App;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
Reg::get('container')->set(App::class, function($c): App Reg::get('container')->set(App::class, function($c): App

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
/**
* @author Robert Strutts
* @copyright Copyright (c) 2022, Robert Strutts.
* @license MIT
*/
$protocol = "HTTP/1.0";
if ( "HTTP/1.1" == $_SERVER["SERVER_PROTOCOL"] ) {
$protocol = "HTTP/1.1";
}
header( "{$protocol} 404 Not Found", true, 404 );
header('Content-type: text/html; charset=utf-8');
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="language" content="english">
<meta name="robots" content="no-follow">
<link rel="shortcut icon" href="/assets/favicon/favicon.ico">
<title>404 Page not found!</title>
<style>
@media only screen and (max-width: 600px) {
#nopage {
height: 150px;
width: 300px;
}
}
@media only screen and (min-width: 600px) {
#nopage {
height: 500px;
width: 1500px;
}
}
</style>
</head>
<body>
<div id="wrap">
<img src="/assets/images/404page.jpg" alt="Page not found." id="nopage"/>
<header><h1>404 Page not found!<h1></header>
<h3>Our apologies for the temporary inconvenience.</h3>
</div>
</body>
</html>
<?php
exit;
Loading…
Cancel
Save