vendor/store.shopware.com/nrlejpostdirektautocomplete/vendor/slim/psr7/src/Response.php line 21

Open in your IDE?
  1. <?php
  2. /**
  3.  * Slim Framework (https://slimframework.com)
  4.  *
  5.  * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
  6.  */
  7. declare (strict_types=1);
  8. namespace NRLEJPostDirektAutocomplete\Slim\Psr7;
  9. use NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface;
  10. use InvalidArgumentException;
  11. use Psr\Http\Message\ResponseInterface;
  12. use Psr\Http\Message\StreamInterface;
  13. use NRLEJPostDirektAutocomplete\Slim\Psr7\Factory\StreamFactory;
  14. use NRLEJPostDirektAutocomplete\Slim\Psr7\Interfaces\HeadersInterface;
  15. use function is_integer;
  16. use function is_object;
  17. use function is_string;
  18. use function method_exists;
  19. class Response extends \NRLEJPostDirektAutocomplete\Slim\Psr7\Message implements \Psr\Http\Message\ResponseInterface
  20. {
  21.     /**
  22.      * @var int
  23.      */
  24.     protected $status \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_OK;
  25.     /**
  26.      * @var string
  27.      */
  28.     protected $reasonPhrase '';
  29.     /**
  30.      * @var array
  31.      */
  32.     protected static $messages = [
  33.         // Informational 1xx
  34.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_CONTINUE => 'Continue',
  35.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_SWITCHING_PROTOCOLS => 'Switching Protocols',
  36.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_PROCESSING => 'Processing',
  37.         // Successful 2xx
  38.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_OK => 'OK',
  39.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_CREATED => 'Created',
  40.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_ACCEPTED => 'Accepted',
  41.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information',
  42.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_NO_CONTENT => 'No Content',
  43.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_RESET_CONTENT => 'Reset Content',
  44.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_PARTIAL_CONTENT => 'Partial Content',
  45.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_MULTI_STATUS => 'Multi-Status',
  46.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_ALREADY_REPORTED => 'Already Reported',
  47.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_IM_USED => 'IM Used',
  48.         // Redirection 3xx
  49.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_MULTIPLE_CHOICES => 'Multiple Choices',
  50.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_MOVED_PERMANENTLY => 'Moved Permanently',
  51.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_FOUND => 'Found',
  52.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_SEE_OTHER => 'See Other',
  53.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_NOT_MODIFIED => 'Not Modified',
  54.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_USE_PROXY => 'Use Proxy',
  55.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_RESERVED => '(Unused)',
  56.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_TEMPORARY_REDIRECT => 'Temporary Redirect',
  57.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_PERMANENT_REDIRECT => 'Permanent Redirect',
  58.         // Client Error 4xx
  59.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_BAD_REQUEST => 'Bad Request',
  60.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_UNAUTHORIZED => 'Unauthorized',
  61.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_PAYMENT_REQUIRED => 'Payment Required',
  62.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_FORBIDDEN => 'Forbidden',
  63.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_NOT_FOUND => 'Not Found',
  64.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED => 'Method Not Allowed',
  65.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_NOT_ACCEPTABLE => 'Not Acceptable',
  66.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required',
  67.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_REQUEST_TIMEOUT => 'Request Timeout',
  68.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_CONFLICT => 'Conflict',
  69.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_GONE => 'Gone',
  70.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_LENGTH_REQUIRED => 'Length Required',
  71.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_PRECONDITION_FAILED => 'Precondition Failed',
  72.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_PAYLOAD_TOO_LARGE => 'Request Entity Too Large',
  73.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_URI_TOO_LONG => 'Request-URI Too Long',
  74.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type',
  75.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable',
  76.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_EXPECTATION_FAILED => 'Expectation Failed',
  77.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_IM_A_TEAPOT => 'I\'m a teapot',
  78.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_MISDIRECTED_REQUEST => 'Misdirected Request',
  79.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY => 'Unprocessable Entity',
  80.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_LOCKED => 'Locked',
  81.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_FAILED_DEPENDENCY => 'Failed Dependency',
  82.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_UPGRADE_REQUIRED => 'Upgrade Required',
  83.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_PRECONDITION_REQUIRED => 'Precondition Required',
  84.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_TOO_MANY_REQUESTS => 'Too Many Requests',
  85.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large',
  86.         444 => 'Connection Closed Without Response',
  87.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_UNAVAILABLE_FOR_LEGAL_REASONS => 'Unavailable For Legal Reasons',
  88.         499 => 'Client Closed Request',
  89.         // Server Error 5xx
  90.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR => 'Internal Server Error',
  91.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_NOT_IMPLEMENTED => 'Not Implemented',
  92.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_BAD_GATEWAY => 'Bad Gateway',
  93.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_SERVICE_UNAVAILABLE => 'Service Unavailable',
  94.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_GATEWAY_TIMEOUT => 'Gateway Timeout',
  95.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_VERSION_NOT_SUPPORTED => 'HTTP Version Not Supported',
  96.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates',
  97.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_INSUFFICIENT_STORAGE => 'Insufficient Storage',
  98.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_LOOP_DETECTED => 'Loop Detected',
  99.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_NOT_EXTENDED => 'Not Extended',
  100.         \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required',
  101.         599 => 'Network Connect Timeout Error',
  102.     ];
  103.     /**
  104.      * @param int                   $status  The response status code.
  105.      * @param HeadersInterface|null $headers The response headers.
  106.      * @param StreamInterface|null  $body    The response body.
  107.      */
  108.     public function __construct(int $status \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_OK, ?\NRLEJPostDirektAutocomplete\Slim\Psr7\Interfaces\HeadersInterface $headers null, ?\Psr\Http\Message\StreamInterface $body null)
  109.     {
  110.         $this->status $this->filterStatus($status);
  111.         $this->headers $headers $headers : new \NRLEJPostDirektAutocomplete\Slim\Psr7\Headers([], []);
  112.         $this->body $body $body : (new \NRLEJPostDirektAutocomplete\Slim\Psr7\Factory\StreamFactory())->createStream();
  113.     }
  114.     /**
  115.      * This method is applied to the cloned object after PHP performs an initial shallow-copy.
  116.      * This method completes a deep-copy by creating new objects for the cloned object's internal reference pointers.
  117.      */
  118.     public function __clone()
  119.     {
  120.         $this->headers = clone $this->headers;
  121.     }
  122.     /**
  123.      * {@inheritdoc}
  124.      */
  125.     public function getStatusCode() : int
  126.     {
  127.         return $this->status;
  128.     }
  129.     /**
  130.      * {@inheritdoc}
  131.      */
  132.     public function withStatus($code$reasonPhrase '')
  133.     {
  134.         $code $this->filterStatus($code);
  135.         $reasonPhrase $this->filterReasonPhrase($reasonPhrase);
  136.         $clone = clone $this;
  137.         $clone->status $code;
  138.         $clone->reasonPhrase $reasonPhrase;
  139.         return $clone;
  140.     }
  141.     /**
  142.      * {@inheritdoc}
  143.      */
  144.     public function getReasonPhrase() : string
  145.     {
  146.         if ($this->reasonPhrase !== '') {
  147.             return $this->reasonPhrase;
  148.         }
  149.         if (isset(static::$messages[$this->status])) {
  150.             return static::$messages[$this->status];
  151.         }
  152.         return '';
  153.     }
  154.     /**
  155.      * Filter HTTP status code.
  156.      *
  157.      * @param  int $status HTTP status code.
  158.      *
  159.      * @return int
  160.      *
  161.      * @throws InvalidArgumentException If an invalid HTTP status code is provided.
  162.      */
  163.     protected function filterStatus($status) : int
  164.     {
  165.         if (!\is_integer($status) || $status \NRLEJPostDirektAutocomplete\Fig\Http\Message\StatusCodeInterface::STATUS_CONTINUE || $status 599) {
  166.             throw new \InvalidArgumentException('Invalid HTTP status code.');
  167.         }
  168.         return $status;
  169.     }
  170.     /**
  171.      * Filter Reason Phrase
  172.      *
  173.      * @param mixed $reasonPhrase
  174.      *
  175.      * @return string
  176.      *
  177.      * @throws InvalidArgumentException
  178.      */
  179.     protected function filterReasonPhrase($reasonPhrase '') : string
  180.     {
  181.         if (\is_object($reasonPhrase) && \method_exists($reasonPhrase'__toString')) {
  182.             $reasonPhrase = (string) $reasonPhrase;
  183.         }
  184.         if (!\is_string($reasonPhrase)) {
  185.             throw new \InvalidArgumentException('Response reason phrase must be a string.');
  186.         }
  187.         if (\strpos($reasonPhrase"\r") || \strpos($reasonPhrase"\n")) {
  188.             throw new \InvalidArgumentException('Reason phrase contains one of the following prohibited characters: \\r \\n');
  189.         }
  190.         return $reasonPhrase;
  191.     }
  192. }