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


PHP Response::getMimeType方法代码示例

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


在下文中一共展示了Response::getMimeType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeRender

 /**
  * Checks if the response can be considered different according to the request
  * headers, and the caching response headers. If it was not modified, then the
  * render process is skipped. And the client will get a blank response with a
  * "304 Not Modified" header.
  *
  * - If Router::extensions() is enabled, the layout and template type are
  *   switched based on the parsed extension or Accept-Type header. For example,
  *   if `controller/action.xml` is requested, the view path becomes
  *   `app/View/Controller/xml/action.ctp`. Also if `controller/action` is
  *   requested with `Accept-Type: application/xml` in the headers the view
  *   path will become `app/View/Controller/xml/action.ctp`. Layout and template
  *   types will only switch to mime-types recognized by Cake\Network\Response.
  *   If you need to declare additional mime-types, you can do so using
  *   Cake\Network\Response::type() in your controller's beforeFilter() method.
  * - If a helper with the same name as the extension exists, it is added to
  *   the controller.
  * - If the extension is of a type that RequestHandler understands, it will
  *   set that Content-type in the response header.
  *
  * @param Event $event The Controller.beforeRender event.
  * @return bool false if the render process should be aborted
  */
 public function beforeRender(Event $event)
 {
     $isRecognized = !in_array($this->ext, ['html', 'htm']) && $this->response->getMimeType($this->ext);
     if (!empty($this->ext) && $isRecognized) {
         $this->renderAs($event->subject(), $this->ext);
     } elseif (empty($this->ext) || in_array($this->ext, ['html', 'htm'])) {
         $this->respondAs('html', ['charset' => Configure::read('App.encoding')]);
     }
     if ($this->_config['checkHttpCache'] && $this->response->checkNotModified($this->request)) {
         return false;
     }
 }
开发者ID:malhan23,项目名称:assignment-3,代码行数:35,代码来源:RequestHandlerComponent.php

示例2: startup

 /**
  * The startup method of the RequestHandler enables several automatic behaviors
  * related to the detection of certain properties of the HTTP request, including:
  *
  * - If Router::extensions() is enabled, the layout and template type are
  *   switched based on the parsed extension or Accept-Type header. For example, if `controller/action.xml`
  *   is requested, the view path becomes `app/View/Controller/xml/action.ctp`. Also if
  *   `controller/action` is requested with `Accept-Type: application/xml` in the headers
  *   the view path will become `app/View/Controller/xml/action.ctp`. Layout and template
  *   types will only switch to mime-types recognized by Cake\Network\Response. If you need to declare
  *   additional mime-types, you can do so using Cake\Network\Response::type() in your controller's beforeFilter()
  *   method.
  * - If a helper with the same name as the extension exists, it is added to the controller.
  * - If the extension is of a type that RequestHandler understands, it will set that
  *   Content-type in the response header.
  * - If the XML data is POSTed, the data is parsed into an XML object, which is assigned
  *   to the $data property of the controller, which can then be saved to a model object.
  *
  * @param Event $event The startup event that was fired.
  * @return void
  */
 public function startup(Event $event)
 {
     $controller = $event->subject();
     $request = $controller->request;
     if (isset($request->params['_ext'])) {
         $this->ext = $request->params['_ext'];
     }
     if (empty($this->ext) || in_array($this->ext, ['html', 'htm'])) {
         $this->_setExtension($request, $this->response);
     }
     if (empty($this->ext) && $request->is('ajax')) {
         $this->ext = 'ajax';
     }
     $request->params['isAjax'] = $this->request->is('ajax');
     $isRecognized = !in_array($this->ext, ['html', 'htm']) && $this->response->getMimeType($this->ext);
     if (!empty($this->ext) && $isRecognized) {
         $this->renderAs($controller, $this->ext);
     } elseif (empty($this->ext) || in_array($this->ext, ['html', 'htm'])) {
         $this->respondAs('html', ['charset' => Configure::read('App.encoding')]);
     }
     foreach ($this->_inputTypeMap as $type => $handler) {
         if ($this->requestedWith($type)) {
             $input = call_user_func_array([$request, 'input'], $handler);
             $request->data = (array) $input;
         }
     }
 }
开发者ID:KarimaLadhani,项目名称:cakephp,代码行数:48,代码来源:RequestHandlerComponent.php

示例3: assertContentType

 /**
  * Asserts content type
  *
  * @param string $type The content-type to check for.
  * @param string $message The failure message that will be appended to the generated message.
  * @return void
  */
 public function assertContentType($type, $message = '')
 {
     if (!$this->_response) {
         $this->fail('No response set, cannot assert content-type. ' . $message);
     }
     $alias = $this->_response->getMimeType($type);
     if ($alias !== false) {
         $type = $alias;
     }
     $result = $this->_response->type();
     $this->assertEquals($type, $result, $message);
 }
开发者ID:hossain-seaos,项目名称:cakephp,代码行数:19,代码来源:IntegrationTestCase.php

示例4: media

 /**
  * Returns an audio/video element
  *
  * ### Usage
  *
  * Using an audio file:
  *
  * ```
  * echo $this->Html->media('audio.mp3', ['fullBase' => true]);
  * ```
  *
  * Outputs:
  *
  * `<video src="http://www.somehost.com/files/audio.mp3">Fallback text</video>`
  *
  * Using a video file:
  *
  * ```
  * echo $this->Html->media('video.mp4', ['text' => 'Fallback text']);
  * ```
  *
  * Outputs:
  *
  * `<video src="/files/video.mp4">Fallback text</video>`
  *
  * Using multiple video files:
  *
  * ```
  * echo $this->Html->media(
  *      ['video.mp4', ['src' => 'video.ogv', 'type' => "video/ogg; codecs='theora, vorbis'"]],
  *      ['tag' => 'video', 'autoplay']
  * );
  * ```
  *
  * Outputs:
  *
  * ```
  * <video autoplay="autoplay">
  *      <source src="/files/video.mp4" type="video/mp4"/>
  *      <source src="/files/video.ogv" type="video/ogv; codecs='theora, vorbis'"/>
  * </video>
  * ```
  *
  * ### Options
  *
  * - `tag` Type of media element to generate, either "audio" or "video".
  *  If tag is not provided it's guessed based on file's mime type.
  * - `text` Text to include inside the audio/video tag
  * - `pathPrefix` Path prefix to use for relative URLs, defaults to 'files/'
  * - `fullBase` If provided the src attribute will get a full address including domain name
  *
  * @param string|array $path Path to the video file, relative to the webroot/{$options['pathPrefix']} directory.
  *  Or an array where each item itself can be a path string or an associate array containing keys `src` and `type`
  * @param array $options Array of HTML attributes, and special options above.
  * @return string Generated media element
  */
 public function media($path, array $options = [])
 {
     $options += ['tag' => null, 'pathPrefix' => 'files/', 'text' => ''];
     if (!empty($options['tag'])) {
         $tag = $options['tag'];
     } else {
         $tag = null;
     }
     if (is_array($path)) {
         $sourceTags = '';
         foreach ($path as &$source) {
             if (is_string($source)) {
                 $source = ['src' => $source];
             }
             if (!isset($source['type'])) {
                 $ext = pathinfo($source['src'], PATHINFO_EXTENSION);
                 $source['type'] = $this->response->getMimeType($ext);
             }
             $source['src'] = $this->Url->assetUrl($source['src'], $options);
             $sourceTags .= $this->formatTemplate('tagselfclosing', ['tag' => 'source', 'attrs' => $this->templater()->formatAttributes($source)]);
         }
         unset($source);
         $options['text'] = $sourceTags . $options['text'];
         unset($options['fullBase']);
     } else {
         if (empty($path) && !empty($options['src'])) {
             $path = $options['src'];
         }
         $options['src'] = $this->Url->assetUrl($path, $options);
     }
     if ($tag === null) {
         if (is_array($path)) {
             $mimeType = $path[0]['type'];
         } else {
             $mimeType = $this->response->getMimeType(pathinfo($path, PATHINFO_EXTENSION));
         }
         if (preg_match('#^video/#', $mimeType)) {
             $tag = 'video';
         } else {
             $tag = 'audio';
         }
     }
     if (isset($options['poster'])) {
         $options['poster'] = $this->Url->assetUrl($options['poster'], ['pathPrefix' => Configure::read('App.imageBaseUrl')] + $options);
//.........这里部分代码省略.........
开发者ID:tgr0ss,项目名称:cakephp,代码行数:101,代码来源:HtmlHelper.php

示例5: startup

 /**
  * The startup method of the RequestHandler enables several automatic behaviors
  * related to the detection of certain properties of the HTTP request, including:
  *
  * - If Router::extensions() is enabled, the layout and template type are
  *   switched based on the parsed extension or Accept-Type header. For example, if `controller/action.xml`
  *   is requested, the view path becomes `app/View/Controller/xml/action.ctp`. Also if
  *   `controller/action` is requested with `Accept-Type: application/xml` in the headers
  *   the view path will become `app/View/Controller/xml/action.ctp`. Layout and template
  *   types will only switch to mime-types recognized by Cake\Network\Response. If you need to declare
  *   additional mime-types, you can do so using Cake\Network\Response::type() in your controllers beforeFilter()
  *   method.
  * - If a helper with the same name as the extension exists, it is added to the controller.
  * - If the extension is of a type that RequestHandler understands, it will set that
  *   Content-type in the response header.
  * - If the XML data is POSTed, the data is parsed into an XML object, which is assigned
  *   to the $data property of the controller, which can then be saved to a model object.
  *
  * @param Event $event The startup event that was fired.
  * @return void
  */
 public function startup(Event $event)
 {
     $controller = $event->subject();
     $controller->request->params['isAjax'] = $this->request->is('ajax');
     $isRecognized = !in_array($this->ext, array('html', 'htm')) && $this->response->getMimeType($this->ext);
     if (!empty($this->ext) && $isRecognized) {
         $this->renderAs($controller, $this->ext);
     } elseif (empty($this->ext) || in_array($this->ext, array('html', 'htm'))) {
         $this->respondAs('html', array('charset' => Configure::read('App.encoding')));
     }
     foreach ($this->_inputTypeMap as $type => $handler) {
         if ($this->requestedWith($type)) {
             $input = call_user_func_array(array($controller->request, 'input'), $handler);
             $controller->request->data = $input;
         }
     }
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:38,代码来源:RequestHandlerComponent.php

示例6: testConstruct

 /**
  * Tests the request object constructor
  *
  * @return void
  */
 public function testConstruct()
 {
     $response = new Response();
     $this->assertNull($response->body());
     $this->assertEquals('UTF-8', $response->charset());
     $this->assertEquals('text/html', $response->type());
     $this->assertEquals(200, $response->statusCode());
     $options = ['body' => 'This is the body', 'charset' => 'my-custom-charset', 'type' => 'mp3', 'status' => '203'];
     $response = new Response($options);
     $this->assertEquals('This is the body', $response->body());
     $this->assertEquals('my-custom-charset', $response->charset());
     $this->assertEquals('audio/mpeg', $response->type());
     $this->assertEquals(203, $response->statusCode());
     $options = ['body' => 'This is the body', 'charset' => 'my-custom-charset', 'type' => 'mp3', 'status' => '422', 'statusCodes' => [422 => 'Unprocessable Entity']];
     $response = new Response($options);
     $this->assertEquals($options['body'], $response->body());
     $this->assertEquals($options['charset'], $response->charset());
     $this->assertEquals($response->getMimeType($options['type']), $response->type());
     $this->assertEquals($options['status'], $response->statusCode());
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:25,代码来源:ResponseTest.php

示例7: mapAlias

 /**
  * Maps a content type alias back to its mime-type(s)
  *
  * @param string|array $alias String alias to convert back into a content type. Or an array of aliases to map.
  * @return string Null on an undefined alias. String value of the mapped alias type. If an
  *   alias maps to more than one content type, the first one will be returned.
  */
 public function mapAlias($alias)
 {
     if (is_array($alias)) {
         return array_map(array($this, 'mapAlias'), $alias);
     }
     $type = $this->response->getMimeType($alias);
     if ($type) {
         if (is_array($type)) {
             return $type[0];
         }
         return $type;
     }
     return null;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:21,代码来源:RequestHandlerComponent.php


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