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


PHP Response::file方法代码示例

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


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

示例1: toCake

 /**
  * Convert a PSR7 Response into a CakePHP one.
  *
  * @param \Psr\Http\Message\ResponseInterface $response The response to convert.
  * @return \Cake\Network\Response The equivalent CakePHP response
  */
 public static function toCake(PsrResponse $response)
 {
     $body = static::getBody($response);
     $data = ['status' => $response->getStatusCode(), 'body' => $body['body']];
     $cake = new CakeResponse($data);
     if ($body['file']) {
         $cake->file($body['file']);
     }
     $cookies = static::parseCookies($response->getHeader('Set-Cookie'));
     foreach ($cookies as $cookie) {
         $cake->cookie($cookie);
     }
     $headers = static::collapseHeaders($response);
     $cake->header($headers);
     if (!empty($headers['Content-Type'])) {
         $cake->type($headers['Content-Type']);
     }
     return $cake;
 }
开发者ID:nrother,项目名称:cakephp,代码行数:25,代码来源:ResponseTransformer.php

示例2: testGetFile

 /**
  * test getFile method
  *
  * @return void
  */
 public function testGetFile()
 {
     $response = new Response();
     $this->assertNull($response->getFile(), 'No file to get');
     $response->file(TEST_APP . 'vendor/css/test_asset.css');
     $file = $response->getFile();
     $this->assertInstanceOf('Cake\\Filesystem\\File', $file, 'Should get a file');
     $this->assertPathEquals(TEST_APP . 'vendor' . DS . 'css' . DS . 'test_asset.css', $file->path);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:14,代码来源:ResponseTest.php

示例3: testFileWithDotsInAPathFragment

 /**
  * test file with .. in a path fragment
  *
  * @expectedException \Cake\Network\Exception\NotFoundException
  * @expectedExceptionMessage my/ca..t/image.gif was not found or not readable
  * @return void
  */
 public function testFileWithDotsInAPathFragment()
 {
     $response = new Response();
     $response->file('my/ca..t/image.gif');
 }
开发者ID:kfer10,项目名称:excel,代码行数:12,代码来源:ResponseTest.php

示例4: testFileWithDotIntheName

 /**
  * test file with ..
  *
  * @expectedException \Cake\Network\Exception\NotFoundException
  * @expectedExceptionMessage my/ca..t.gif was not found or not readable
  * @return void
  */
 public function testFileWithDotIntheName()
 {
     $response = new Response();
     $response->file('my/ca..t.gif');
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:12,代码来源:ResponseTest.php

示例5: testFileWithPathTraversal

 /**
  * test file with ..
  *
  * @expectedException \Cake\Network\Exception\NotFoundException
  * @return void
  */
 public function testFileWithPathTraversal()
 {
     $response = new Response();
     $response->file('my/../cat.gif');
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:11,代码来源:ResponseTest.php

示例6: _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 \Cake\Network\Response The updated response.
  */
 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->file($assetFile);
     return $response;
 }
开发者ID:nrother,项目名称:cakephp,代码行数:27,代码来源:AssetFilter.php


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