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


PHP Response::mapType方法代碼示例

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


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

示例1: testMapType

 /**
  * Tests the mapType method
  *
  * @return void
  */
 public function testMapType()
 {
     $response = new Response();
     $this->assertEquals('wav', $response->mapType('audio/x-wav'));
     $this->assertEquals('pdf', $response->mapType('application/pdf'));
     $this->assertEquals('xml', $response->mapType('text/xml'));
     $this->assertEquals('html', $response->mapType('*/*'));
     $this->assertEquals('csv', $response->mapType('application/vnd.ms-excel'));
     $expected = ['json', 'xhtml', 'css'];
     $result = $response->mapType(['application/json', 'application/xhtml+xml', 'text/css']);
     $this->assertEquals($expected, $result);
 }
開發者ID:rashmi,項目名稱:newrepo,代碼行數:17,代碼來源:ResponseTest.php

示例2: _setExtension

 /**
  * Set the extension based on the accept headers.
  * Compares the accepted types and configured extensions.
  * If there is one common type, that is assigned as the ext/content type for the response.
  * The type with the highest weight will be set. If the highest weight has more
  * than one type matching the extensions, the order in which extensions are specified
  * determines which type will be set.
  *
  * If html is one of the preferred types, no content type will be set, this
  * is to avoid issues with browsers that prefer HTML and several other content types.
  *
  * @param \Cake\Network\Request $request The request instance.
  * @param \Cake\Network\Response $response The response instance.
  * @return void
  */
 protected function _setExtension($request, $response)
 {
     $accept = $request->parseAccept();
     if (empty($accept)) {
         return;
     }
     $accepts = $response->mapType($accept);
     $preferedTypes = current($accepts);
     if (array_intersect($preferedTypes, ['html', 'xhtml'])) {
         return;
     }
     $extensions = Router::extensions();
     foreach ($accepts as $types) {
         $ext = array_intersect($extensions, $types);
         if ($ext) {
             $this->ext = current($ext);
             break;
         }
     }
 }
開發者ID:KarimaLadhani,項目名稱:cakephp,代碼行數:35,代碼來源:RequestHandlerComponent.php

示例3: mapType

 /**
  * Maps a content-type back to an alias
  *
  * e.g `mapType('application/pdf'); // returns 'pdf'`
  *
  * @param string|array $ctype Either a string content type to map, or an array of types.
  * @return mixed Aliases for the types provided.
  */
 public function mapType($ctype)
 {
     return parent::mapType($ctype);
 }
開發者ID:alescx,項目名稱:cakephp-tools,代碼行數:12,代碼來源:Mime.php

示例4: _setExtension

 /**
  * Set the extension based on the accept headers.
  * Compares the accepted types and configured extensions.
  * If there is one common type, that is assigned as the ext/content type for the response.
  * The type with the highest weight will be set. If the highest weight has more
  * than one type matching the extensions, the order in which extensions are specified
  * determines which type will be set.
  *
  * If html is one of the preferred types, no content type will be set, this
  * is to avoid issues with browsers that prefer HTML and several other content types.
  *
  * @param \Cake\Network\Request $request The request instance.
  * @param \Cake\Network\Response $response The response instance.
  * @return void
  */
 protected function _setExtension($request, $response)
 {
     $accept = $request->parseAccept();
     if (empty($accept)) {
         return;
     }
     $accepts = $response->mapType($accept);
     $preferredTypes = current($accepts);
     if (array_intersect($preferredTypes, ['html', 'xhtml'])) {
         return;
     }
     $extensions = array_unique(array_merge(Router::extensions(), array_keys($this->config('viewClassMap'))));
     foreach ($accepts as $types) {
         $ext = array_intersect($extensions, $types);
         if (!empty($ext)) {
             $this->ext = current($ext);
             break;
         }
     }
 }
開發者ID:malhan23,項目名稱:assignment-3,代碼行數:35,代碼來源:RequestHandlerComponent.php

示例5: responseType

 /**
  * Returns the current response type (Content-type header), or null if not alias exists
  *
  * @return mixed A string content type alias, or raw content type if no alias map exists,
  *	otherwise null
  */
 public function responseType()
 {
     return $this->response->mapType($this->response->type());
 }
開發者ID:ripzappa0924,項目名稱:carte0.0.1,代碼行數:10,代碼來源:RequestHandlerComponent.php


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