123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- /**
- * Base HTTP response object
- *
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\HTTP\PhpEnvironment;
- class Response extends \Zend\Http\PhpEnvironment\Response implements \Magento\Framework\App\Response\HttpInterface
- {
- /**
- * Flag; is this response a redirect?
- * @var boolean
- */
- protected $isRedirect = false;
- /**
- * {@inheritdoc}
- */
- public function getHeader($name)
- {
- $header = false;
- $headers = $this->getHeaders();
- if ($headers->has($name)) {
- $header = $headers->get($name);
- }
- return $header;
- }
- /**
- * Send the response, including all headers, rendering exceptions if so
- * requested.
- *
- * @return void
- */
- public function sendResponse()
- {
- $this->send();
- }
- /**
- * {@inheritdoc}
- */
- public function appendBody($value)
- {
- $body = $this->getContent();
- $this->setContent($body . $value);
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setBody($value)
- {
- $this->setContent($value);
- return $this;
- }
- /**
- * Clear body
- * @return $this
- */
- public function clearBody()
- {
- $this->setContent('');
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setHeader($name, $value, $replace = false)
- {
- $value = (string)$value;
- if ($replace) {
- $this->clearHeader($name);
- }
- $this->getHeaders()->addHeaderLine($name, $value);
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function clearHeader($name)
- {
- $headers = $this->getHeaders();
- if ($headers->has($name)) {
- $header = $headers->get($name);
- $headers->removeHeader($header);
- }
- return $this;
- }
- /**
- * Remove all headers
- *
- * @return $this
- */
- public function clearHeaders()
- {
- $headers = $this->getHeaders();
- $headers->clearHeaders();
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setRedirect($url, $code = 302)
- {
- $this->setHeader('Location', $url, true)
- ->setHttpResponseCode($code);
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setHttpResponseCode($code)
- {
- if (!is_numeric($code) || (100 > $code) || (599 < $code)) {
- throw new \InvalidArgumentException('Invalid HTTP response code');
- }
- $this->isRedirect = (300 <= $code && 307 >= $code) ? true : false;
- $this->setStatusCode($code);
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setStatusHeader($httpCode, $version = null, $phrase = null)
- {
- $version = $version === null ? $this->detectVersion() : $version;
- $phrase = $phrase === null ? $this->getReasonPhrase() : $phrase;
- $this->setVersion($version);
- $this->setHttpResponseCode($httpCode);
- $this->setReasonPhrase($phrase);
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function getHttpResponseCode()
- {
- return $this->getStatusCode();
- }
- /**
- * Is this a redirect?
- *
- * @return boolean
- */
- public function isRedirect()
- {
- return $this->isRedirect;
- }
- /**
- * @return string[]
- */
- public function __sleep()
- {
- return ['content', 'isRedirect', 'statusCode'];
- }
- }
|