parent
14524359d7
commit
19fdd5131c
@ -1,44 +0,0 @@ |
|||||||
<?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,31 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types = 1); |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Robert Strutts <Bob_586@Yahoo.com> |
||||||
|
* @copyright (c) 2025, Robert Strutts |
||||||
|
* @license MIT |
||||||
|
*/ |
||||||
|
namespace Project\controllers\app; |
||||||
|
use \CodeHydrater\http\request as Request; |
||||||
|
use \CodeHydrater\http\response as Response; |
||||||
|
|
||||||
|
/** |
||||||
|
* Description of protected_ctrl |
||||||
|
* |
||||||
|
* @author Robert Strutts <Bob_586@Yahoo.com> |
||||||
|
*/ |
||||||
|
class protected_ctrl { |
||||||
|
|
||||||
|
public static array $middleware = [ |
||||||
|
\Project\classes\auth_middleware::class |
||||||
|
]; |
||||||
|
|
||||||
|
public function __construct(private Request $request, private Response $response) { } |
||||||
|
|
||||||
|
public function index(): Response { |
||||||
|
$this->response->set_content("Coool!"); |
||||||
|
return $this->response; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue