當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。