An extension of SplFileObject
that uses exceptions.
You would use this class the exact same way you use SplFileObject
, because
it is SplFileObject
. The only difference is that errors will throw an
exception when they occur.
use KHerGe\File\File;
$file = new File('example.txt');
$file->fseek(-1);
/*
* Fatal error: Uncaught exception 'KHerGe\File\Exception\FileException' with message 'The file "test.txt" could not be seeked.' in /path/to/file/src/lib/KHerGe/File/Exception/FileException.php on line 157
*
* KHerGe\File\Exception\FileException: The file "test.txt" could not be seeked. in /path/to/file/src/lib/KHerGe/File/Exception/FileException.php on line 157
*
* Call Stack:
* 0.0001 248992 1. {main}() /path/to/file/test.php:0
* 0.0011 382928 2. KHerGe\File\File->fseek() /path/to/file/test.php:6
*/
Exceptions originally thrown by
SplFileObject
will also be wrapped in theFileException
class included with this library.
- PHP >= 5.4
Via Composer:
$ composer require "kherge/file=dev-master"
I recommend that you install the most recent stable release. You can find one on Packagist, the GitHub releases page, or the tag list in the Git repository.
This library is available under the MIT license.