本文整理汇总了PHP中Psr\Http\Message\ResponseInterface::getProtocolVersion方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::getProtocolVersion方法的具体用法?PHP ResponseInterface::getProtocolVersion怎么用?PHP ResponseInterface::getProtocolVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ResponseInterface
的用法示例。
在下文中一共展示了ResponseInterface::getProtocolVersion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendStatus
/**
* Send the status
*
* @param ResponseInterface $response The response object
*
* @return void
*/
protected function sendStatus(ResponseInterface $response)
{
$version = $response->getProtocolVersion();
$status = $response->getStatusCode();
$phrase = $response->getReasonPhrase();
header("HTTP/{$version} {$status} {$phrase}");
}
示例2: 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());
}
示例3: 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);
}
示例4: 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);
}
示例5: sendHeaders
/**
* Sends the response headers.
*
* @param \Psr\Http\Message\ResponseInterface $response Response instance
*/
private function sendHeaders(ResponseInterface $response)
{
$statusCode = $response->getStatusCode();
header(sprintf('HTTP/%s %d %s', $response->getProtocolVersion(), $statusCode, $response->getReasonPhrase()), true, $statusCode);
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header("{$name}: {$value}", false, $statusCode);
}
}
}
示例6: emitStatusLine
/**
* Emit the status line.
*
* Emits the status line using the protocol version and status code from
* the response; if a reason phrase is availble, it, too, is emitted.
*
* @param ResponseInterface $response
*/
private function emitStatusLine(ResponseInterface $response)
{
$reasonPhrase = $response->getReasonPhrase();
header(sprintf(
'HTTP/%s %d%s',
$response->getProtocolVersion(),
$response->getStatusCode(),
($reasonPhrase ? ' ' . $reasonPhrase : '')
));
}
示例7: getStatusLine
private function getStatusLine(ResponseInterface $response)
{
$protocol = $response->getProtocolVersion();
$statusCode = $response->getStatusCode();
$reasonPhrase = $response->getReasonPhrase();
if ($reasonPhrase) {
return "HTTP/{$protocol} {$statusCode} {$reasonPhrase}";
} else {
return "HTTP/{$protocol} {$statusCode}";
}
}
示例8: execute
/**
* Process a ResponseInterface into an output.
*
* @param ResponseInterface $httpResponse
*/
public function execute(ResponseInterface $httpResponse)
{
$headerFunction = $this->headerFunction;
$bodyFunction = $this->bodyFunction;
$headerFunction('HTTP/' . $httpResponse->getProtocolVersion() . ' ' . $httpResponse->getStatusCode() . ' ' . $httpResponse->getReasonPhrase());
foreach ($httpResponse->getHeaders() as $name => $values) {
foreach ($values as $value) {
$headerFunction(sprintf('%s: %s', $name, $value));
}
}
$bodyFunction($httpResponse->getBody());
}
示例9: sendResponse
public static function sendResponse(Response $response)
{
header(sprintf('HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase()));
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
}
}
if (!in_array($response->getStatusCode(), [204, 205, 304])) {
echo $response->getBody();
}
}
示例10: toString
/**
* Create a string representation of a response.
*
* @param ResponseInterface $response
* @return string
*/
public static function toString(ResponseInterface $response)
{
$reasonPhrase = $response->getReasonPhrase();
$headers = self::serializeHeaders($response->getHeaders());
$body = (string) $response->getBody();
$format = 'HTTP/%s %d%s%s%s';
if (!empty($headers)) {
$headers = "\r\n" . $headers;
}
$headers .= "\r\n\r\n";
return sprintf($format, $response->getProtocolVersion(), $response->getStatusCode(), $reasonPhrase ? ' ' . $reasonPhrase : '', $headers, $body);
}
示例11: renderResponse
/**
* Takes a PSR-7 Response and outputs all headers and body. This should be the
* very last thing done in request processing.
*/
function renderResponse(ResponseInterface $response)
{
// Send HTTP code
header(sprintf("HTTP/%s %s %s", $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase()));
// Additional headers
foreach ($response->getHeaders() as $key => $values) {
foreach ($values as $value) {
header(sprintf("%s: %s", $key, $value), false);
}
}
// And then the body
echo $response->getBody();
}
示例12: send
public static function send(ResponseInterface $response)
{
$statusCode = $response->getStatusCode();
$reasonPhrase = $response->getReasonPhrase();
$protocolVersion = $response->getProtocolVersion();
header("HTTP/{$protocolVersion} {$statusCode} {$reasonPhrase}");
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
}
}
echo $response->getBody();
}
示例13: sendHeaders
public function sendHeaders(ResponseInterface $response)
{
header(sprintf('HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase()), true, $response->getStatusCode());
foreach ($response->getHeaders() as $header => $values) {
$name = $this->filterHeader($header);
$first = true;
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), $first);
$first = false;
}
}
$time = round(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], 3);
header("X-Processing-Time: {$time} seconds");
}
示例14: sendResponse
/**
* Sends the response back to the client
*
* @param ResponseInterface $response
*/
public function sendResponse(ResponseInterface $response)
{
if (!headers_sent()) {
$header = sprintf('HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase());
header($header);
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
$header = sprintf('%s: %s', $name, $value);
header($header, false);
}
}
}
echo (string) $response->getBody();
}
示例15: send
function send(ResponseInterface $response)
{
if (!headers_sent()) {
// status
header(sprintf('HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase()), true, $response->getStatusCode());
// headers
foreach ($response->getHeaders() as $header => $values) {
foreach ($values as $value) {
header($header . ': ' . $value, false, $response->getStatusCode());
}
}
}
echo $response->getBody();
}