diff --git a/file.php b/file.php index 92791a5..1247aa8 100644 --- a/file.php +++ b/file.php @@ -145,6 +145,33 @@ class file } // }}} + /** Get the file contents in an array (like 'file' function, but can not + * have the same name as the class...) + * @param string $filename Name of the file to read + * @return string Content of the file + * @throws If parent directory not exists, is not readable, the file is not + * exists or is not readable + */ + public function fileArray ($filename) + // {{{ + { + $this->debug (2, "file ($filename)"); + $filename = $this->realpath ($filename); + $this->checkPathRO (dirname ($filename)); + if (! is_file ($filename)) + throw new \Exception (sprintf (dgettext ("domframework", + "File '%s' is not a file"), + $filename), 500); + if (! is_readable ($filename)) + throw new \Exception (sprintf (dgettext ("domframework", + "File '%s' is not readable"), + $filename), 500); + $contents = file ($filename); + $this->debug (1, "file ($filename) => ". count ($contents). " rows"); + return $contents; + } + // }}} + /** Checks whether a file or directory exists * @param string $filename The file or directory to verify * @return bool true if the file exists, false otherwise