base_controller

main
Robert 4 months ago
parent 19fdd5131c
commit 9532b5d2d9
  1. 2
      protected/src/configs/on_remove_request_vars.php
  2. 9
      protected/src/controllers/app/cookie_ctrl.php
  3. 28
      protected/src/controllers/app/home_ctrl.php
  4. 14
      protected/src/controllers/app/jwt_ctrl.php
  5. 9
      protected/src/controllers/app/protected_ctrl.php
  6. 4
      public/index.php

@ -9,5 +9,3 @@ declare(strict_types=1);
*/ */
unset($_REQUEST); // Request is dangerious as order of Vars is not Known unset($_REQUEST); // Request is dangerious as order of Vars is not Known
unset($_GET); // Super Globals are not Filtered, so unset them
unset($_POST);

@ -9,12 +9,13 @@ declare(strict_types = 1);
*/ */
namespace Project\controllers\app; namespace Project\controllers\app;
use \CodeHydrater\http\request as Request; use \CodeHydrater\base_controller;
use \CodeHydrater\http\response as Response; use \CodeHydrater\http\response as Response;
use \CodeHydrater\enums\exit_on_dump as endDump;
class cookie_ctrl { class cookie_ctrl extends base_controller {
public function __construct(private Request $request, private Response $response) { public function init() {
\CodeHydrater\security::init_sessions(); // Init Sessions \CodeHydrater\security::init_sessions(); // Init Sessions
} }
@ -27,7 +28,7 @@ class cookie_ctrl {
} }
public function read(): Response { public function read(): Response {
var_dump($_SESSION); dd($_SESSION, endDump::keep_working);
// var_dump($_SESSION['admin'] ?? ""); // var_dump($_SESSION['admin'] ?? "");
return $this->response; return $this->response;
} }

@ -9,18 +9,18 @@ declare(strict_types = 1);
*/ */
namespace Project\controllers\app; namespace Project\controllers\app;
use \CodeHydrater\base_controller;
use \CodeHydrater\enums\view_type as ViewType; use \CodeHydrater\enums\view_type as ViewType;
use \CodeHydrater\http\request as Request;
use \CodeHydrater\http\response as Response; use \CodeHydrater\http\response as Response;
/** /**
* Description of home_ctrl URL Route: /FOLDER/FILE/METHOD * Description of home_ctrl URL Route: /FOLDER/FILE/METHOD
* /app/home/name_demo * /app/home/name_demo
*/ */
class home_ctrl { class home_ctrl extends base_controller {
private $footer; private $footer;
public function __construct(private Request $request, private Response $response) { public function init() {
// FROM on_footer_banner.php in the configs folder... // FROM on_footer_banner.php in the configs folder...
if (function_exists("\Project\get_footer")) { if (function_exists("\Project\get_footer")) {
$this->footer = \Project\get_footer(); $this->footer = \Project\get_footer();
@ -30,16 +30,14 @@ class home_ctrl {
} }
public function index(): Response { public function index(): Response {
$html = new \CodeHydrater\html_document(); $this->html->set_footer($this->footer);
$html->set_footer($this->footer); $this->html->set_author("Robert Strutts, plus ME!");
$html->set_author("Robert Strutts, plus ME!");
$view = new \CodeHydrater\view(); $this->view->set('html', $this->html);
$view->set('html', $html); $this->view->set_template('main');
$view->set_template('main'); $this->view->include("app/header", ViewType::PHP);
$view->include("app/header", ViewType::PHP); $this->view->include("app/footer", ViewType::PHP);
$view->include("app/footer", ViewType::PHP); $content = $this->view->fetch($this, "app/home_index", ViewType::PHP);
$content = $view->fetch($this, "app/home_index", ViewType::PHP);
$this->response->set_content($content); $this->response->set_content($content);
return $this->response; return $this->response;
@ -58,13 +56,11 @@ class home_ctrl {
public function liquid(): Response { public function liquid(): Response {
echo $this->footer; echo $this->footer;
$this->view->set('template_assigns', [
$view = new \CodeHydrater\view();
$view->set('template_assigns', [
'name' => "James Smith", 'name' => "James Smith",
'date' => date('Y-m-d') 'date' => date('Y-m-d')
]); ]);
$content = $view->fetch($this, "app/liquid", ViewType::LIQUID); $content = $this->view->fetch($this, "app/liquid", ViewType::LIQUID);
$this->response->set_content($content); $this->response->set_content($content);
return $this->response; return $this->response;

@ -8,15 +8,15 @@ declare(strict_types = 1);
* @license MIT * @license MIT
*/ */
namespace Project\controllers\app; namespace Project\controllers\app;
use \CodeHydrater\base_controller;
use CodeHydrater\bootstrap\registry as Reg; use CodeHydrater\bootstrap\registry as Reg;
use \CodeHydrater\http\request as Request;
use \CodeHydrater\http\response as Response; use \CodeHydrater\http\response as Response;
use \CodeHydrater\enums\exit_on_dump as endDump;
class jwt_ctrl { class jwt_ctrl extends base_controller {
public function __construct(private Request $request, private Response $response) { }
public function index() { public function index(): Response {
// Payload data (customize as needed) // Payload data (customize as needed)
$payload = [ $payload = [
'iss' => 'your-issuer', // Issuer 'iss' => 'your-issuer', // Issuer
@ -36,7 +36,7 @@ class jwt_ctrl {
return $this->response; return $this->response;
} }
public function read(array $p) { public function read(array $p): Response {
$token = $p['token'] ?? false; $token = $p['token'] ?? false;
if ($token === false) { if ($token === false) {
echo "Sorry, no token in URL"; echo "Sorry, no token in URL";
@ -44,7 +44,7 @@ class jwt_ctrl {
} }
try { try {
\CodeHydrater\common::dump(Reg::get('di')->get_service('JWT_Decode', $token)); \CodeHydrater\common::dump(Reg::get('di')->get_service('JWT_Decode', $token), endDump::keep_working);
} catch (\Exception $e) { } catch (\Exception $e) {
echo "Invalid token: " . $e->getMessage(); echo "Invalid token: " . $e->getMessage();
} }

@ -8,22 +8,23 @@ declare(strict_types = 1);
* @license MIT * @license MIT
*/ */
namespace Project\controllers\app; namespace Project\controllers\app;
use \CodeHydrater\http\request as Request;
use \CodeHydrater\base_controller;
use \CodeHydrater\http\response as Response; use \CodeHydrater\http\response as Response;
/** /**
* Description of protected_ctrl * Description of protected_ctrl
* *
* to test auth middleware
*
* @author Robert Strutts <Bob_586@Yahoo.com> * @author Robert Strutts <Bob_586@Yahoo.com>
*/ */
class protected_ctrl { class protected_ctrl extends base_controller {
public static array $middleware = [ public static array $middleware = [
\Project\classes\auth_middleware::class \Project\classes\auth_middleware::class
]; ];
public function __construct(private Request $request, private Response $response) { }
public function index(): Response { public function index(): Response {
$this->response->set_content("Coool!"); $this->response->set_content("Coool!");
return $this->response; return $this->response;

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
use CodeHydrater\enums\exit_on_dump as endDump;
/** /**
* @author Robert Strutts <Bob_586@Yahoo.com> * @author Robert Strutts <Bob_586@Yahoo.com>
* @copyright (c) 2025, Robert Strutts * @copyright (c) 2025, Robert Strutts
@ -19,7 +21,7 @@ CodeHydrater\bootstrap\site_helper::init(CodeHydrater_PROJECT, $_SERVER['REQUEST
require_once CodeHydrater_FRAMEWORK . "bootstrap/main.php"; require_once CodeHydrater_FRAMEWORK . "bootstrap/main.php";
function dd($var = 'nothing', $end = true) { function dd($var = 'nothing', endDump $end = endDump::exit_and_stop) {
\CodeHydrater\common::dump($var, $end); \CodeHydrater\common::dump($var, $end);
} }

Loading…
Cancel
Save