routes[] = [ 'method' => $method, 'path' => $path, 'handler' => $handler ]; } public function dispatch(string $method, string $uri) { foreach ($this->routes as $route) { if ($route['method'] === $method && $route['path'] === $uri) { return \call_user_func($route['handler']); } } http_response_code(404); header('Content-Type: application/json'); echo json_encode(['error' => 'Not Found']); } }