Extends
lithium\net\Message
Add a header to rendered output, or return a single header or full header list.
Parameters
- string $key
- string $value
Returns
arraySource
public function headers($key = null, $value = null) {
if (is_string($key) && strpos($key, ':') === false) {
if ($value === null) {
return isset($this->headers[$key]) ? $this->headers[$key] : null;
}
if ($value === false) {
unset($this->headers[$key]);
return $this->headers;
}
}
if ($value) {
$this->headers = array_merge($this->headers, array($key => $value));
} else {
foreach ((array) $key as $header => $value) {
if (!is_string($header)) {
if (preg_match('/(.*?):(.+)/i', $value, $match)) {
$this->headers[$match[1]] = trim($match[2]);
}
} else {
$this->headers[$header] = $value;
}
}
}
$headers = array();
foreach ($this->headers as $key => $value) {
if (is_array($value)) {
foreach ($value as $val) {
$headers[] = "{$key}: {$val}";
}
continue;
}
$headers[] = "{$key}: {$value}";
}
return $headers;
}