lithium\action\Response::headers PHP Метод

headers() публичный Метод

Expands on \net\http\Message::headers() with some magic conversions for shorthand headers.
Устаревший: This method will be removed in a future version. Note that the parent `header()` wil continue to exist.
public headers ( string | array $key = null, mixed $value = null, boolean $replace = true ) : mixed
$key string | array
$value mixed
$replace boolean
Результат mixed
    public function headers($key = null, $value = null, $replace = true)
    {
        if ($key === 'download' || $key === 'Download') {
            $message = "Shorthand header `Download` with `<FILENAME>` has been deprecated ";
            $message .= "because it's too magic. Please use `Content-Disposition` ";
            $message .= "with `attachment; filename=\"<FILENAME>\"` instead.";
            trigger_error($message, E_USER_DEPRECATED);
            $key = 'Content-Disposition';
            $value = 'attachment; filename="' . $value . '"';
        }
        return parent::headers($key, $value, $replace);
    }

Usage Example

 /**
  * Tests the writing mechanism. At first, no Response object is bound to the logger, so
  * it queues up the messages. When the Response object finally gets bound, it flushes the
  * needed headers and all messages at once. All messages coming after this point get added
  * to the header immediately.
  */
 public function testWrite()
 {
     $response = new Response();
     $result = Logger::write('debug', 'FirePhp to the rescue!', array('name' => 'firephp'));
     $this->assertTrue($result);
     $this->assertFalse($response->headers());
     $host = 'meta.firephp.org';
     $expected = array("X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2", "X-Wf-1-Plugin-1: http://{$host}/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3", "X-Wf-1-Structure-1: http://{$host}/Wildfire/Structure/FirePHP/FirebugConsole/0.1", "X-Wf-1-1-1-1: 41|[{\"Type\":\"LOG\"},\"FirePhp to the rescue!\"]|");
     Logger::adapter('firephp')->bind($response);
     $this->assertEqual($expected, $response->headers());
     $result = Logger::write('debug', 'Add this immediately.', array('name' => 'firephp'));
     $this->assertTrue($result);
     $expected[] = 'X-Wf-1-1-1-2: 40|[{"Type":"LOG"},"Add this immediately."]|';
     $this->assertEqual($expected, $response->headers());
 }