本文整理汇总了PHP中Slim\Http\Headers::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Headers::add方法的具体用法?PHP Headers::add怎么用?PHP Headers::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Headers
的用法示例。
在下文中一共展示了Headers::add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFromReactRequest
/**
* Creates a new request object from the data of a reactPHP request object
*
* @param \React\Http\Request $request ReactPHP native request object
*
* @return \Slim\Http\Request
*/
public static function createFromReactRequest(\React\Http\Request $request)
{
$slimHeads = new Headers();
foreach ($request->getHeaders() as $reactHeadKey => $reactHead) {
$slimHeads->add($reactHeadKey, $reactHead);
if ($reactHeadKey === 'Host') {
$host = explode(':', $reactHead);
if (count($host) === 1) {
$host[1] = '80';
}
}
}
$slimUri = new Uri('http', $host[0], (int) $host[1], $request->getPath(), $request->getQuery());
$cookies = [];
$serverParams = $_SERVER;
$serverParams['SERVER_PROTOCOL'] = 'HTTP/' . $request->getHttpVersion();
$slimBody = new RequestBody();
return new self($request->getMethod(), $slimUri, $slimHeads, $cookies, $serverParams, $slimBody);
}
示例2: createFromReactRequest
/**
* Creates a new request object from the data of a reactPHP request object
*
* @param \React\Http\Request $request ReactPHP native request object
* @param string $body Content of received call
*
* @return \Slim\Http\Request
*/
public static function createFromReactRequest(\React\Http\Request $request, $body = '')
{
$slimHeads = new Headers();
$cookies = [];
$host = ['', 80];
foreach ($request->getHeaders() as $reactHeadKey => $reactHead) {
$slimHeads->add($reactHeadKey, $reactHead);
switch ($reactHeadKey) {
case 'Host':
$host = static::getHost($reactHead);
break;
case 'Cookie':
$cookies = Cookies::parseHeader($reactHead);
break;
}
}
$slimUri = new Uri('http', $host[0], (int) $host[1], $request->getPath(), $request->getQuery());
$serverParams = $_SERVER;
$serverParams['SERVER_PROTOCOL'] = 'HTTP/' . $request->getHttpVersion();
$slimBody = static::getBody($body);
return new Request($request->getMethod(), $slimUri, $slimHeads, $cookies, $serverParams, $slimBody);
}
示例3: testWithoutHeader
/**
* @covers Slim\Http\Message::withoutHeader
*/
public function testWithoutHeader()
{
$headers = new Headers();
$headers->add('X-Foo', 'one');
$headers->add('X-Bar', 'two');
$response = new MessageStub();
$response->headers = $headers;
$clone = $response->withoutHeader('X-Foo');
$shouldBe = ['X-Bar' => ['two']];
$this->assertEquals($shouldBe, $clone->getHeaders());
}
示例4: testAddArrayValue
public function testAddArrayValue()
{
$h = new Headers();
$h->add('Foo', 'Bar');
$h->add('Foo', ['Xyz', '123']);
$prop = new ReflectionProperty($h, 'data');
$prop->setAccessible(true);
$this->assertTrue(is_array($prop->getValue($h)['foo']));
$this->assertEquals(['Bar', 'Xyz', '123'], $prop->getValue($h)['foo']['value']);
}