本文整理汇总了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;
}