Пример #1
0
 /**
  * Render an API Problem representation
  *
  * Also sets the $apiProblem member to the passed object.
  *
  * @param  ApiProblem $apiProblem
  * @return string
  */
 protected function renderApiProblem(ApiProblem $apiProblem)
 {
     $this->apiProblem = $apiProblem;
     if ($this->displayExceptions) {
         $apiProblem->setDetailIncludesStackTrace(true);
     }
     return parent::render($apiProblem->toArray());
 }
 /**
  * Retrieve the HTTP status from an ApiProblem object
  *
  * Ensures that the status falls within the acceptable range (100 - 599).
  *
  * @param  ApiProblem $problem
  * @return int
  */
 protected function getStatusCodeFromApiProblem(ApiProblem $problem)
 {
     $problemData = $problem->toArray();
     $status = array_key_exists('status', $problemData) ? $problemData['status'] : 0;
     if ($status < 100 || $status >= 600) {
         return 500;
     }
     return $status;
 }
 /**
  * @throws ApiProblem
  */
 public function bulkAction()
 {
     $data = $this->bodyParams();
     if (!is_array($data)) {
         $exception = new ApiProblem(500, 'Invalid body');
         return new JsonModel($exception->toArray());
     }
     $result = $this->bulkService->bulk($data);
     $response = new JsonModel($result);
     return $response;
 }
 public function deleteClientParamAction()
 {
     // get pass in params
     $data = $this->bodyParams();
     if (isset($data['account']) && isset($data['key'])) {
         try {
             // service
             $service = $this->sm->get('Lib\\Openvpn\\Service\\ClientConfig');
             $response = $service->deleteParam($data['account'], $data['key']);
         } catch (\Exception $e) {
             $this->getResponse()->setStatusCode(405);
             $response = new ApiProblem(405, 'Param key:[' . $data['key'] . '] has already deleted.');
         }
         // view
         return new ViewModel($response->toArray());
     }
 }
Пример #5
0
 /**
  * Constructor
  *
  * Create an instance using the provided information. If nothing is
  * provided for the type field, the class default will be used;
  * if the status matches any known, the title field will be selected
  * from $problemStatusTitles as a result.
  *
  * @param int    $status
  * @param string $detail
  * @param string $type
  * @param string $title
  * @param array  $additional
  *  @param \Zend\service  $oService
  */
 public function __construct($status, $detail, $type = null, $title = null, array $additional = [], $oService = null)
 {
     parent::__construct($status, $detail, $type, $title, $additional);
     $this->_oService = $oService;
     $additional['status'] = $status;
     $additional['type'] = $type;
     $additional['title'] = $title;
     $this->_getLogService()->log(LogService::ERR, $detail, LogService::LOGICIEL, $additional);
 }
 /**
  * Retrieve the content.
  *
  * Serializes the composed ApiProblem instance to JSON.
  *
  * @return string
  */
 public function getContent()
 {
     return json_encode($this->apiProblem->toArray(), $this->jsonFlags);
 }
Пример #7
0
 public function testUsesAdditionalDetailsFromExceptionWhenProvided()
 {
     $exception = new Exception\DomainException('exception message', 401);
     $exception->setAdditionalDetails(['foo' => 'bar']);
     $apiProblem = new ApiProblem('401', $exception);
     $payload = $apiProblem->toArray();
     $this->assertArrayHasKey('foo', $payload);
     $this->assertEquals('bar', $payload['foo']);
 }
 public function testApiProblemResponseBodyIsSerializedApiProblem()
 {
     $apiProblem = new ApiProblem(400, 'Random error');
     $response = new ApiProblemResponse($apiProblem);
     $this->assertEquals($apiProblem->toArray(), json_decode($response->getContent(), true));
 }