Ejemplo n.º 1
0
 protected function sendResponse(MethodAbstract $method, $response)
 {
     $statusCode = $this->response->getStatusCode();
     if (!empty($statusCode) && $method->hasResponse($statusCode)) {
         $schema = $method->getResponse($statusCode);
     } else {
         $schema = $this->getSuccessfulResponse($method, $statusCode);
     }
     if ($schema instanceof SchemaInterface) {
         $this->setResponseCode($statusCode);
         if ($schema->getDefinition()->getName() == self::SCHEMA_PASSTHRU) {
             $this->setBody($response);
         } else {
             $this->setBodyAs($response, $schema);
         }
     } else {
         $this->setResponseCode(204);
         $this->setBody('');
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns the successful response of an method or null if no is available
  *
  * @param \PSX\Api\Resource\MethodAbstract $method
  * @param integer $statusCode
  * @return \PSX\Data\SchemaInterface
  */
 protected function getSuccessfulResponse(MethodAbstract $method, &$statusCode)
 {
     $successCodes = [200, 201, 202, 203, 205, 207];
     foreach ($successCodes as $successCode) {
         if ($method->hasResponse($successCode)) {
             $statusCode = $successCode;
             return $method->getResponse($successCode);
         }
     }
     return null;
 }