file : add fileArray (can not be named 'file' as it is the class name)

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5428 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-08-22 10:19:58 +00:00
parent 45a003930b
commit c280b01ba9

View File

@@ -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 /** Checks whether a file or directory exists
* @param string $filename The file or directory to verify * @param string $filename The file or directory to verify
* @return bool true if the file exists, false otherwise * @return bool true if the file exists, false otherwise