當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HTTP::request_headers方法代碼示例

本文整理匯總了PHP中HTTP::request_headers方法的典型用法代碼示例。如果您正苦於以下問題:PHP HTTP::request_headers方法的具體用法?PHP HTTP::request_headers怎麽用?PHP HTTP::request_headers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在HTTP的用法示例。


在下文中一共展示了HTTP::request_headers方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: headers

 /**
  * Gets or sets HTTP headers oo the request. All headers
  * are included immediately after the HTTP protocol definition during
  * transmission. This method provides a simple array or key/value
  * interface to the headers.
  *
  * @param   mixed   $key   Key or array of key/value pairs to set
  * @param   string  $value Value to set to the supplied key
  * @return  mixed
  */
 public function headers($key = NULL, $value = NULL)
 {
     if ($key instanceof HTTP_Header) {
         // Act a setter, replace all headers
         $this->_header = $key;
         return $this;
     }
     if (is_array($key)) {
         // Act as a setter, replace all headers
         $this->_header->exchangeArray($key);
         return $this;
     }
     if ($this->_header->count() === 0 and $this->is_initial()) {
         // Lazy load the request headers
         $this->_header = HTTP::request_headers();
     }
     if ($key === NULL) {
         // Act as a getter, return all headers
         return $this->_header;
     } elseif ($value === NULL) {
         // Act as a getter, single header
         return $this->_header->offsetExists($key) ? $this->_header->offsetGet($key) : NULL;
     }
     // Act as a setter for a single header
     $this->_header[$key] = $value;
     return $this;
 }
開發者ID:benshez,項目名稱:DreamWeddingCeremomies,代碼行數:37,代碼來源:Request.php

示例2: test_request_headers

 /**
  * Tests HTTP::request_headers()
  *
  * HTTP::request_headers relies on the $_SERVER superglobal if the function
  * `apache_request_headers` or the PECL `http` extension are not available.
  *
  * The test feeds the $_SERVER superglobal with the test cases' datasets
  * and then restores the $_SERVER superglobal so that it does not affect
  * other tests.
  *
  * @test
  * @dataProvider provider_request_headers
  * @param array  $server_globals      globals to feed $_SERVER
  * @param array  $expected_headers    Expected, cleaned HTTP headers
  */
 public function test_request_headers(array $server_globals, array $expected_headers)
 {
     // save the $_SERVER super-global into temporary local var
     $tmp_server = $_SERVER;
     $_SERVER = array_replace_recursive($_SERVER, $server_globals);
     $headers = HTTP::request_headers();
     $actual_headers = array_intersect_key($headers->getArrayCopy(), $expected_headers);
     $this->assertSame($expected_headers, $actual_headers);
     // revert the super-global to its previous state
     $_SERVER = $tmp_server;
 }
開發者ID:Chinese1904,項目名稱:openclassifieds2,代碼行數:26,代碼來源:HTTPTest.php


注:本文中的HTTP::request_headers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。