當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。