Skip to content

Add readFile method to Filesystem component #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ $filesystem->makePathRelative($endPath, $startPath);
$filesystem->mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array());

$filesystem->isAbsolutePath($file);

$filesystem->readFile($file);

```

Resources
Expand Down