本文整理汇总了PHP中Psr\Http\Message\ResponseInterface::withoutHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::withoutHeader方法的具体用法?PHP ResponseInterface::withoutHeader怎么用?PHP ResponseInterface::withoutHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ResponseInterface
的用法示例。
在下文中一共展示了ResponseInterface::withoutHeader方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display
/**
* Outputs the error popup, or a plain message, depending on the response content type.
*
* @param \Exception|\Error $exception Note: can't be type hinted, for PHP7 compat.
* @param ResponseInterface|null $response If null, it outputs directly to the client. Otherwise, it assumes the
* object is a new blank response.
* @return ResponseInterface|null
*/
static function display($exception, ResponseInterface $response = null)
{
// For HTML pages, output the error popup
if (strpos(get($_SERVER, 'HTTP_ACCEPT'), 'text/html') !== false) {
ob_start();
ErrorConsoleRenderer::renderStyles();
$stackTrace = self::getStackTrace($exception->getPrevious() ?: $exception);
ErrorConsoleRenderer::renderPopup($exception, self::$appName, $stackTrace);
$popup = ob_get_clean();
// PSR-7 output
if ($response) {
$response->getBody()->write($popup);
return $response->withStatus(500);
}
// Direct output
echo $popup;
} else {
// PSR-7 output
if ($response) {
$response->getBody()->write($exception->getMessage());
if (self::$devEnv) {
$response->getBody()->write("\n\nStack trace:\n" . $exception->getTraceAsString());
}
return $response->withoutHeader('Content-Type')->withHeader('Content-Type', 'text-plain')->withStatus(500);
}
// Direct output
header("Content-Type: text/plain");
http_response_code(500);
echo $exception->getMessage();
if (self::$devEnv) {
echo "\n\nStack trace:\n" . $exception->getTraceAsString();
}
}
return null;
}
示例2: dispatch
public function dispatch(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface
{
$lang = LanguageNegotiator::getLanguage($request);
$query = $this->db->prepare('SELECT n.id, n.title, n.parent_id from nodes n
INNER JOIN node_attributes na ON na.node_id = n.id
INNER JOIN attribute_values av on na.`attribute_value_id` = av.`id`
where av.`attribute_value` = :language;');
$query->bindParam(':language', $lang);
$query->execute();
$data = $query->fetchAll(\PDO::FETCH_ASSOC);
$neg = new FormatNegotiator();
$contentType = $neg->getFormat($request);
switch ($contentType) {
case 'xml':
$xml = new \SimpleXMLElement('<root/>');
array_walk_recursive($this->treeBuilder->build($data), array($xml, 'addChild'));
$response->getBody()->write($xml->asXML());
break;
default:
$response->getBody()->write(json_encode($this->treeBuilder->build($data)));
break;
}
return $response->withoutHeader('Content-Type');
// Remove the Content-Type Header
}
示例3: withoutHeader
/**
* Proxy to PsrResponseInterface::withoutHeader()
*
* {@inheritdoc}
* @throws RuntimeException if response is already completed
*/
public function withoutHeader($header)
{
if ($this->complete) {
throw $this->responseIsAlreadyCompleted(__METHOD__);
}
$new = $this->psrResponse->withoutHeader($header);
return new self($new);
}
示例4: withoutHeader
/**
* Proxy to PsrResponseInterface::withoutHeader()
*
* {@inheritdoc}
*/
public function withoutHeader($header)
{
if ($this->complete) {
return $this;
}
$new = $this->psrResponse->withoutHeader($header);
return new self($new);
}
示例5: isAuthentic
/**
* {@inheritDoc}
*/
public function isAuthentic(ResponseInterface $response)
{
if (!$response->hasHeader('X-Server-Authorization-HMAC-SHA256')) {
throw new MalformedResponseException('Response is missing required X-Server-Authorization-HMAC-SHA256 header.', null, 0, $response);
}
$responseSigner = new ResponseSigner($this->key, $this->request);
$compareResponse = $responseSigner->signResponse($response->withoutHeader('X-Server-Authorization-HMAC-SHA256'));
$responseSignature = $response->getHeaderLine('X-Server-Authorization-HMAC-SHA256');
$compareSignature = $compareResponse->getHeaderLine('X-Server-Authorization-HMAC-SHA256');
return hash_equals($compareSignature, $responseSignature);
}
示例6: withoutHeader
/**
* {@inheritDoc}
*/
public function withoutHeader($name)
{
return new self($this->app, $this->decorated->withoutHeader($name));
}
示例7: withoutHeader
/**
* Return an instance without the specified header.
*
* Header resolution MUST be done without case-sensitivity.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that removes
* the named header.
*
* @param string $name Case-insensitive header field name to remove.
* @return self
*/
function withoutHeader($name)
{
return $this->response->withoutHeader($name);
}
示例8: withoutHeader
/**
* {@inheritdoc}
*/
public function withoutHeader($name)
{
return new HttpException($this->response->withoutHeader($name), $this->attributes);
}
示例9: withoutHeader
/**
* @inheritDoc
*/
public function withoutHeader($name)
{
return new self($this->psrResponse->withoutHeader($name));
}
示例10: withoutHeader
public function withoutHeader($name)
{
$response = clone $this;
$response->response = $this->response->withoutHeader($name);
return $response;
}
示例11: send
/**
* @param ResponseInterface $response
*/
public function send(ResponseInterface $response)
{
$empty = \false;
if (in_array($response->getStatusCode(), [204, 205, 304])) {
$empty = \true;
}
if ($empty === \true) {
$response->withoutHeader('Content-Type')->withoutHeader('Content-Length');
}
$size = $response->getBody()->getSize();
if ($size !== \null && !$response->hasHeader('Content-Length')) {
$response->withHeader('Content-Length', (string) $size);
}
// Send response
if (!\headers_sent()) {
// Status
\header(\sprintf('HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase()));
// Headers
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
\header(\sprintf('%s: %s', $name, $value), false);
}
}
}
// Body
if ($empty === \false) {
$body = $response->getBody();
if ($body->isSeekable()) {
$body->rewind();
}
$chunkSize = $this->container->get('config')->get('response.responseChunkSize', 4096);
$contentLength = $response->getHeaderLine('Content-Length');
if (!$contentLength) {
$contentLength = $body->getSize();
}
$totalChunks = \ceil($contentLength / $chunkSize);
$lastChunkSize = $contentLength % $chunkSize;
$currentChunk = 0;
while (!$body->eof() && $currentChunk < $totalChunks) {
if (++$currentChunk == $totalChunks && $lastChunkSize > 0) {
$chunkSize = $lastChunkSize;
}
echo $body->read($chunkSize);
if (\connection_status() != \CONNECTION_NORMAL) {
break;
}
}
}
}