本文整理汇总了PHP中Response::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getHeaders方法的具体用法?PHP Response::getHeaders怎么用?PHP Response::getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRebuild
public function testRebuild()
{
$expectedContent = ['foo' => 'bar'];
$expectedHeaders = new \Phalcon\Http\Response\Headers();
$expectedHeaders->set('Status', '200 OK');
$expectedHeaders->set('HTTP/1.1 200 OK', null);
$this->response->rebuild(['foo' => 'bar']);
$this->assertEquals($expectedContent, $this->response->getContent());
$this->assertEquals($expectedHeaders, $this->response->getHeaders());
}
示例2: handle
/**
* @param Response $response
*/
public function handle(Response $response)
{
foreach ($response->getHeaders() as $header) {
header($header);
}
echo $response->getContent();
}
示例3: format
/**
* 格式化指定的响应
*
* @param Response $response
*/
public function format($response)
{
if (stripos($this->contentType, 'charset') === false) {
$this->contentType .= '; charset=' . $response->charset;
}
$response->getHeaders()->set('Content-Type', $this->contentType);
$response->content = $response->data;
}
示例4: buildMessage
public function buildMessage(Response $response)
{
$str = '';
$str .= $response->getStatus();
$str .= "\nURL:\n" . $response->getUrl();
$str .= "\nPARAMS:\n" . var_export($response->getParams(), true);
$str .= "\nRESPONSE HEADER:\n" . var_export($response->getHeaders(), true);
$str .= "\nRESPONSE CONTENT:\n" . substr($response->getContent(), 0, 200);
return $str;
}
示例5: construct
/**
* Verify basic functionality of the response object.
*
* @test
* @covers ::__construct
* @covers ::getHttpCode
* @covers ::getHeaders
* @covers ::getBody
*
* @return void
*/
public function construct()
{
$httpCode = 200;
$headers = ['Content-Type' => 'text/json'];
$body = ['doesnt' => 'matter'];
$response = new Response($httpCode, $headers, $body);
$this->assertSame($httpCode, $response->getHttpCode());
$this->assertSame($headers, $response->getHeaders());
$this->assertSame($body, $response->getBody());
}
示例6: render
/**
* {@inheritdoc}
*/
public function render(Request $request, Response $response)
{
if (!$this->environment->isSilent()) {
header('HTTP/1.1 ' . $response->getStatusCode() . ' ' . $response->getStatusMessage());
foreach ($response->getHeaders() as $name => $value) {
header($name . ': ' . $value);
}
}
echo $this->createTemplate($response);
}
示例7: render
/** Renders a response. */
public final function render(Response $response)
{
foreach ($response->getHeaders() as $h) {
header($h);
}
http_response_code($response->getStatus());
$e = $response->getEntity();
if (!is_null($e)) {
$this->renderEntity($e);
}
}
示例8: sendHeaders
/**
* Sends the headers of the response to the client.
*
* @return void
*/
protected function sendHeaders()
{
if (!headers_sent()) {
$status = $this->response->getMessage() ?: $this->response->getStatus();
header(sprintf("%s %s", $this->response->getProtocol(), $status));
foreach ($this->response->getHeaders() as $name => $value) {
header("{$name}: {$value}", true);
}
foreach ($this->response->getCookies() as $cookie) {
header("Set-Cookie: {$cookie}", false);
}
}
}
示例9: format
/**
* Formats the specified response.
* @param Response $response the response to be formatted.
*/
public function format($response)
{
$charset = $this->encoding === null ? $response->charset : $this->encoding;
if (stripos($this->contentType, 'charset') === false) {
$this->contentType .= '; charset=' . $charset;
}
$response->getHeaders()->set('Content-Type', $this->contentType);
$dom = new DOMDocument($this->version, $charset);
$root = $dom->createElement($this->rootTag);
$root->setAttribute('xmlns', $this->xmlns);
$dom->appendChild($root);
$this->buildXml($root, $response->data);
$response->content = $dom->saveXML();
}
示例10: format
/**
* Formats the specified response.
* @param Response $response the response to be formatted.
*/
public function format($response)
{
$charset = $this->encoding === null ? $response->charset : $this->encoding;
if ($this->gzip) {
$this->contentType = $this->gzipContentType;
} elseif (stripos($this->contentType, 'charset') === false) {
$this->contentType .= '; charset=' . $charset;
}
$response->getHeaders()->set('Content-Type', $this->contentType);
$dom = new DOMDocument($this->version, $charset);
$root = $dom->createElement($this->rootTag);
$root->setAttribute('xmlns', $this->xmlns);
$dom->appendChild($root);
$this->buildXml($root, $response->data);
$xmlData = $dom->saveXML();
//output
if ($this->gzip) {
$response->content = gzencode($xmlData);
$response->getHeaders()->set('Content-Disposition', "attachment; filename=\"{$this->gzipFilename}\"");
} else {
$response->content = $xmlData;
}
}
示例11: __construct
public function __construct(Response $parent)
{
$status = $parent->getStatus();
$convertToJson = false;
$ok = self::statusIsOK($status);
if ($ok) {
$contentType = $parent->getHeader('Content-Type');
if (!empty($contentType)) {
$convertToJson = stristr($contentType, '/json') !== false;
}
}
$bodyString = $parent->getBody();
parent::__construct($convertToJson ? json_decode($bodyString) : $bodyString, $parent->getHeaders(), $status);
$this->ok = $ok;
}
示例12: format
/**
* Formats the specified response.
* @param Response $response the response to be formatted.
* @throws \RuntimeException
*/
public function format($response)
{
$response->getHeaders()->set('Content-Type', 'text/csv; charset=UTF-8');
$handle = fopen('php://temp/maxmemory:' . intval($this->maxMemory), 'w+');
$response->stream = $handle;
if ($this->includeColumnNames && $this->checkAllRows) {
$columns = $this->getColumnNames($response->data);
if (empty($columns)) {
return;
}
$outputHeader = false;
$this->put($handle, $columns);
} else {
$outputHeader = true;
}
if (!$response->data instanceof \Traversable && !is_array($response->data)) {
throw new \InvalidArgumentException('Response data must be traversable.');
}
foreach ($response->data as $row) {
if ($outputHeader && $this->includeColumnNames && !$this->checkAllRows && \yii\helpers\ArrayHelper::isAssociative($row)) {
$this->put($handle, array_keys($row));
$outputHeader = false;
}
if ($row instanceof Arrayable) {
$row = $row->toArray();
}
$rowData = [];
if (isset($columns)) {
// Map columns.
foreach ($columns as $column) {
if (array_key_exists($column, $row)) {
$rowData[] = isset($row[$column]) ? $row[$column] : $this->nullValue;
} else {
$rowData[] = $this->missingValue;
}
}
} else {
foreach ($row as $column => $value) {
$rowData[] = isset($value) ? $value : $this->nullValue;
}
}
$this->put($handle, $rowData);
}
rewind($handle);
}
示例13: format
/**
* Formats the specified response.
* @param Response $response the response to be formatted.
*/
public function format($response)
{
$charset = $this->encoding === null ? $response->charset : $this->encoding;
if (stripos($this->contentType, 'charset') === false) {
$this->contentType .= '; charset=' . $charset;
}
$response->getHeaders()->set('Content-Type', $this->contentType);
if ($response->data !== null) {
$dom = new DOMDocument($this->version, $charset);
$root = new DOMElement($this->rootTag);
$result = new DOMElement($this->itemTag);
$code = new DOMElement($this->itemTag);
$status = new DOMElement($this->itemTag);
$dom->appendChild($root);
$code->appendChild($response->getStatusCode());
$status->appendChild($response->getIsSuccessful() ? 'success' : 'error');
$messageText = '';
if (!$response->getIsOk()) {
$messageText = $response->statusText;
}
if (is_string($response->data)) {
//For string result we send it like 'message'
$messageText = $response->data;
} elseif ($response->getIsClientError() && isset($response->data['message'])) {
//For HttpExceptions we save message field only to 'message'
$messageText = $response->data['message'];
unset($response->data['message']);
$result->appendChild($response->data);
} else {
//Otherwise send all as result
$result->appendChild($response->data);
}
if ($messageText !== '') {
$message = new DOMElement($this->itemTag);
$message->appendChild($messageText);
$root->appendChild($message);
}
$root->appendChild($result);
$root->appendChild($code);
$root->appendChild($status);
$this->buildXml($root, $response->data);
$response->content = $dom->saveXML();
}
}
示例14: createFromBuffer
/**
* @param int $status_code OPTIONAL Defaults to `200`.
* @param boolean $read_all_buffers OPTIONAL Whether to get and clean the content of all open buffers.
* Defaults to `true`.
*/
public static function createFromBuffer($status_code = 200, $read_all_buffers = true)
{
# Get our body from the buffer
$body = "";
while (($more_body = ob_get_clean()) !== false) {
$body .= $more_body;
if (!$read_all_buffers) {
break;
}
}
$response = new Response($body, $status_code);
# Add all headers in the buffer and guess response encoding.
$response->addSentHeaders();
foreach ($response->getHeaders() as $header) {
if (preg_match("/^Content-Type:.+;\\s*charset=(.+)\$/i", $header, $matches) === 0) {
continue;
}
$response->setEncoding($matches[1]);
}
return $response;
}
示例15: testConstructHeaders
public function testConstructHeaders()
{
$response = new Response(["test" => ["value"]]);
$this->assertEquals(["test" => ["value"]], $response->getHeaders());
}