diff --git a/Filesystem.php b/Filesystem.php index 7e13571c9e..8495001cc5 100644 --- a/Filesystem.php +++ b/Filesystem.php @@ -478,4 +478,22 @@ private function toIterator($files) return $files; } + + /** + * Read file and return contents. + * + * @param $filename + * + * @return string $filename The file to read. + * + * @throws Exception\IOException + */ + public function readFile($filename) + { + if (false === $source = @file_get_contents($filename)) { + throw new IOException(sprintf('Failed to read "%s" because source file could not be opened for reading.', $filename), 0, null, $filename); + } + + return $source; + } } diff --git a/README.md b/README.md index 7d8a4749ed..ca18b8e1e9 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,9 @@ $filesystem->makePathRelative($endPath, $startPath); $filesystem->mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array()); $filesystem->isAbsolutePath($file); + +$filesystem->readFile($file); + ``` Resources