39 lines
911 B
PHP
39 lines
911 B
PHP
<?php
|
|
|
|
namespace lib\Core;
|
|
|
|
use lib\Core\Router;
|
|
use lib\Core\Http\Response;
|
|
|
|
abstract class App
|
|
{
|
|
protected function __construct()
|
|
{
|
|
// 초기화 작업
|
|
}
|
|
public function run()
|
|
{
|
|
$router = new Router();
|
|
require_once APP_PATH . "Configs" . DIRECTORY_SEPARATOR . "Route.php";
|
|
// CLI 요청인지 웹 요청인지에 따라 URI 파싱
|
|
$uri = php_sapi_name() === 'cli' ? $this->parseCliUri() : $_SERVER['REQUEST_URI'];
|
|
$method = php_sapi_name() === 'cli' ? 'GET' : $_SERVER['REQUEST_METHOD'];
|
|
$response = $router->dispatch($uri, $method);
|
|
if ($response instanceof Response) {
|
|
$response->send();
|
|
} else {
|
|
echo $response; // 단순 string 반환일 경우 (fallback)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* CLI 요청에서 URI를 파싱하는 메서드
|
|
* @return string
|
|
*/
|
|
private function parseCliUri(): string
|
|
{
|
|
global $argv;
|
|
return $argv[1] ?? '';
|
|
}
|
|
}
|