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


PHP Response::getFile方法代碼示例

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


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

示例1: getStream

 /**
  * Get the stream for the new response.
  *
  * @param \Cake\Network\Response $response The cake response to extract the body from.
  * @return \Psr\Http\Message\StreamInterface|string The stream.
  */
 protected static function getStream($response)
 {
     $stream = 'php://memory';
     $body = $response->body();
     if (is_string($body) && strlen($body)) {
         $stream = new Stream('php://memory', 'wb');
         $stream->write($body);
         return $stream;
     }
     if (is_callable($body)) {
         $stream = new CallbackStream($body);
         return $stream;
     }
     $file = $response->getFile();
     if ($file) {
         $stream = new Stream($file->path, 'rb');
         return $stream;
     }
     return $stream;
 }
開發者ID:nrother,項目名稱:cakephp,代碼行數:26,代碼來源: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: assertFileResponse

 /**
  * Asserts that a file with the given name was sent in the response
  *
  * @param string $expected The file name that should be sent in the response
  * @param string $message The failure message that will be appended to the generated message.
  * @return void
  */
 public function assertFileResponse($expected, $message = '')
 {
     if ($this->_response === null) {
         $this->fail('No response set, cannot assert file.');
     }
     $actual = isset($this->_response->getFile()->path) ? $this->_response->getFile()->path : null;
     if ($actual === null) {
         $this->fail('No file was sent in this response');
     }
     $this->assertEquals($expected, $actual, $message);
 }
開發者ID:aceat64,項目名稱:cakephp,代碼行數:18,代碼來源:IntegrationTestCase.php


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