Robert 4 months ago
parent 0d8a5de7ac
commit 6282694da2
  1. 8
      src/bootstrap/main.php
  2. 10
      src/classes/app.php
  3. 11
      src/classes/http/kernel.php
  4. 8
      src/classes/router.php
  5. 4
      src/classes/rss_feed.php
  6. 2
      src/classes/traits/security/session_hijacking_functions.php

@ -289,10 +289,4 @@ function is_live(): bool {
$live = errors::get_live_mode();
}
return (bool) $live;
}
$returned_route = \CodeHydrater\router::execute();
if ($returned_route["found"] === false) {
$app = new \CodeHydrater\app();
$app->load_controller();
}
}

@ -10,6 +10,8 @@ declare(strict_types=1);
namespace CodeHydrater;
use \CodeHydrater\http\request as Request;
use \CodeHydrater\http\response as Response;
use Exception;
class app {
@ -155,7 +157,7 @@ class app {
* @param string $method
* @retval type
*/
private function action(string $file, string $class, string $method, $params) {
private function action(Request $request, Response $response, string $file, string $class, string $method, $params) {
$safer_file = bootstrap\requires::safer_file_exists($file);
if (! $safer_file) {
$this->local404();
@ -168,7 +170,7 @@ class app {
$test = $this->get_ctrl_dir();
$call_class = "\\Project\\" . $test . 'controllers\\' . $class;
$controller = new $call_class();
$controller = new $call_class($request, $response);
if ($method === "error" && str_contains($class, "app") &&
method_exists($controller, $method) === false
@ -203,8 +205,8 @@ class app {
/**
* Does load controller by calling action
*/
public function load_controller() {
return $this->action($this->file, $this->class, $this->method, $this->params);
public function load_controller(Request $request, Response $response) {
return $this->action($request, $response, $this->file, $this->class, $this->method, $this->params);
}
} // end of app

@ -40,7 +40,7 @@ class kernel {
$this->middleware[] = $middleware;
}
public function handle(Request $request): Response {
public function handle(request $request): response {
try {
$response = $this->send_request_through_middleware($request);
return $response;
@ -49,12 +49,12 @@ class kernel {
}
}
protected function send_request_through_middleware(Request $request): Response
protected function send_request_through_middleware(request $request): response
{
$middleware_stack = $this->build_middleware_stack();
// Create initial response
$response = new Response();
$response = new response();
// Process the request through middleware
return $middleware_stack($request, $response);
@ -83,7 +83,7 @@ class kernel {
);
}
protected function handle_exception(\Throwable $e): Response {
protected function handle_exception(\Throwable $e): response {
// Basic exception handling - override in child class
$response = new response();
return $response
@ -91,8 +91,7 @@ class kernel {
->set_content('Server Error: ' . $e->getMessage());
}
public function run(): void
{
public function run(): void {
$request = $this->container->make(request::class);
$response = $this->handle($request);
$response->send();

@ -11,6 +11,9 @@ declare(strict_types=1);
namespace CodeHydrater;
use \CodeHydrater\http\request as Request;
use \CodeHydrater\http\response as Response;
class router
{
private static $instance = null;
@ -335,9 +338,8 @@ class router
/**
* Execute router
* @todo add Kernel/Requests...
*/
public static function execute() {
public static function execute(Request $my_request, Response $my_response) {
$ROOT = bootstrap\site_helper::get_root();
$request_uri = bootstrap\site_helper::get_uri();
$request_method = bootstrap\site_helper::get_method();
@ -427,7 +429,7 @@ class router
list($controller, $method) = explode('@', $route['action']);
// init new controller
$controller = new $controller;
$controller = new $controller($my_request, $my_response);
// Check if class has parent
$parentControllers = class_parents($controller);

@ -106,6 +106,10 @@ class rss_feed {
header('Content-Type: application/rss+xml; charset=utf-8');
echo $rss->saveXML();
}
public static function get_rss(\DOMDocument $rss): string {
return $rss->saveXML();
}
}

@ -11,7 +11,7 @@ namespace CodeHydrater\traits\security;
trait session_hijacking_functions {
public static function init() {
public static function init_sessions() {
if (\CodeHydrater\bootstrap\registry::get('di')->has('sessions')) {
\CodeHydrater\bootstrap\registry::get('di')->get_service('sessions');
}

Loading…
Cancel
Save