123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace Qii\Response;
- class Http extends \Qii\Base\Response
- {
- protected $_sendheader = true;
- protected $_responseCode = 200;
- /**
- * Set HTTP response code to use with headers
- *
- * @param int $code
- * @return Qii\Response\Http
- */
- public function setResponseCode($code)
- {
- if (!is_int($code) || (100 > $code) || (599 < $code)) {
- throw new \Qii\Exceptions\Response('Invalid HTTP response code');
- }
- $this->_responseCode = $code;
- return $this;
- }
- /**
- * Retrieve HTTP response code
- *
- * @return int
- */
- public function getResponseCode()
- {
- return $this->_responseCode;
- }
- /**
- * Send all headers
- *
- * Sends any headers specified.
- * If an {@link setResponseCode() HTTP response code}
- * has been specified, it is sent with the first header.
- *
- * @return Qii_Response_Http
- */
- protected function sendHeaders()
- {
- $httpCodeSent = false;
- if (!$this->_sendheader) {
- return $this;
- }
- foreach ($this->_headers as $header) {
- if (!$httpCodeSent && $this->_responseCode) {
- header(
- $header['name'] . ': ' . $header['value'],
- $header['replace'], $this->_responseCode
- );
- $httpCodeSent = true;
- } else {
- header(
- $header['name'] . ': ' . $header['value'],
- $header['replace']
- );
- }
- }
- return $this;
- }
- /**
- * Set redirect URL
- *
- * Sets Location header. Forces replacement of any prior redirects.
- *
- * @param string $url
- * @return Qii_Response_Abstract
- */
- public function setRedirect($url)
- {
- $this->setHeader('Location', $url, true)
- ->setResponseCode(302);
- return $this;
- }
- }
|