34 lines
768 B
PHP
34 lines
768 B
PHP
<?php
|
|
|
|
namespace lib\Core;
|
|
|
|
use lib\Core\Router;
|
|
use lib\Core\Response;
|
|
|
|
abstract class App
|
|
{
|
|
protected function __construct()
|
|
{
|
|
// 초기화 작업
|
|
}
|
|
public function run(): void
|
|
{
|
|
$router = new Router();
|
|
// 기본 홈 라우트
|
|
$router->add('GET', '', function ($params) {
|
|
Response::text("홈 페이지");
|
|
});
|
|
require_once ROOT_PATH . '/lib/Configs/Route.php';
|
|
// CLI 요청인지 웹 요청인지에 따라 URI 파싱
|
|
$uri = php_sapi_name() === 'cli' ? $this->parseCliUri() : $_SERVER['REQUEST_URI'];
|
|
$method = php_sapi_name() === 'cli' ? 'GET' : $_SERVER['REQUEST_METHOD'];
|
|
$router->dispatch($uri, $method);
|
|
}
|
|
|
|
private function parseCliUri(): string
|
|
{
|
|
global $argv;
|
|
return $argv[1] ?? '';
|
|
}
|
|
}
|