PHP MVC 프레임워크에서 라우터 사용하기

index.php 파일의 현재 내용을 다시 살펴보겠습니다:

index.php<?php
  namespace Core;
  
  error_reporting(E_ALL);
  ini_set('display_errors', 'on');
  
  spl_autoload_register(function($class) {
    // 자동 로드 구현
  });
  
  $routes = require $_SERVER['DOCUMENT_ROOT'] . '/project/config/routes.php';
?>

이제 index.php에서 다음과 같이 라우터를 사용하려고 합니다:

index.php<?php
  $router = new Router();
  $track  = $router->getTrack($routes, $_SERVER['REQUEST_URI']);
?>

더 간결하게 다시 작성할 수 있습니다:

index.php<?php
  $track = ( new Router ) -> getTrack($routes, $_SERVER['REQUEST_URI']);
?>