2024-07-29 15:57:20 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace kernel;
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-13 16:51:41 +03:00
|
|
|
use kernel\helpers\Debug;
|
|
|
|
use kernel\services\ModuleService;
|
2024-07-29 15:57:20 +03:00
|
|
|
use Phroute\Phroute\Dispatcher;
|
|
|
|
|
|
|
|
class App
|
|
|
|
{
|
|
|
|
|
|
|
|
static string $responseType = ResponseType::TEXT_HTML;
|
|
|
|
|
|
|
|
static CgRouteCollector $collector;
|
|
|
|
|
|
|
|
static Header $header;
|
|
|
|
|
2024-09-13 16:51:41 +03:00
|
|
|
public ModuleService $moduleService;
|
|
|
|
|
2024-07-29 15:57:20 +03:00
|
|
|
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();
|
2024-07-30 12:27:44 +03:00
|
|
|
|
|
|
|
//header('Content-Type: ' . App::$responseType);
|
2024-07-29 15:57:20 +03:00
|
|
|
echo $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function load(): static
|
|
|
|
{
|
2024-09-13 16:51:41 +03:00
|
|
|
$this->moduleService = new ModuleService();
|
2024-07-29 15:57:20 +03:00
|
|
|
App::$collector = new CgRouteCollector();
|
|
|
|
$this->setRouting();
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRouting(): void
|
|
|
|
{
|
2024-09-03 16:29:44 +03:00
|
|
|
include KERNEL_DIR . "/routs/admin.php";
|
2024-07-29 15:57:20 +03:00
|
|
|
include ROOT_DIR . "/rout.php";
|
2024-09-13 16:51:41 +03:00
|
|
|
$modules_routs = $this->moduleService->getModulesRouts();
|
|
|
|
foreach ($modules_routs as $rout){
|
|
|
|
include "$rout";
|
|
|
|
}
|
2024-07-29 15:57:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function create(): App
|
|
|
|
{
|
|
|
|
return new self();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|