Skip to content
Permalink
Browse files

Add Response::getFile()

Right now if you need to get the file from inside the response, you have
to use reflection tricks. Which makes me sad as I try to build out the
PSR7 bridge for CakePHP. Having a method will be much nicer.
  • Loading branch information...
markstory committed Feb 23, 2016
1 parent fd98737 commit 0e6a509ea02081ac17250612d78ed82101c8ca51
Showing with 27 additions and 0 deletions.
  1. +10 −0 src/Network/Response.php
  2. +17 −0 tests/TestCase/Network/ResponseTest.php
@@ -1457,6 +1457,16 @@ public function file($path, array $options = [])
$this->_file = $file;
}
/**
* Get the current file if one exists.
*
* @return \Cake\Filesystem\File|null The file to use in the response or null
*/
public function getFile()
{
return $this->_file;
}
/**
* Apply a file range to a file and set the end offset.
*
@@ -1536,6 +1536,23 @@ public function testFileWithUnknownFileNoDownload()
}
}
/**
* test getFile method
*
* @return void
*/
public function testGetFile()
{
ob_start();
$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->assertSame(TEST_APP . 'vendor/css/test_asset.css', $file->path, 'Path should match');
}
/**
* testConnectionAbortedOnBuffering method
*

0 comments on commit 0e6a509

Please sign in to comment.
You can’t perform that action at this time.