[HttpFoundation] Added File::getContent()

This commit is contained in:
Grégoire Pineau 2020-07-02 11:52:45 +02:00
parent 70ebf7e912
commit 50d5167a66
3 changed files with 19 additions and 0 deletions

View File

@ -5,6 +5,7 @@ CHANGELOG
-----
* added `HeaderUtils::parseQuery()`: it does the same as `parse_str()` but preserves dots in variable names
* added `File::getContent()`
5.1.0
-----

View File

@ -104,6 +104,17 @@ class File extends \SplFileInfo
return $target;
}
public function getContent(): string
{
$content = file_get_contents($this->getPathname());
if (false === $content) {
throw new FileException(sprintf('Could not get the content of the file "%s".', $this->getPathname()));
}
return $content;
}
/**
* @return self
*/

View File

@ -85,6 +85,13 @@ class FileTest extends TestCase
@unlink($targetPath);
}
public function testGetContent()
{
$file = new File(__FILE__);
$this->assertStringEqualsFile(__FILE__, $file->getContent());
}
public function getFilenameFixtures()
{
return [