private function setNotAcceptableError(GetResponseEvent $event) { $responseFactory = new ResponseFactory($this->accept->getDefault()); $catalogResponse = new \Dafiti\Silex\Response(HttpFoundation\Response::HTTP_NOT_ACCEPTABLE); $response = $responseFactory->create($catalogResponse); $event->setResponse($response); $event->stopPropagation(); }
public function testCreateNotAcceptableShouldReturnResponse406() { $expectedStatusCode = HttpFoundation\Response::HTTP_NOT_ACCEPTABLE; $controllerResponse = new \Dafiti\Silex\Response($expectedStatusCode); $factory = new Factory('application/json'); $result = $factory->create($controllerResponse); $this->assertEquals($expectedStatusCode, $result->getStatusCode()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\JsonResponse', $result); }
/** * @param GetResponseForControllerResultEvent $event * * @return GetResponseForControllerResultEvent */ public function onKernelResponse(GetResponseForControllerResultEvent $event) { if ($event->hasResponse()) { return $event; } $accept = $event->getRequest()->get('_accept'); $responseFactory = new Factory($accept); $response = $responseFactory->create($event->getControllerResult()); $event->setResponse($response); return $event; }