Raml\Validator\ValidatorSchemaHelper::getResponseHeaders PHP Метод

getResponseHeaders() публичный Метод

public getResponseHeaders ( string $method, string $path, integer $statusCode, boolean $requiredOnly = false ) : Raml\NamedParameter[]
$method string
$path string
$statusCode integer
$requiredOnly boolean
Результат Raml\NamedParameter[]
    public function getResponseHeaders($method, $path, $statusCode, $requiredOnly = false)
    {
        $schema = $this->getResponse($method, $path, $statusCode);
        $out = [];
        /** @var NamedParameter $header */
        foreach ($schema->getHeaders() as $header) {
            if ($requiredOnly && !$header->isRequired()) {
                continue;
            }
            $out[$header->getKey()] = $header;
        }
        return $out;
    }

Usage Example

 /**
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @throws ValidatorResponseException
  */
 private function assertValidHeaders(RequestInterface $request, ResponseInterface $response)
 {
     $method = $request->getMethod();
     $path = $request->getUri()->getPath();
     $statusCode = $response->getStatusCode();
     $schemaHeaders = $this->schemaHelper->getResponseHeaders($method, $path, $statusCode);
     /** @var NamedParameter $schemaHeader */
     foreach ($schemaHeaders as $schemaHeader) {
         $key = $schemaHeader->getKey();
         /** @var string[] $header */
         foreach ($response->getHeader($key) as $header) {
             foreach ($header as $headerValue) {
                 try {
                     $schemaHeader->validate($headerValue);
                 } catch (ValidationException $exception) {
                     $message = sprintf('Response header %s with value "%s" for %s %s ' . 'with status code %s does not match schema: %s', $key, $headerValue, strtoupper($method), $path, $statusCode, $exception->getMessage());
                     throw new ValidatorResponseException($message, 0, $exception);
                 }
             }
         }
     }
 }