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


PHP Request::accepts方法代码示例

本文整理汇总了PHP中Cake\Network\Request::accepts方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::accepts方法的具体用法?PHP Request::accepts怎么用?PHP Request::accepts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Network\Request的用法示例。


在下文中一共展示了Request::accepts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 Cake\Network\Request::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->response->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:ripzappa0924,项目名称:carte0.0.1,代码行数:43,代码来源:RequestHandlerComponent.php

示例2: testAcceptWithQvalueSorting

 /**
  * Content types from accepts() should respect the client's q preference values.
  *
  * @return void
  */
 public function testAcceptWithQvalueSorting()
 {
     $request = new Request(['environment' => ['HTTP_ACCEPT' => 'text/html;q=0.8,application/json;q=0.7,application/xml;q=1.0']]);
     $result = $request->accepts();
     $expected = ['application/xml', 'text/html', 'application/json'];
     $this->assertEquals($expected, $result);
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:12,代码来源:RequestTest.php


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