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


PHP Response::compress方法代码示例

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


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

示例1: _deliverAsset

 /**
  * Sends an asset file to the client
  *
  * @param \Cake\Network\Request $request The request object to use.
  * @param \Cake\Network\Response $response The response object to use.
  * @param string $assetFile Path to the asset file in the file system
  * @param string $ext The extension of the file to determine its mime type
  * @return void
  */
 protected function _deliverAsset(Request $request, Response $response, $assetFile, $ext)
 {
     $compressionEnabled = $response->compress();
     if ($response->type($ext) === $ext) {
         $contentType = 'application/octet-stream';
         $agent = $request->env('HTTP_USER_AGENT');
         if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
             $contentType = 'application/octetstream';
         }
         $response->type($contentType);
     }
     if (!$compressionEnabled) {
         $response->header('Content-Length', filesize($assetFile));
     }
     // $response->cache(filemtime($assetFile), $this->_cacheTime);
     $response->sendHeaders();
     readfile($assetFile);
     if ($compressionEnabled) {
         ob_end_flush();
     }
 }
开发者ID:scherersoftware,项目名称:cake-cms,代码行数:30,代码来源:WidgetAssetFilter.php

示例2: testCompress

 /**
  * Tests the compress method
  *
  * @return void
  */
 public function testCompress()
 {
     $this->skipIf(defined('HHVM_VERSION'), 'HHVM does not implement ob_gzhandler');
     $response = new Response();
     if (ini_get("zlib.output_compression") === '1' || !extension_loaded("zlib")) {
         $this->assertFalse($response->compress());
         $this->markTestSkipped('Is not possible to test output compression');
     }
     $_SERVER['HTTP_ACCEPT_ENCODING'] = '';
     $result = $response->compress();
     $this->assertFalse($result);
     $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip';
     $result = $response->compress();
     $this->assertTrue($result);
     $this->assertTrue(in_array('ob_gzhandler', ob_list_handlers()));
     ob_get_clean();
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:22,代码来源:ResponseTest.php

示例3: _deliverCacheFile

 /**
  * Sends an asset file to the client
  *
  * @param \Cake\Network\Request $request The request object to use.
  * @param \Cake\Network\Response $response The response object to use.
  * @param string $assetFile Path to the asset file in the file system
  * @param string $ext The extension of the file to determine its mime type
  * @return void
  */
 protected function _deliverCacheFile(Request $request, Response $response, $file, $ext)
 {
     $compressionEnabled = $response->compress();
     if ($response->type($ext) === $ext) {
         $contentType = 'application/octet-stream';
         $agent = $request->env('HTTP_USER_AGENT');
         if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
             $contentType = 'application/octetstream';
         }
         $response->type($contentType);
     }
     if (!$compressionEnabled) {
         $response->header('Content-Length', filesize($file));
     }
     $content = file_get_contents($file);
     $cacheInfo = $this->extractCacheInfo($content);
     $modifiedTime = filemtime($file);
     $cacheTime = $cacheInfo['time'];
     if (!$cacheTime) {
         $cacheTime = $this->_cacheTime;
     }
     $response->cache($modifiedTime, $cacheTime);
     $response->type($cacheInfo['ext']);
     if (Configure::read('debug') || $this->config('debug')) {
         if ($cacheInfo['ext'] === 'html') {
             $content = '<!--created:' . $modifiedTime . '-->' . $content;
         }
     }
     $response->body($content);
 }
开发者ID:jxav,项目名称:cakephp-cache,代码行数:39,代码来源:CacheFilter.php

示例4: testCompress

 /**
  * Tests the compress method
  *
  * @return void
  */
 public function testCompress()
 {
     if (php_sapi_name() !== 'cli') {
         $this->markTestSkipped('The response compression can only be tested in cli.');
     }
     $response = new Response();
     if (ini_get("zlib.output_compression") === '1' || !extension_loaded("zlib")) {
         $this->assertFalse($response->compress());
         $this->markTestSkipped('Is not possible to test output compression');
     }
     $_SERVER['HTTP_ACCEPT_ENCODING'] = '';
     $result = $response->compress();
     $this->assertFalse($result);
     $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip';
     $result = $response->compress();
     $this->assertTrue($result);
     $this->assertTrue(in_array('ob_gzhandler', ob_list_handlers()));
     ob_get_clean();
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:24,代码来源:ResponseTest.php


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