本文整理汇总了PHP中Psr\Http\Message\ResponseInterface::withAddedHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::withAddedHeader方法的具体用法?PHP ResponseInterface::withAddedHeader怎么用?PHP ResponseInterface::withAddedHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ResponseInterface
的用法示例。
在下文中一共展示了ResponseInterface::withAddedHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setHeadersFromArray
/**
* Add headers represented by an array of header lines.
*
* @param string[] $headers Response headers as array of header lines.
*
* @return $this
*
* @throws \UnexpectedValueException For invalid header values.
* @throws \InvalidArgumentException For invalid status code arguments.
*/
public function setHeadersFromArray(array $headers)
{
$statusLine = trim(array_shift($headers));
$parts = explode(' ', $statusLine, 3);
if (count($parts) < 2 || substr(strtolower($parts[0]), 0, 5) !== 'http/') {
throw new \UnexpectedValueException(sprintf('"%s" is not a valid HTTP status line', $statusLine));
}
$reasonPhrase = count($parts) > 2 ? $parts[2] : '';
$this->response = $this->response->withStatus((int) $parts[1], $reasonPhrase)->withProtocolVersion(substr($parts[0], 5));
foreach ($headers as $headerLine) {
$headerLine = trim($headerLine);
if ('' === $headerLine) {
continue;
}
$parts = explode(':', $headerLine, 2);
if (count($parts) !== 2) {
throw new \UnexpectedValueException(sprintf('"%s" is not a valid HTTP header line', $headerLine));
}
$name = trim(urldecode($parts[0]));
$value = trim(urldecode($parts[1]));
if ($this->response->hasHeader($name)) {
$this->response = $this->response->withAddedHeader($name, $value);
} else {
$this->response = $this->response->withHeader($name, $value);
}
}
return $this;
}
示例2: options
/**
* Options
*
* Responding to OPTIONS requests and checks for implemented
* methods that matches HTTP METHODS.
*
* @return array
* @throws MethodNotAllowed
*/
public function options()
{
if (!$this->response instanceof ResponseInterface) {
throw new MethodNotAllowed();
}
// Get all implemented methods for this resources
$methods = get_class_methods(get_class($this));
// Get supported verbs
$validMethods = $this->container['validHttpVerbs'];
// Loop though class functions/methods
foreach ($methods as $key => &$method) {
$method = strtoupper($method);
// If class function/method isn't a verb, then unset it
if (!in_array($method, $validMethods)) {
unset($methods[$key]);
}
}
// Set accept header
$this->response = $this->response->withAddedHeader('Allow', implode(', ', $methods));
// Prepare output
$output = [];
$output['Content-Type'] = $this->container['contentTypes'];
$output['Accept'] = $this->container['acceptTypes'];
foreach ($methods as $verb) {
$doc = $this->parseMethodDoc($verb);
// Check if there is any output to show
if (!empty($doc)) {
$output['methods'][$verb] = $doc;
}
}
// return output
return $output;
}
示例3: withAddedHeader
/**
* Proxy to PsrResponseInterface::withAddedHeader()
*
* {@inheritdoc}
*/
public function withAddedHeader($header, $value)
{
if ($this->complete) {
return $this;
}
$new = $this->psrResponse->withAddedHeader($header, $value);
return new self($new);
}
示例4: addToResponse
/**
* Add the set cookies to a response.
*
* @param ResponseInterface $response
*
* @return ResponseInterface
*/
public function addToResponse(ResponseInterface $response) : ResponseInterface
{
$header = [];
foreach ($this->cookies as $setCookie) {
$header[] = $setCookie->toHeaderValue();
}
return $response->withAddedHeader('Set-Cookie', $header);
}
示例5: withAddedHeader
/**
* Proxy to PsrResponseInterface::withAddedHeader()
*
* {@inheritdoc}
* @throws RuntimeException if response is already completed
*/
public function withAddedHeader($header, $value)
{
if ($this->complete) {
throw $this->responseIsAlreadyCompleted(__METHOD__);
}
$new = $this->psrResponse->withAddedHeader($header, $value);
return new self($new);
}
示例6: createRequestHeaders
/**
* Create all headers for a regular request
*/
protected function createRequestHeaders()
{
$headers = [];
// Set Allowed origin header (either * or Origin from request)
$headers = $this->createOriginHeader($headers);
// Set support credentials header
$headers = $this->createCredentialsHeader($headers);
// Set exposed headers header
$headers = $this->createExposedHeadersHeader($headers);
// Add the headers to the response
foreach ($headers as $name => $value) {
$this->response = $this->response->withAddedHeader($name, (string) $value);
}
}
示例7: addHeader
/**
* Add header represented by a string.
*
* @param string $headerLine Response header as a string.
*
* @return $this
*
* @throws \InvalidArgumentException For invalid header names or values.
*/
public function addHeader($headerLine)
{
$parts = explode(':', $headerLine, 2);
if (count($parts) !== 2) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid HTTP header line', $headerLine));
}
$name = trim(urldecode($parts[0]));
$value = trim(urldecode($parts[1]));
if ($this->response->hasHeader($name)) {
$this->response = $this->response->withAddedHeader($name, $value);
} else {
$this->response = $this->response->withHeader($name, $value);
}
return $this;
}
示例8: __invoke
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
$index = $this->storage->getIndex();
return $response->withAddedHeader('X-Demeter-Index', $index);
}
示例9: withAddedHeader
/**
* {@inheritdoc}
*/
public function withAddedHeader($name, $value)
{
return new HttpException($this->response->withAddedHeader($name, $value), $this->attributes);
}
示例10: addToResponse
public function addToResponse(ResponseInterface $response) : ResponseInterface
{
return $response->withAddedHeader('Set-Cookie', $this->toHeaderValue());
}
示例11: respondWithSessionCookie
/**
* Add session cookie Set-Cookie header to response.
*
* @param ResponseInterface $response
*
* @throws \InvalidArgumentException
*
* @return ResponseInterface
*/
protected function respondWithSessionCookie(ResponseInterface $response)
{
if (session_status() !== PHP_SESSION_ACTIVE || !array_key_exists($this->sessionTimeoutKey, $_SESSION)) {
$expireTime = time() - $this->sessionLifetime;
} else {
$expireTime = $_SESSION[$this->sessionTimeoutKey];
}
$cookieParams = [sprintf('expires=%s; max-age=%s', gmdate('D, d M Y H:i:s T', $expireTime), $this->sessionLifetime)];
if (trim($this->getSessionSetting('cookie_path')) !== '') {
$cookieParams[] = 'path=' . $this->getSessionSetting('cookie_path');
}
if (trim($this->getSessionSetting('cookie_domain')) !== '') {
$cookieParams[] = 'domain=' . $this->getSessionSetting('cookie_domain');
}
if ((bool) $this->getSessionSetting('cookie_secure')) {
$cookieParams[] = 'secure';
}
if ((bool) $this->getSessionSetting('cookie_httponly')) {
$cookieParams[] = 'httponly';
}
return $response->withAddedHeader('Set-Cookie', sprintf('%s=%s; %s', urlencode($this->sessionName), urlencode(session_id()), implode('; ', $cookieParams)));
}
示例12: apply
public function apply(ResponseInterface $respose)
{
return $respose->withAddedHeader(self::HEADER_NAME, (string) $this);
}
示例13: removeToken
/**
* {@inheritdoc}
*/
public function removeToken(Request $request, Response $response, TokenInterface $token)
{
return $response->withAddedHeader('Set-Cookie', $this->cookieHeader($request, null));
}
示例14: mountToken
/**
* {@inheritdoc}
*/
public function mountToken(Request $request, Response $response, TokenInterface $token)
{
return $response->withAddedHeader($this->header, $token->getHash());
}
示例15: withAddedHeader
/**
* {@inheritDoc}
*/
public function withAddedHeader($name, $value)
{
return new self($this->app, $this->decorated->withAddedHeader($name, $value));
}