MicroFrameWork/kernel/App.php
2024-09-13 16:51:41 +03:00

58 lines
1.2 KiB
PHP

<?php
namespace kernel;
use kernel\helpers\Debug;
use kernel\services\ModuleService;
use Phroute\Phroute\Dispatcher;
class App
{
static string $responseType = ResponseType::TEXT_HTML;
static CgRouteCollector $collector;
static Header $header;
public ModuleService $moduleService;
public static Database $db;
public function run(): void
{
$dispatcher = new Dispatcher(App::$collector->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
App::$header->set();
//header('Content-Type: ' . App::$responseType);
echo $response;
}
public function load(): static
{
$this->moduleService = new ModuleService();
App::$collector = new CgRouteCollector();
$this->setRouting();
return $this;
}
public function setRouting(): void
{
include KERNEL_DIR . "/routs/admin.php";
include ROOT_DIR . "/rout.php";
$modules_routs = $this->moduleService->getModulesRouts();
foreach ($modules_routs as $rout){
include "$rout";
}
}
public static function create(): App
{
return new self();
}
}