parent
14b14bcc46
commit
14524359d7
@ -0,0 +1,24 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types = 1); |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Robert Strutts <Bob_586@Yahoo.com> |
||||||
|
* @copyright (c) 2025, Robert Strutts |
||||||
|
* @license MIT |
||||||
|
*/ |
||||||
|
namespace Project\classes; |
||||||
|
|
||||||
|
use \CodeHydrater\http\request as Request; |
||||||
|
use \CodeHydrater\http\response as Response; |
||||||
|
|
||||||
|
class example_middleware { |
||||||
|
public function __invoke(Request $request, Response $response, $next) { |
||||||
|
$response = $next($request, $response); |
||||||
|
|
||||||
|
// After controller |
||||||
|
$response->set_content($response->get_content() . "\n<!-- Served by ExampleMiddleware -->"); |
||||||
|
|
||||||
|
return $response; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,44 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types = 1); |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Robert Strutts <Bob_586@Yahoo.com> |
||||||
|
* @copyright (c) 2025, Robert Strutts |
||||||
|
* @license MIT |
||||||
|
*/ |
||||||
|
namespace Project\classes; |
||||||
|
|
||||||
|
use \CodeHydrater\http\service_provider as ServiceProvider; |
||||||
|
use \CodeHydrater\http\kernel as Kernel; |
||||||
|
use \CodeHydrater\http\request as Request; |
||||||
|
use \CodeHydrater\http\response as Response; |
||||||
|
use \CodeHydrater\router as Router; |
||||||
|
use \CodeHydrater\app as App; |
||||||
|
|
||||||
|
/** |
||||||
|
* Description of route_service_provider |
||||||
|
* Setup Router and Controllers |
||||||
|
* |
||||||
|
* @author Robert Strutts <Bob_586@Yahoo.com> |
||||||
|
*/ |
||||||
|
class route_service_provider extends ServiceProvider { |
||||||
|
protected Kernel $kernel; |
||||||
|
|
||||||
|
public function __construct(Kernel $kernel) { |
||||||
|
$this->kernel = $kernel; |
||||||
|
} |
||||||
|
|
||||||
|
public function register(): void { |
||||||
|
// Add router middleware |
||||||
|
$this->kernel->add_middleware(function (Request $request, Response $response, $next) { |
||||||
|
$returned_route = Router::execute($request, $response); |
||||||
|
if ($returned_route["found"] === false) { |
||||||
|
$app = new App(); |
||||||
|
return $app->load_controller($request, $response); |
||||||
|
} else { |
||||||
|
return $returned_route['returned']; |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types = 1); |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Robert Strutts <Bob_586@Yahoo.com> |
||||||
|
* @copyright (c) 2025, Robert Strutts |
||||||
|
* @license MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
use CodeHydrater\bootstrap\registry as Reg; |
||||||
|
use CodeHydrater\bootstrap\configure as Config; |
||||||
|
|
||||||
|
Reg::get('di')->register('sessions', function() { |
||||||
|
$running = Reg::get('sessions_started') ?? false; |
||||||
|
if ($running === false) { |
||||||
|
$options = Config::get('sessions') ?? []; |
||||||
|
\CodeHydrater\session_management::start($options); |
||||||
|
|
||||||
|
Reg::set('sessions_started', true); |
||||||
|
} |
||||||
|
}); |
||||||
Loading…
Reference in new issue