本文整理汇总了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;
}
示例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);
}
示例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);
}