本文整理匯總了PHP中Psr\Http\Message\ServerRequestInterface::withHeader方法的典型用法代碼示例。如果您正苦於以下問題:PHP ServerRequestInterface::withHeader方法的具體用法?PHP ServerRequestInterface::withHeader怎麽用?PHP ServerRequestInterface::withHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Psr\Http\Message\ServerRequestInterface
的用法示例。
在下文中一共展示了ServerRequestInterface::withHeader方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: willReturnNullWhenMatchWasNotFound
/**
* @test
*/
public function willReturnNullWhenMatchWasNotFound()
{
$this->request = $this->request->withHeader('Accept', 'text/html');
$this->negotiator->expects($this->once())->method('getBest')->will($this->returnValue(null));
$bestMatch = $this->manager->getBestMatch($this->request);
$this->assertNull($bestMatch);
}
示例2: __invoke
public function __invoke(ServerRequestInterface $request)
{
$forwardedFor = array();
if ($this->trustPreviousReverseProxies && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$forwardedFor[] = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
}
$forwardedFor[] = $_SERVER['REMOTE_ADDR'];
return $request->withHeader("X-Forwarded-For", implode(",", $forwardedFor));
}
示例3: withHeader
/**
* {@inheritdoc}
*/
public function withHeader($name, $value)
{
return new static($this->wrapped->withHeader($name, $value));
}
示例4: withHeader
/**
* {@inheritDoc}
*/
public function withHeader($name, $value)
{
return new self($this->app, $this->psrRequest->withHeader($name, $value));
}
示例5: assertRequestHeader
/**
* Assert request header and we only accept application/json or ajax request.
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @return \Psr\Http\Message\ServerRequestInterface
* @throws \InvalidArgumentException If Request Accept header not application/json.
*/
protected function assertRequestHeader(Request $request)
{
// If it's an AJAX request, return as is
if ($request->getHeaderLine('X-Requested-With') == 'XMLHttpRequest') {
return $request;
}
// Otherwise, split the Accept header
$accepts = explode(',', $request->getHeaderLine('Accept'));
// Make sure it's accept application/json
if (in_array('application/json', $accepts)) {
return $request->withHeader('X-Requested-With', 'XMLHttpRequest');
}
// Otherwise, throw it
throw new InvalidArgumentException('Invalid request');
}
示例6: withHeader
/**
* Proxy to ServerRequestInterface::withHeader()
*
* {@inheritdoc}
*/
public function withHeader($header, $value)
{
$new = $this->psrRequest->withHeader($header, $value);
return new self($new, $this->originalRequest);
}
示例7: withHeader
/**
* @inheritDoc
*/
public function withHeader($name, $value)
{
$self = clone $this;
$self->serverRequest = $this->serverRequest->withHeader($name, $value);
return $self;
}