public function __invoke(Request $request, Response $response, callable $out = null)
 {
     $restResponseBuilder = new CASSResponseBuilder($response);
     $restResponseBuilder->getDecorators()->clear();
     $restResponseBuilder->setJson($this->apiDocsService->buildAPIDocs());
     $restResponseBuilder->setStatusSuccess();
     return $restResponseBuilder->build();
 }
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     try {
         $this->withProfileService->specifyProfile((int) $request->getAttribute('profileId'));
         return $out($request, $response);
     } catch (ProfileNotFoundException $e) {
         $responseBuilder = new CASSResponseBuilder($response);
         return $responseBuilder->setStatusNotAllowed()->setError($e)->build();
     }
 }
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     $isURLProtected = strpos($request->getUri()->getPath(), "/protected/") === 0;
     try {
         $this->currentAccountService->signInWithStrategies([new HeaderStrategy($request), new JSONBodyStrategy($request), new SessionStrategy($request)]);
     } catch (NotAuthenticatedException $e) {
         if ($isURLProtected) {
             $responseBuilder = new CASSResponseBuilder($response);
             return $responseBuilder->setStatusNotAllowed()->setError($e)->build();
         }
     }
     return $out($request, $response);
 }
Beispiel #4
0
 public function __invoke(Request $request, Response $response, $error)
 {
     $responseBuilder = new CASSResponseBuilder($response);
     $responseBuilder->setStatusBadRequest();
     if ($error === null) {
         $errorType = '404';
         $responseBuilder->setError($error);
         $responseBuilder->setStatusNotFound()->setError('404 Not Found');
     } else {
         if ($error instanceof \Exception) {
             $errorType = get_class($error);
             $responseBuilder->setError($error);
             try {
                 throw $error;
             } catch (EntityNotFoundException $e) {
                 $responseBuilder->setStatusNotFound();
             } catch (InvalidJSONSchema $e) {
                 $responseBuilder->setStatusBadRequest();
             } catch (BadCommandCallException $e) {
                 $responseBuilder->setStatusBadRequest();
             } catch (NotFoundException $e) {
                 $responseBuilder->setStatusNotFound();
             } catch (PermissionsDeniedException $e) {
                 $responseBuilder->setStatusNotAllowed();
             } catch (\Exception $e) {
                 $responseBuilder->setStatusInternalError();
             }
         } else {
             if ($error instanceof \Error) {
                 throw $error;
             } else {
                 if (is_int($error)) {
                     $errorType = "INT_CODE";
                     $responseBuilder->setError(sprintf("ErrorCode: %d", $error));
                 } else {
                     throw new \Exception(sprintf('Unknown error: %s', get_class($error)));
                 }
             }
         }
     }
     return $responseBuilder->setJson(['error_type' => $errorType])->build();
 }