public function execute(Request $request) { $this->trigger(self::BEFORE_EXECUTE_SERVICE, [$request, $this->response]); if (!$request->isAllowed()) { $this->trigger(self::NOT_ALLOWED, [$request, $this->response]); return null; } $class_name = String::underscoreToCamelCase($request->getService()); $group_name = $request->getGroup() ? String::underscoreToCamelCase($request->getGroup()) . '\\' : ''; $service_class = $this->getServicePrefix() . $group_name . $class_name; $this->validateClass($service_class); $reflector = new \ReflectionClass($service_class); $service = $reflector->newInstanceArgs([$request->getData(), $this->response]); $this->trigger(self::AFTER_EXECUTE_SERVICE, [$request, $this->response]); $this->routeRequest($request, $service); $this->response->render(); $this->trigger(self::REQUEST_COMPLETE, [$request, $this->response]); }
public function testSwapHeadersWithContentRendered() { $this->setExpectedException('RESTful\\Exception\\Response\\CanNotSwapResponseType'); $received_header = null; $this->response->addEventHandler(Response::HEADER_ADDED_EVENT, function (Response $response, $header) use(&$received_header) { $received_header = $header; }); $this->response->setResponseType(Response::HTML); $this->response->render(); $this->assertSame('Content-Type: text/html', $received_header); $this->response->setResponseType(Response::TEXT); }