Source of file Response.php

Size: 2,231 Bytes - Last Modified: 2018-11-03T09:50:48-04:00

G:/AdobeConnectClient/src/Connection/Curl/Response.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
<?php

namespace AdobeConnectClient\Connection\Curl;

use AdobeConnectClient\Connection\ResponseInterface;
use AdobeConnectClient\Connection\StreamInterface;
use AdobeConnectClient\Traits\HttpReasonPhrase;

/**
 * The server response for cURL Connection.
 */
class Response implements ResponseInterface
{
    use HttpReasonPhrase;

    /**
     * @var int The response status code
     */
    protected $statusCode = 0;

    /**
     * @var array An associative array
     */
    protected $headers = [];

    /**
     * @var StreamInterface The response body
     */
    protected $body = null;

    /**
     * Create the Response.
     *
     * @param int $statusCode The response status code
     * @param array $headers Associative array as name => value. Value is an array of strings
     * @param StreamInterface $body The response body
     */
    public function __construct($statusCode, array $headers, StreamInterface $body)
    {
        $this->statusCode = intval($statusCode);
        $this->headers = $headers;
        $this->body = $body;
    }

    /**
     * @inheritdoc
     */
    public function getStatusCode()
    {
        return $this->statusCode;
    }

    /**
     * @inheritdoc
     */
    public function getBody()
    {
        return $this->body;
    }

    /**
     * @inheritdoc
     */
    public function getHeaders()
    {
        return $this->headers;
    }

    /**
     * @inheritdoc
     */
    public function getHeader($name)
    {
        if (isset($this->headers[$name])) {
            return $this->headers[$name];
        }
        $name = $this->normalizeString($name);

        foreach ($this->headers as $header => $value) {
            if ($this->normalizeString($header) === $name) {
                return $value;
            }
        }
        return [];
    }

    /**
     * @inheritdoc
     */
    public function getHeaderLine($name)
    {
        return implode(', ', $this->getHeader($name));
    }

    /**
     * Normalize the string to compare with others strings
     *
     * @param string $string
     * @return string
     */
    protected function normalizeString($string)
    {
        return mb_strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $string));
    }
}