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


PHP CakeRequest::accepts方法代碼示例

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


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

示例1: accepts

 /**
  * Determines which content types the client accepts.  Acceptance is based on
  * the file extension parsed by the Router (if present), and by the HTTP_ACCEPT
  * header. Unlike CakeRequest::accepts() this method deals entirely with mapped content types.
  *
  * Usage:
  *
  * `$this->RequestHandler->accepts(array('xml', 'html', 'json'));`
  *
  * Returns true if the client accepts any of the supplied types.
  *
  * `$this->RequestHandler->accepts('xml');`
  *
  * Returns true if the client accepts xml.
  *
  * @param mixed $type Can be null (or no parameter), a string type name, or an
  *   array of types
  * @return mixed If null or no parameter is passed, returns an array of content
  *   types the client accepts.  If a string is passed, returns true
  *   if the client accepts it.  If an array is passed, returns true
  *   if the client accepts one or more elements in the array.
  * @see RequestHandlerComponent::setContent()
  */
 public function accepts($type = null)
 {
     $accepted = $this->request->accepts();
     if ($type == null) {
         return $this->mapType($accepted);
     } elseif (is_array($type)) {
         foreach ($type as $t) {
             $t = $this->mapAlias($t);
             if (in_array($t, $accepted)) {
                 return true;
             }
         }
         return false;
     } elseif (is_string($type)) {
         $type = $this->mapAlias($type);
         return in_array($type, $accepted);
     }
     return false;
 }
開發者ID:gilyaev,項目名稱:framework-bench,代碼行數:42,代碼來源:RequestHandlerComponent.php

示例2: accepts

 /**
  * Determines which content types the client accepts. Acceptance is based on
  * the file extension parsed by the Router (if present), and by the HTTP_ACCEPT
  * header. Unlike CakeRequest::accepts() this method deals entirely with mapped content types.
  *
  * Usage:
  *
  * `$this->RequestHandler->accepts(array('xml', 'html', 'json'));`
  *
  * Returns true if the client accepts any of the supplied types.
  *
  * `$this->RequestHandler->accepts('xml');`
  *
  * Returns true if the client accepts xml.
  *
  * @param string|array $type Can be null (or no parameter), a string type name, or an
  *                           array of types
  *
  * @return mixed If null or no parameter is passed, returns an array of content
  *   types the client accepts. If a string is passed, returns true
  *   if the client accepts it. If an array is passed, returns true
  *   if the client accepts one or more elements in the array.
  * @see RequestHandlerComponent::setContent()
  */
 public function accepts($type = NULL)
 {
     $accepted = $this->request->accepts();
     if (!$type) {
         return $this->mapType($accepted);
     }
     if (is_array($type)) {
         foreach ($type as $t) {
             $t = $this->mapAlias($t);
             if (in_array($t, $accepted)) {
                 return TRUE;
             }
         }
         return FALSE;
     }
     if (is_string($type)) {
         return in_array($this->mapAlias($type), $accepted);
     }
     return FALSE;
 }
開發者ID:mrbadao,項目名稱:api-official,代碼行數:44,代碼來源:RequestHandlerComponent.php

示例3: testAcceptWithQvalueSorting

 /**
  * Content types from accepts() should respect the client's q preference values.
  *
  * @return void
  */
 public function testAcceptWithQvalueSorting()
 {
     $_SERVER['HTTP_ACCEPT'] = 'text/html;q=0.8,application/json;q=0.7,application/xml;q=1.0';
     $request = new CakeRequest('/', false);
     $result = $request->accepts();
     $expected = array('application/xml', 'text/html', 'application/json');
     $this->assertEquals($expected, $result);
 }
開發者ID:xMyThoLoGyx,項目名稱:centremedicaletp3,代碼行數:13,代碼來源:CakeRequestTest.php

示例4: testAccepts

 /**
  * test accepts() with and without parameters
  *
  * @return void
  */
 function testAccepts()
 {
     $_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml;q=0.9,application/xhtml+xml,text/html,text/plain,image/png';
     $request = new CakeRequest('/', false);
     $result = $request->accepts();
     $expected = array('text/xml', 'application/xml', 'application/xhtml+xml', 'text/html', 'text/plain', 'image/png');
     $this->assertEquals($expected, $result, 'Content types differ.');
     $result = $request->accepts('text/html');
     $this->assertTrue($result);
     $result = $request->accepts('image/gif');
     $this->assertFalse($result);
 }
開發者ID:robotarmy,項目名稱:Phog,代碼行數:17,代碼來源:cake_request.test.php


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