Exemplo n.º 1
0
 /**
  * Returns the successful response of an method or null if no is available
  *
  * @param \PSX\Api\Resource\MethodAbstract $method
  * @return \PSX\Data\SchemaInterface
  */
 protected function getSuccessfulResponse(MethodAbstract $method)
 {
     $responses = $method->getResponses();
     for ($i = 200; $i < 210; $i++) {
         if (isset($responses[$i])) {
             return $responses[$i];
         }
     }
     return null;
 }
Exemplo n.º 2
0
 public function addMethod(MethodAbstract $method)
 {
     $this->methods[$method->getName()] = $method;
 }
Exemplo n.º 3
0
Arquivo: Raml.php Projeto: seytar/psx
 protected function parseResponses(Resource\MethodAbstract $method, array $data)
 {
     if (isset($data['responses']) && is_array($data['responses'])) {
         foreach ($data['responses'] as $statusCode => $row) {
             if (isset($row['body']) && is_array($row['body'])) {
                 $schema = $this->getBodySchema($row['body']);
                 if ($schema instanceof SchemaInterface) {
                     $method->addResponse($statusCode, $schema);
                 }
             }
         }
     }
 }
Exemplo n.º 4
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('');
     }
 }
Exemplo n.º 5
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;
 }