NanoGal/app/Utils.php

46 lines
1.9 KiB
PHP
Raw Normal View History

2024-08-23 16:13:41 +02:00
<?php
namespace Utils;
class Utils {
/**
* Prints debugging information in a styled HTML format.
*
* This method is used for debugging purposes by printing the provided data along with
* the file name and line number where the function was called. The output is wrapped
* in styled HTML tags to enhance readability. It optionally accepts a name to label the output.
*
* @param mixed $data The data to be printed. Can be of any type (e.g., array, object, string).
* @param string $name (optional) A label for the printed data. Default is an empty string.
*
* @return void
*/
static function n_print(mixed $data, string $name = ''): void {
error_reporting(-1);
$aBackTrace = debug_backtrace();
echo '<h2>', $name, '</h2>';
echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">';
echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', $aBackTrace[0]['file'], ' ligne => ', $aBackTrace[0]['line'], '</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '</fieldset><br />';
}
/**
* Checks if the provided path is authorized by ensuring it is within the current working directory.
*
* This method resolves the absolute path of the given directory and compares it with the
* current working directory (getcwd()). If the path is not within the current working directory,
* it is considered unauthorized.
*
* @param string $path The directory path to be validated.
*
* @return bool Returns true if the path is authorized, false otherwise.
*/
static function isPathAuthorized(string $path): bool {
if (!str_contains(realpath($path), getcwd())) {
return false;
}
return true;
}
}