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


PHP CakeRequest::parseAccept方法代碼示例

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


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

示例1: prefers

 /**
  * Determines which content-types the client prefers. If no parameters are given,
  * the single content-type that the client most likely prefers is returned. If $type is
  * an array, the first item in the array that the client accepts is returned.
  * Preference is determined primarily by the file extension parsed by the Router
  * if provided, and secondarily by the list of content-types provided in
  * HTTP_ACCEPT.
  *
  * @param string|array $type An optional array of 'friendly' content-type names, i.e.
  *   'html', 'xml', 'js', etc.
  * @return mixed If $type is null or not provided, the first content-type in the
  *    list, based on preference, is returned. If a single type is provided
  *    a boolean will be returned if that type is preferred.
  *    If an array of types are provided then the first preferred type is returned.
  *    If no type is provided the first preferred type is returned.
  * @see RequestHandlerComponent::setContent()
  */
 public function prefers($type = null)
 {
     $acceptRaw = $this->request->parseAccept();
     if (empty($acceptRaw)) {
         return $this->ext;
     }
     $accepts = $this->mapType(array_shift($acceptRaw));
     if (!$type) {
         if (empty($this->ext) && !empty($accepts)) {
             return $accepts[0];
         }
         return $this->ext;
     }
     $types = (array) $type;
     if (count($types) === 1) {
         if (!empty($this->ext)) {
             return in_array($this->ext, $types);
         }
         return in_array($types[0], $accepts);
     }
     $intersect = array_values(array_intersect($accepts, $types));
     if (empty($intersect)) {
         return false;
     }
     return $intersect[0];
 }
開發者ID:rednazj,項目名稱:Inventory,代碼行數:43,代碼來源:RequestHandlerComponent.php

示例2: testParseAcceptInvalidSyntax

 /**
  * Test that parsing accept headers with invalid syntax works.
  *
  * The header used is missing a q value for application/xml.
  *
  * @return void
  */
 public function testParseAcceptInvalidSyntax()
 {
     $_SERVER['HTTP_ACCEPT'] = 'text/html,application/xhtml+xml,application/xml;image/png,image/jpeg,image/*;q=0.9,*/*;q=0.8';
     $request = new CakeRequest('/', false);
     $result = $request->parseAccept();
     $expected = array('1.0' => array('text/html', 'application/xhtml+xml', 'application/xml', 'image/jpeg'), '0.9' => array('image/*'), '0.8' => array('*/*'));
     $this->assertEquals($expected, $result);
 }
開發者ID:xMyThoLoGyx,項目名稱:centremedicaletp3,代碼行數:15,代碼來源:CakeRequestTest.php

示例3: testParseAcceptWithQValue

 /**
  * Test the raw parsing of accept headers into the q value formatting.
  *
  * @return void
  */
 public function testParseAcceptWithQValue()
 {
     $_SERVER['HTTP_ACCEPT'] = 'text/html;q=0.8,application/json;q=0.7,application/xml;q=1.0,image/png';
     $request = new CakeRequest('/', false);
     $result = $request->parseAccept();
     $expected = array('1.0' => array('application/xml', 'image/png'), '0.8' => array('text/html'), '0.7' => array('application/json'));
     $this->assertEquals($expected, $result);
 }
開發者ID:nabeelio,項目名稱:CakePHP-Base,代碼行數:13,代碼來源:CakeRequestTest.php

示例4: testParseAcceptNoQValues

 /**
  * Test parsing accept with a confusing accept value.
  *
  * @return void
  */
 public function testParseAcceptNoQValues()
 {
     $_SERVER['HTTP_ACCEPT'] = 'application/json, text/plain, */*';
     $request = new CakeRequest('/', false);
     $result = $request->parseAccept();
     $expected = array('1.0' => array('application/json', 'text/plain', '*/*'));
     $this->assertEquals($expected, $result);
 }
開發者ID:cc2i,項目名稱:calibrephp,代碼行數:13,代碼來源:CakeRequestTest.php


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