本文整理汇总了PHP中Psr\Http\Message\ResponseInterface::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::getHeaders方法的具体用法?PHP ResponseInterface::getHeaders怎么用?PHP ResponseInterface::getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ResponseInterface
的用法示例。
在下文中一共展示了ResponseInterface::getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendHeaders
private function sendHeaders()
{
foreach ($this->response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header($name . ': ' . $value);
}
}
}
示例2: _getResult
/**
* @param ResponseInterface $response
*
* @return ApiResult
*/
protected function _getResult($response)
{
if (!$response instanceof ResponseInterface) {
throw new \InvalidArgumentException("{$response} should be an instance of ResponseInterface");
}
$result = new ApiResult();
$result->setStatusCode($response->getStatusCode());
$callId = $response->getHeader('X-Call-Id');
if (!empty($callId)) {
$result->setCallId($callId);
}
$decoded = json_decode((string) $response->getBody());
if (isset($decoded->meta) && isset($decoded->data) && isset($decoded->meta->code) && $decoded->meta->code == $response->getStatusCode()) {
$meta = $decoded->meta;
$data = $decoded->data;
if (isset($meta->message)) {
$result->setStatusMessage($meta->message);
}
$result->setContent(json_encode($data));
} else {
$result->setContent((string) $response->getBody());
}
$result->setHeaders($response->getHeaders());
return $result;
}
示例3: send
/**
* @param ResponseInterface $response
*/
public function send(ResponseInterface $response)
{
/**
* build response header
*/
foreach ($response->getHeaders() as $key => $value) {
$filter_header = function ($header) {
$filtered = str_replace('-', ' ', $header);
$filtered = ucwords($filtered);
return str_replace(' ', '-', $filtered);
};
$name = $filter_header($key);
foreach ($value as $v) {
$this->app['SwooleResponder']->header($name, $v);
}
}
/**
* compress content
*/
if (!empty($this->app['Config']['server.gzip'])) {
$this->app['SwooleResponder']->gzip($this->app['Config']['server.gzip']);
}
$this->app['SwooleResponder']->status($response->getStatusCode());
$this->app['SwooleResponder']->header('Server', 'vinnige-app-server');
$this->app['SwooleResponder']->end((string) $response->getBody());
}
示例4: leave
/**
* Stops the profiling.
* @param ResponseInterface $response
*/
public function leave(ResponseInterface $response = null)
{
$this->ends = ['wt' => microtime(true), 'mu' => memory_get_usage(), 'pmu' => memory_get_peak_usage()];
if ($response) {
$this->response = ['headers' => $response->getHeaders(), 'statusCode' => $response->getStatusCode(), 'body' => (string) $response->getBody()];
}
}
示例5: logResponse
/**
* @param ResponseInterface $response
* @param string $type
*/
protected function logResponse(ResponseInterface $response, $type = 'http')
{
$args = [ucfirst($type), $response->getStatusCode(), $response->getReasonPhrase()];
/** @noinspection PrintfScanfArgumentsInspection */
$this->log(sprintf(' <== (%s) %s %s', ...$args));
$headers = $this->removeTokenFromLogs($response->getHeaders());
$this->log(' Response headers: ' . json_encode($headers), Logger::DEBUG);
}
示例6: psr7HeadersToString
/**
* Convert the PSR-7 headers to string
*
* @param ResponseInterface $psr7Response
* @return string
*/
private static function psr7HeadersToString(ResponseInterface $psr7Response)
{
$headers = '';
foreach ($psr7Response->getHeaders() as $name => $value) {
$headers .= $name . ": " . implode(", ", $value) . "\r\n";
}
return $headers;
}
示例7: formatResponse
public function formatResponse(ResponseInterface $response)
{
$format = ['code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody()];
if ($this->markerHeader) {
$format['headers']['X-Guzzle-Stereo'] = true;
}
return $format;
}
示例8: formatResponse
/**
* {@inheritdoc}
*/
public function formatResponse(ResponseInterface $response)
{
$message = sprintf("HTTP/%s %s %s\n", $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase());
foreach ($response->getHeaders() as $name => $values) {
$message .= $name . ': ' . implode(', ', $values) . "\n";
}
return $this->addBody($response, $message);
}
示例9: save
/**
* Save data
*
* @author Florian Preusner
* @version 2.1
* @since 2015-05
*
* @param ResponseInterface $response
*/
public function save(ResponseInterface $response)
{
$this->setStatusCode($response->getStatusCode());
$this->setStatusPhrase($response->getReasonPhrase());
$this->setBody($response->getBody()->__toString());
$this->setHeaders($response->getHeaders());
$this->setProtocolVersion($response->getProtocolVersion());
}
示例10: send
/**
* @param ResponseInterface $response
*/
public function send(ResponseInterface $response)
{
header('HTTP/' . $response->getProtocolVersion() . ' ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase());
foreach ($response->getHeaders() as $header => $values) {
header($header . ': ' . implode(', ', $values));
}
parent::send($response);
}
示例11: getHeadersAsString
/**
* Returns the Guzzle array of headers as a string.
*
* @param ResponseInterface $response The Guzzle response.
*
* @return string
*/
public function getHeadersAsString(ResponseInterface $response)
{
$headers = $response->getHeaders();
$rawHeaders = [];
foreach ($headers as $name => $values) {
$rawHeaders[] = $name . ": " . implode(", ", $values);
}
return implode("\r\n", $rawHeaders);
}
示例12: createResponse
/**
* {@inheritdoc}
*/
public function createResponse(ResponseInterface $psrResponse)
{
$response = new Response($psrResponse->getBody()->__toString(), $psrResponse->getStatusCode(), $psrResponse->getHeaders());
$response->setProtocolVersion($psrResponse->getProtocolVersion());
foreach ($psrResponse->getHeader('Set-Cookie') as $cookie) {
$response->headers->setCookie($this->createCookie($cookie));
}
return $response;
}
示例13: emitHeaders
private function emitHeaders(ResponseInterface $response)
{
foreach ($response->getHeaders() as $header => $values) {
$name = str_replace(' ', '-', ucwords(str_replace('-', ' ', $header)));
foreach ($values as $value) {
$this->output->writeln(sprintf('%s: %s', $name, $value));
}
}
}
示例14: __construct
/**
* Response constructor.
*
* @param ResponseInterface $response
*/
public function __construct($response)
{
if ($response instanceof ResponseInterface) {
$this->statusCode = $response->getStatusCode();
$this->body = $response->getBody();
$this->headers = $response->getHeaders();
}
$this->decodedBody = json_decode($this->body, true);
}
示例15: __construct
/**
* Constructs a representable document
*
* @param ResponseInterface $response
*/
public function __construct(ResponseInterface $response)
{
$headers = $response->getHeaders();
// What better to get the mime type than what the Telegram servers already send us?
$this->mime_type = $headers['Content-Type'][0];
// Same with file length
$this->file_size = (int) $headers['Content-Length'][0];
$this->contents = (string) $response->getBody();
}