utils icon indicating copy to clipboard operation
utils copied to clipboard

Missing `file` support in `Utils/Filesystem`

Open zeleznypa opened this issue 4 years ago • 0 comments

Sometimes it is useful to read the file content "line by line".

It is also handy to have all file manipulation methods in one place.

Unfortunately, the Filesystem class is final, so I can't extend it just for my projects.

But I miss the code like:

    /**
     * Reads file content "line by line".
     *
     * @return array<int,string>
     * @throws Nette\IOException
     */
    public static function readLines(string $file): array
    {
        $content = @file($file); // @ is escalated to exception
        if ($content === false) {
            throw new Nette\IOException("Unable to read file '$file'. " . Helpers::getLastError());
        }
        return $content;
    }

Will it be possible please, to add it or change the Filesystem class as non-final?

zeleznypa avatar Apr 09 '20 07:04 zeleznypa