Debug tests update, IO class fixes, support class fixes
Added more tests to debug, form, system class tests IO: max calls check return variable name was wrong Logging: changed from preg to str replace for HTMLPRE tag clean up Debug: empty string debug, returns filled string with dummy text if string is empty() System: return base name as is array Updated Array IO check for loading control array not only from file, but from direct variable if set or from an array filled with control array
This commit is contained in:
@@ -52,6 +52,9 @@ print "S::GETCALLERMETHOD: ".DebugSupport::getCallerMethod(0)."<br>";
|
||||
print "S::GETCALLERMETHOD: ".test()."<br>";
|
||||
print "S::PRINTAR: ".DebugSupport::printAr(['Foo', 'Bar'])."<br>";
|
||||
print "V-S::PRINTAR: ".$debug_support_class::printAr(['Foo', 'Bar'])."<br>";
|
||||
print "S::DEBUSTRING(s): ".DebugSupport::debugString('SET')."<br>";
|
||||
print "S::DEBUSTRING(''): ".DebugSupport::debugString('')."<br>";
|
||||
print "S::DEBUSTRING(,s): ".DebugSupport::debugString(null, '{-}')."<br>";
|
||||
|
||||
// debug
|
||||
print "C->DEBUG: ".$debug->debug('CLASS-TEST-DEBUG', 'Class Test Debug')."<br>";
|
||||
|
||||
@@ -29,6 +29,31 @@ if (!defined('SET_SESSION_NAME')) {
|
||||
$LOG_FILE_ID = 'classTest-form';
|
||||
ob_end_flush();
|
||||
|
||||
// define an array for page use
|
||||
$table_arrays[\CoreLibs\Get\System::getPageName(1)] = [
|
||||
// form fields mtaching up with db fields
|
||||
'table_array' => [
|
||||
],
|
||||
// laod query
|
||||
'load_query' => '',
|
||||
// database table to load from
|
||||
'table_name' => '',
|
||||
// for load dro pdown, format output
|
||||
'show_fields' => [
|
||||
[
|
||||
'name' => 'name'
|
||||
],
|
||||
[
|
||||
'name' => 'enabled',
|
||||
'binary' => ['Yes', 'No'],
|
||||
'before_value' => 'Enabled: '
|
||||
],
|
||||
],
|
||||
// a multi reference entry
|
||||
'element_list' => [
|
||||
]
|
||||
];
|
||||
|
||||
$basic = new CoreLibs\Basic();
|
||||
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG);
|
||||
// $db = new CoreLibs\DB\IO(DB_CONFIG, $basic->log);
|
||||
@@ -37,7 +62,8 @@ print "<html><head><title>TEST CLASS: FORM GENERATE</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
print "TODO<br>";
|
||||
print "MOBILE PHONE: ".$form->mobile_phone."<br>";
|
||||
print "MY PAGE NAME: ".$form->my_page_name."<br>"; // sets table array to include
|
||||
|
||||
// error message
|
||||
print $basic->log->printErrorMsg();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php declare(strict_types=1);
|
||||
<?php // phpcs:ignore warning
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||
*/
|
||||
@@ -39,6 +40,7 @@ print "GETHOSTNAME: ".DgS::printAr(System::getHostName())."<br>";
|
||||
print "GETPAGENAME(0): ".System::getPageName()."<br>";
|
||||
print "GETPAGENAME(1): ".System::getPageName(1)."<br>";
|
||||
print "GETPAGENAME(2): ".System::getPageName(2)."<br>";
|
||||
print "GETPAGENAMEARRAY: ".\CoreLibs\Debug\Support::printAr(System::getPageNameArray())."<br>";
|
||||
// seting errro codes file upload
|
||||
print "FILEUPLOADERRORMESSAGE(): ".System::fileUploadErrorMessage(-1)."<br>";
|
||||
print "FILEUPLOADERRORMESSAGE(UPLOAD_ERR_CANT_WRITE): ".System::fileUploadErrorMessage(UPLOAD_ERR_CANT_WRITE)."<br>";
|
||||
|
||||
@@ -920,7 +920,7 @@ class IO extends \CoreLibs\Basic
|
||||
$max_calls > 0
|
||||
) {
|
||||
$this->MAX_QUERY_CALL = $max_calls;
|
||||
$succes = true;
|
||||
$success = true;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ class Logging
|
||||
*/
|
||||
public function prAr(array $a): string
|
||||
{
|
||||
return '{##HTMLPRE##}'.print_r($a, true).'{##/HTMLPRE##}';
|
||||
return '##HTMLPRE##'.print_r($a, true).'##/HTMLPRE##';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -468,9 +468,9 @@ class Logging
|
||||
.'{'.$class.'} '
|
||||
.'<'.$level.'> - '
|
||||
// strip the htmlpre special tags if exist
|
||||
.preg_replace(
|
||||
"/{##HTMLPRE##}((.|\n)*?){##\/HTMLPRE##}/m",
|
||||
'\\1',
|
||||
.str_replace(
|
||||
['##HTMLPRE##', '##/HTMLPRE##'],
|
||||
'',
|
||||
// if stripping all html, etc is requested, only for write error msg
|
||||
($strip ?
|
||||
// find any <br> and replace them with \n
|
||||
@@ -498,7 +498,11 @@ class Logging
|
||||
// as is prefix, allow HTML
|
||||
.$prefix
|
||||
// we replace special HTMLPRE with <pre> entries
|
||||
.preg_replace("/{##HTMLPRE##}((.|\n)*?){##\/HTMLPRE##}/m", "<pre>\\1</pre>", \CoreLibs\Convert\Html::htmlent($string))
|
||||
.str_replace(
|
||||
['##HTMLPRE##', '##/HTMLPRE##'],
|
||||
['<pre>', '</pre>'],
|
||||
\CoreLibs\Convert\Html::htmlent($string)
|
||||
)
|
||||
."</div><!--#BR#-->";
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -78,6 +78,21 @@ class Support
|
||||
}
|
||||
return $class ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* If a string is empty, sets '-' for return, or if given any other string
|
||||
*
|
||||
* @param string|null $string The string to check
|
||||
* @param string $replace [default '-'] What to replace the empty string with
|
||||
* @return string String itself or the replaced value
|
||||
*/
|
||||
public static function debugString(?string $string, string $replace = '-'): string
|
||||
{
|
||||
if (empty($string)) {
|
||||
return $replace;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -80,6 +80,16 @@ class System
|
||||
return $page_temp['basename'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* similar to getPageName, but it retuns the raw array
|
||||
*
|
||||
* @return array pathinfo array from PHP SELF
|
||||
*/
|
||||
public static function getPageNameArray(): array
|
||||
{
|
||||
return pathinfo($_SERVER['PHP_SELF']);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -260,31 +260,45 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
*/
|
||||
public function __construct(array $db_config, int $table_width = 750)
|
||||
{
|
||||
$this->my_page_name = \CoreLibs\Get\System::getPageName(1);
|
||||
// replace any non valid variable names
|
||||
$this->my_page_name = str_replace(['.'], '_', \CoreLibs\Get\System::getPageName(1));
|
||||
$this->setLangEncoding();
|
||||
// init the language class
|
||||
$this->l = new \CoreLibs\Language\L10n($this->lang);
|
||||
// load config array
|
||||
// get table array definitions for current page name
|
||||
// WARNING: auto spl load does not work with this as it is an array and not a function/object
|
||||
// check if this is the old path or the new path
|
||||
if (is_dir(TABLE_ARRAYS)) {
|
||||
if (is_file(TABLE_ARRAYS.'array_'.$this->my_page_name.'.php')) {
|
||||
include(TABLE_ARRAYS.'array_'.$this->my_page_name.'.php');
|
||||
}
|
||||
|
||||
// first check if we have a in page override as $table_arrays[page name]
|
||||
if (isset($_GLOBALS['table_arrays']) &&
|
||||
is_array($_GLOBALS['table_arrays']) &&
|
||||
isset($_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) &&
|
||||
is_array($_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)])
|
||||
) {
|
||||
$config_array = $_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)];
|
||||
} else {
|
||||
if (is_file(BASE.INCLUDES.TABLE_ARRAYS.'array_'.$this->my_page_name.'.php')) {
|
||||
// WARNING: auto spl load does not work with this as it is an array and not a function/object
|
||||
// check if this is the old path or the new path
|
||||
// check local folder in current path
|
||||
// then check general global folder
|
||||
if (is_dir(TABLE_ARRAYS) &&
|
||||
is_file(TABLE_ARRAYS.'array_'.$this->my_page_name.'.php')
|
||||
) {
|
||||
include(TABLE_ARRAYS.'array_'.$this->my_page_name.'.php');
|
||||
} elseif (is_dir(BASE.INCLUDES.TABLE_ARRAYS) &&
|
||||
is_file(BASE.INCLUDES.TABLE_ARRAYS.'array_'.$this->my_page_name.'.php')
|
||||
) {
|
||||
include(BASE.INCLUDES.TABLE_ARRAYS.'array_'.$this->my_page_name.'.php');
|
||||
}
|
||||
}
|
||||
if (isset(${$this->my_page_name}) && is_array(${$this->my_page_name})) {
|
||||
$config_array = ${$this->my_page_name};
|
||||
} else {
|
||||
// dummy created
|
||||
$config_array = [
|
||||
'table_array' => [],
|
||||
'table_name' => '',
|
||||
];
|
||||
// in the include file there must be a variable with the page name matching
|
||||
if (isset(${$this->my_page_name}) && is_array(${$this->my_page_name})) {
|
||||
$config_array = ${$this->my_page_name};
|
||||
} else {
|
||||
// dummy created
|
||||
$config_array = [
|
||||
'table_array' => [],
|
||||
'table_name' => '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// start the array_io class which will start db_io ...
|
||||
|
||||
Reference in New Issue
Block a user