Further split out Class.Basic

- Email/File/Hash class update
- add random key, running time
- get system calls
- Debug classes for logging, running time, etc
This commit is contained in:
Clemens Schwaighofer
2021-06-08 18:08:42 +09:00
parent 4ae1c2bde0
commit e80915cd5c
28 changed files with 1358 additions and 483 deletions

View File

@@ -0,0 +1,61 @@
<?php declare(strict_types=1);
/*
* direct write to log file
* must have BASE folder and LOG foder defined
*/
namespace CoreLibs\Debug;
class FileWriter
{
private static $debug_filename = 'debug_file.log'; // where to write output
/**
* set new debug file name
* Must be alphanumeric and underscore only.
* Must end with .log
*
* @param string $filename File name to set
* @return bool True for valid file name, False if invalid
*/
public static function fsetFilename(string $filename): bool
{
// valid file. must be only ascii & _, must end with .log
if (!preg_match("/^[A-Za-z_-]+\.log$/", $filename)) {
return false;
}
self::$debug_filename = $filename;
return true;
}
/**
* writes a string to a file immediatly, for fast debug output
* @param string $string string to write to the file
* @param boolean $enter default true, if set adds a linebreak \n at the end
* @return bool True for log written, false for not wirrten
*/
public static function fdebug(string $string, bool $enter = true): bool
{
if (!self::$debug_filename) {
return false;
}
if (!is_writeable(BASE.LOG)) {
return false;
}
$filename = BASE.LOG.self::$debug_filename;
$fh = fopen($filename, 'a');
if ($fh === false) {
return false;
}
if ($enter === true) {
$string .= "\n";
}
$string = "[".\CoreLibs\Debug\Support::printTime()."] [".\CoreLibs\Get\System::getPageName(2)."] - ".$string;
fwrite($fh, $string);
fclose($fh);
return true;
}
}
// __END__