当前位置: 首页>>代码示例>>PHP>>正文


PHP Headers::add方法代码示例

本文整理汇总了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);
 }
开发者ID:mbarquin,项目名称:reactphp-slim,代码行数:26,代码来源:Request.php

示例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);
 }
开发者ID:mbarquin,项目名称:reactphp-slim,代码行数:30,代码来源:SlimRequest.php

示例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());
 }
开发者ID:slimphp,项目名称:Slim-Http,代码行数:14,代码来源:MessageTest.php

示例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']);
 }
开发者ID:hidayat365,项目名称:phpindonesia.or.id-membership2,代码行数:10,代码来源:HeadersTest.php


注:本文中的Slim\Http\Headers::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。