/** * 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; }
public function addMethod(MethodAbstract $method) { $this->methods[$method->getName()] = $method; }
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); } } } } }
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(''); } }
/** * 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; }