/** * Process the Request object and call the correct methods to display the response. * * @param Request $request * * @throws InvalidTypeException * @throws NotExistsException */ public function handleRequest(Request $request) { $router = $this->masterFactory->getHttpFactory()->getRouter(); $router->parseUrl($request->getUrl()); $request->addData($router->getQueryData()); $builder = $this->masterFactory->getHttpFactory()->getControllerBuilder($request, $router); $builder->build(); $controller = $builder->getController(); $action = $builder->getAction(); // Call action and get the response /** @var Response $response */ $response = call_user_func_array([$controller, Controller::HANDLE], [$action]); // Send headers if (headers_sent() === false) { header(sprintf('Status: %s', Response::getMessageForCode($response->getStatus()))); http_response_code($response->getStatus()); // Send headers foreach ($response->getHeaders() as $name => $value) { header("{$name}: {$value}", false); } } // Print the body echo $response->getBody(); }
/** * @dataProvider isMethodDataProvider * @param string $actualMethod * @param string $requestedMethod * @param bool $expected */ public function testIsMethod($actualMethod, $requestedMethod, $expected) { $_SERVER['REQUEST_METHOD'] = $requestedMethod; $request = new Request(''); $this->assertEquals($expected, $request->isMethod($actualMethod)); }