示例#1
0
 /**
  * Gets and sets headers to the [Response], allowing chaining
  * of response methods
  *
  * If chaining isn't required, direct access to the property
  * should be used instead.
  *
  * Example:
  * ~~~
  * // Get a header
  * $accept = $response->headers('Content-Type');
  *
  * // Set a header
  * $response->headers('Content-Type', 'text/html');
  *
  * // Get all headers
  * $headers = $response->headers();
  *
  * // Set multiple headers
  * $response->headers(array('Content-Type' => 'text/html', 'Cache-Control' => 'no-cache'));
  * ~~~
  *
  * @param   mixed   $key    Header key [Optional]
  * @param   string  $value  Header value [Optional]
  *
  * @return  mixed
  *
  * @uses    Arr::get
  */
 public function headers($key = NULL, $value = NULL)
 {
     if ($key === NULL) {
         return $this->_header;
     } elseif (is_array($key)) {
         $this->_header->exchangeArray($key);
         return $this;
     } elseif ($value === NULL) {
         return Arr::get($this->_header, $key);
     } else {
         $this->_header[$key] = $value;
         return $this;
     }
 }
示例#2
0
 /**
  * Gets or sets HTTP headers to the request or response. All headers
  * are included immediately after the HTTP protocol definition during
  * transmission. This method provides a simple array or key/value
  * interface to the headers.
  *
  * @param   mixed   $key   Key or array of key/value pairs to set
  * @param   string  $value Value to set to the supplied key
  *
  * @return  Request|HTTP_Header|mixed
  */
 public function headers($key = NULL, $value = NULL)
 {
     if ($key instanceof HTTP_Header) {
         // Act a setter, replace all headers
         $this->_header = $key;
         return $this;
     }
     if (is_array($key)) {
         // Act as a setter, replace all headers
         $this->_header->exchangeArray($key);
         return $this;
     }
     if ($this->_header->count() === 0 and $this->is_initial()) {
         // Lazy load the request headers
         $this->_header = HTTP::request_headers();
     }
     if ($key === NULL) {
         // Act as a getter, return all headers
         return $this->_header;
     } elseif ($value === NULL) {
         // Act as a getter, single header
         return $this->_header->offsetExists($key) ? $this->_header->offsetGet($key) : NULL;
     }
     // Act as a setter for a single header
     $this->_header[$key] = $value;
     return $this;
 }