[HttpFoundation] Added File::getContent()
This commit is contained in:
parent
70ebf7e912
commit
50d5167a66
@ -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
|
||||
-----
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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 [
|
||||
|
Reference in New Issue
Block a user