feat BlueprintAdminLibrary, BlueprintClientLibrary, BlueprintConsoleLibrary: rewrite fileRead() to no longer use shell commands caused by tech-debt

This commit is contained in:
prplwtf 2024-09-08 20:16:56 +02:00
parent b1fe15a628
commit dac362dad5
3 changed files with 27 additions and 6 deletions

View file

@ -101,12 +101,19 @@ class BlueprintAdminLibrary
*
* @param string $path Path to file
* @return string File contents
* @throws string Errors encountered by `cat` shell utility
* @throws string File cannot be read or found
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileRead($path) {
return shell_exec("cat ".escapeshellarg($path).";");
if (!file_exists($path)) {
return "File not found: " . $path;
}
if (!is_readable($path)) {
return "File is not readable: " . $path;
}
return file_get_contents($path);
}
/**

View file

@ -58,12 +58,19 @@ class BlueprintClientLibrary
*
* @param string $path Path to file
* @return string File contents
* @throws string Errors encountered by `cat` shell utility
* @throws string File cannot be read or found
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileRead($path) {
return shell_exec("cat ".escapeshellarg($path).";");
if (!file_exists($path)) {
return "File not found: " . $path;
}
if (!is_readable($path)) {
return "File is not readable: " . $path;
}
return file_get_contents($path);
}
/**

View file

@ -58,12 +58,19 @@ class BlueprintConsoleLibrary
*
* @param string $path Path to file
* @return string File contents
* @throws string Errors encountered by `cat` shell utility
* @throws string File cannot be read or found
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileRead($path) {
return shell_exec("cat ".escapeshellarg($path).";");
if (!file_exists($path)) {
return "File not found: " . $path;
}
if (!is_readable($path)) {
return "File is not readable: " . $path;
}
return file_get_contents($path);
}
/**