Example #1
5
 /**
  * @param HttpRequest $httpRequest
  *
  * @return Response
  */
 public function handle(HttpRequest $httpRequest)
 {
     try {
         $routeParameters = $this->urlMatcher->matchRequest($httpRequest);
         $httpRequest->attributes->add($routeParameters);
         $request = $this->extractRequestFromRouteParameters($routeParameters);
         $controller = $this->extractControllerFromRouteParameters($routeParameters);
         return $controller->handleRequest($request, $this->serviceContainer);
     } catch (ValidationExceptionSet $exception) {
         return $this->errorResponseFactory->createBadRequestResponse($exception);
     } catch (BadRequestHttpException $exception) {
         return $this->errorResponseFactory->createBadRequestResponse($exception);
     } catch (NotFoundHttpException $exception) {
         return $this->errorResponseFactory->createNotFoundResponse($exception);
     } catch (MethodNotAllowedException $exception) {
         $exception = new MethodNotAllowedHttpException($exception->getAllowedMethods(), 'Used request method not allowed. Allowed: ' . implode(', ', $exception->getAllowedMethods()));
         return $this->errorResponseFactory->createMethodNotAllowedResponse($exception);
     } catch (\Exception $exception) {
         return $this->errorResponseFactory->createInternalServerErrorResponse($exception);
     }
 }
 /**
  * @param MethodNotAllowedHttpException $exception
  *
  * @return Response
  */
 public function createMethodNotAllowedResponse(MethodNotAllowedHttpException $exception)
 {
     $body = array('success' => false, 'error' => array('global' => $this->environmentDetectionService->isEnvironment(Environment::LOCAL) === true ? $exception->getMessage() : null));
     return new JsonResponse($body, Response::HTTP_METHOD_NOT_ALLOWED);
 }
 public function __construct($message = null, \Exception $previous = null, $code = 0)
 {
     $message = is_null($message) ? trans('Method Not Allowed') : $message;
     parent::__construct($message, $previous, $code);
 }
 /**
  * @dataProvider headerDataProvider
  */
 public function testHeadersSetter($headers)
 {
     $exception = new MethodNotAllowedHttpException(array('GET'));
     $exception->setHeaders($headers);
     $this->assertSame($headers, $exception->getHeaders());
 }
 public function whenNotAllowed(MethodNotAllowedHttpException $e)
 {
     $response = $this->createApiProblemResponse($e->getMessage(), Response::HTTP_METHOD_NOT_ALLOWED);
     $response->headers->add($e->getHeaders());
     return $response;
 }