Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64e76530d4 | ||
|
|
0b93f9f146 | ||
|
|
4c6fe1cd6c | ||
|
|
83ba48f598 | ||
|
|
62c6de8244 |
@@ -131,7 +131,7 @@ return [
|
|||||||
'PhanReadOnlyPublicProperty',
|
'PhanReadOnlyPublicProperty',
|
||||||
// start ignore annotations
|
// start ignore annotations
|
||||||
'PhanUnextractableAnnotationElementName',
|
'PhanUnextractableAnnotationElementName',
|
||||||
'PhanUnextractableAnnotationSuffix'
|
'PhanUnextractableAnnotationSuffix',
|
||||||
],
|
],
|
||||||
|
|
||||||
// Override to hardcode existence and types of (non-builtin) globals in the global scope.
|
// Override to hardcode existence and types of (non-builtin) globals in the global scope.
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ namespace tests;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use CoreLibs\Logging\Logger\Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for DB\IO + DB\SQL\PgSQL
|
* Test class for DB\IO + DB\SQL\PgSQL
|
||||||
@@ -59,20 +60,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
'db_type' => 'pgsql',
|
'db_type' => 'pgsql',
|
||||||
'db_encoding' => '',
|
'db_encoding' => '',
|
||||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||||
'db_debug' => true,
|
|
||||||
],
|
|
||||||
// same as valid, but db debug is off
|
|
||||||
'valid_debug_false' => [
|
|
||||||
'db_name' => 'corelibs_db_io_test',
|
|
||||||
'db_user' => 'corelibs_db_io_test',
|
|
||||||
'db_pass' => 'corelibs_db_io_test',
|
|
||||||
'db_host' => 'localhost',
|
|
||||||
'db_port' => 5432,
|
|
||||||
'db_schema' => 'public',
|
|
||||||
'db_type' => 'pgsql',
|
|
||||||
'db_encoding' => '',
|
|
||||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
|
||||||
'db_debug' => false,
|
|
||||||
],
|
],
|
||||||
// same as valid, but encoding is set
|
// same as valid, but encoding is set
|
||||||
'valid_with_encoding_utf8' => [
|
'valid_with_encoding_utf8' => [
|
||||||
@@ -85,7 +72,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
'db_type' => 'pgsql',
|
'db_type' => 'pgsql',
|
||||||
'db_encoding' => 'UTF-8',
|
'db_encoding' => 'UTF-8',
|
||||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||||
'db_debug' => true,
|
|
||||||
],
|
],
|
||||||
// valid with no schema set
|
// valid with no schema set
|
||||||
'valid_no_schema' => [
|
'valid_no_schema' => [
|
||||||
@@ -98,7 +84,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
'db_type' => 'pgsql',
|
'db_type' => 'pgsql',
|
||||||
'db_encoding' => '',
|
'db_encoding' => '',
|
||||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||||
'db_debug' => true,
|
|
||||||
],
|
],
|
||||||
// invalid (missing db name)
|
// invalid (missing db name)
|
||||||
'invalid' => [
|
'invalid' => [
|
||||||
@@ -111,7 +96,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
'db_type' => 'pgsql',
|
'db_type' => 'pgsql',
|
||||||
'db_encoding' => '',
|
'db_encoding' => '',
|
||||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||||
'db_debug' => true,
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
private static $log;
|
private static $log;
|
||||||
@@ -137,6 +121,7 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||||
'log_file_id' => 'CoreLibs-DB-IO-Test',
|
'log_file_id' => 'CoreLibs-DB-IO-Test',
|
||||||
]);
|
]);
|
||||||
|
// will be true, default logging is true
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -534,6 +519,9 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function debugSetProvider(): array
|
public function debugSetProvider(): array
|
||||||
{
|
{
|
||||||
|
// 0: db connecdtion
|
||||||
|
// 1: override log flag, null for default
|
||||||
|
// 2: set flag
|
||||||
return [
|
return [
|
||||||
'default debug set' => [
|
'default debug set' => [
|
||||||
// what base connection
|
// what base connection
|
||||||
@@ -541,11 +529,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
// actions (set)
|
// actions (set)
|
||||||
null,
|
null,
|
||||||
// set exepected
|
// set exepected
|
||||||
self::$db_config['valid']['db_debug'],
|
|
||||||
],
|
|
||||||
'set debug to true' => [
|
|
||||||
'valid_debug_false',
|
|
||||||
true,
|
|
||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
'set debug to false' => [
|
'set debug to false' => [
|
||||||
@@ -556,99 +539,46 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* test set for toggleDEbug
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function debugToggleProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'default debug set' => [
|
|
||||||
// what base connection
|
|
||||||
'valid',
|
|
||||||
// actions
|
|
||||||
null,
|
|
||||||
// toggle is inverse
|
|
||||||
self::$db_config['valid']['db_debug'] ? false : true,
|
|
||||||
],
|
|
||||||
'toggle debug to true' => [
|
|
||||||
'valid_debug_false',
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
],
|
|
||||||
'toggle debug to false' => [
|
|
||||||
'valid',
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test dbSetDbug, dbGetDebug
|
* Test dbSetDbug, dbGetDebug
|
||||||
*
|
*
|
||||||
* @covers ::dbGetDbug
|
* @covers ::dbGetDbug
|
||||||
* @covers ::dbSetDebug
|
* @covers ::dbSetDebug
|
||||||
* @dataProvider debugSetProvider
|
* @testdox Set and Get Debug flag
|
||||||
* @testdox Setting debug $set will be $expected [$_dataName]
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDbSetDebug(
|
public function testDbSetDebug(): void
|
||||||
string $connection,
|
{
|
||||||
?bool $set,
|
$connection = 'valid';
|
||||||
bool $expected
|
// default set, expect true
|
||||||
): void {
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config[$connection],
|
self::$db_config[$connection],
|
||||||
self::$log
|
self::$log
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertTrue(
|
||||||
$expected,
|
$db->dbGetDebug()
|
||||||
$set === null ?
|
|
||||||
$db->dbSetDebug() :
|
|
||||||
$db->dbSetDebug($set)
|
|
||||||
);
|
);
|
||||||
// must always match
|
// switch off
|
||||||
$this->assertEquals(
|
$db->dbSetDebug(false);
|
||||||
$expected,
|
$this->assertFalse(
|
||||||
$db->dbGetDebug()
|
$db->dbGetDebug()
|
||||||
);
|
);
|
||||||
$db->dbClose();
|
$db->dbClose();
|
||||||
}
|
// second conenction with log set NOT debug
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
/**
|
// 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
|
||||||
* Test dbToggleDebug, dbGetDebug
|
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||||
*
|
'log_file_id' => 'CoreLibs-DB-IO-Test',
|
||||||
* @covers ::dbGetDbug
|
'log_level' => \CoreLibs\Logging\Logger\Level::Notice,
|
||||||
* @covers ::dbSetDebug
|
]);
|
||||||
* @dataProvider debugToggleProvider
|
|
||||||
* @testdox Toggle debug $toggle will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testDbToggleDebug(
|
|
||||||
string $connection,
|
|
||||||
?bool $toggle,
|
|
||||||
bool $expected
|
|
||||||
): void {
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config[$connection],
|
self::$db_config[$connection],
|
||||||
self::$log
|
$log
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertFalse(
|
||||||
$expected,
|
|
||||||
$toggle === null ?
|
|
||||||
$db->dbToggleDebug() :
|
|
||||||
$db->dbToggleDebug($toggle)
|
|
||||||
);
|
|
||||||
// must always match
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
$db->dbGetDebug()
|
$db->dbGetDebug()
|
||||||
);
|
);
|
||||||
$db->dbClose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - set max query call sets
|
// - set max query call sets
|
||||||
@@ -806,7 +736,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
'host' => 'db_host',
|
'host' => 'db_host',
|
||||||
'port' => 'db_port',
|
'port' => 'db_port',
|
||||||
'ssl' => 'db_ssl',
|
'ssl' => 'db_ssl',
|
||||||
'debug' => 'db_debug',
|
|
||||||
'password' => '***',
|
'password' => '***',
|
||||||
] as $read => $compare
|
] as $read => $compare
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -217,14 +217,14 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
|||||||
|
|
||||||
// setLoggingLevel
|
// setLoggingLevel
|
||||||
// getLoggingLevel
|
// getLoggingLevel
|
||||||
// getJsDebug
|
// loggingLevelIsDebug
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @covers ::setLoggingLevel
|
* @covers ::setLoggingLevel
|
||||||
* @covers ::getLoggingLevel
|
* @covers ::getLoggingLevel
|
||||||
* @covers ::getJsDebug
|
* @covers ::loggingLevelIsDebug
|
||||||
* @testdox setLoggingLevel set/get checks
|
* @testdox setLoggingLevel set/get checks
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
@@ -242,7 +242,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
|||||||
$log->getLoggingLevel()
|
$log->getLoggingLevel()
|
||||||
);
|
);
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$log->getJsDebug()
|
$log->loggingLevelIsDebug()
|
||||||
);
|
);
|
||||||
// not set, should be debug]
|
// not set, should be debug]
|
||||||
$log = new \CoreLibs\Logging\Logging([
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
@@ -254,7 +254,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
|||||||
$log->getLoggingLevel()
|
$log->getLoggingLevel()
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$log->getJsDebug()
|
$log->loggingLevelIsDebug()
|
||||||
);
|
);
|
||||||
// invalid, should be debug, will throw excpetion too
|
// invalid, should be debug, will throw excpetion too
|
||||||
$this->expectException(\InvalidArgumentException::class);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
@@ -269,7 +269,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
|||||||
$log->getLoggingLevel()
|
$log->getLoggingLevel()
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$log->getJsDebug()
|
$log->loggingLevelIsDebug()
|
||||||
);
|
);
|
||||||
// set valid, then change
|
// set valid, then change
|
||||||
$log = new \CoreLibs\Logging\Logging([
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ ob_end_flush();
|
|||||||
$ECHO_ALL = true;
|
$ECHO_ALL = true;
|
||||||
|
|
||||||
// use CoreLibs\Debug\Support;
|
// use CoreLibs\Debug\Support;
|
||||||
|
|
||||||
|
use CoreLibs\Debug\Support;
|
||||||
use CoreLibs\Logging\Logger\Level;
|
use CoreLibs\Logging\Logger\Level;
|
||||||
use CoreLibs\Logging\Logger\Flag;
|
use CoreLibs\Logging\Logger\Flag;
|
||||||
// use CoreLibs\Debug\Support;
|
// use CoreLibs\Debug\Support;
|
||||||
@@ -51,7 +53,18 @@ print "Flag: per_run ->value: " . Flag::per_class->value . "<br>";
|
|||||||
$log->setLogUniqueId();
|
$log->setLogUniqueId();
|
||||||
print "LogUniqId: " . $log->getLogUniqueId() . "<br>";
|
print "LogUniqId: " . $log->getLogUniqueId() . "<br>";
|
||||||
|
|
||||||
print "DUMP: " . $log->dV(['something' => 'error']) . "<br>";
|
print "Is Debug (check): " . Support::printBool($log->getLoggingLevel()->includes(
|
||||||
|
Level::Debug
|
||||||
|
)) . "<br>";
|
||||||
|
print "Is Debug (fk): " . Support::printBool($log->loggingLevelIsDebug()) . "<br>";
|
||||||
|
$log->setLoggingLevel(Level::Notice);
|
||||||
|
print "Is Debug (check): " . Support::printBool($log->getLoggingLevel()->includes(
|
||||||
|
Level::Debug
|
||||||
|
)) . "<br>";
|
||||||
|
print "Is Debug (fk): " . Support::printBool($log->loggingLevelIsDebug()) . "<br>";
|
||||||
|
$log->setLoggingLevel(Level::Debug);
|
||||||
|
|
||||||
|
print "DUMP: <pre>" . $log->dV(['something' => 'error']) . "</pre><br>";
|
||||||
|
|
||||||
$log->debug('LEGACY', 'Some legacy shit here');
|
$log->debug('LEGACY', 'Some legacy shit here');
|
||||||
$log->debug('ARRAY', 'Dump some data: ' . $log->dV(['something' => 'error']));
|
$log->debug('ARRAY', 'Dump some data: ' . $log->dV(['something' => 'error']));
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ print "<body>";
|
|||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||||
|
|
||||||
$smarty->DATA['JS_DEBUG'] = $log->getJsDebug();
|
$smarty->DATA['JS_DEBUG'] = $log->loggingLevelIsDebug();
|
||||||
$smarty->MASTER_TEMPLATE_NAME = 'main_body.tpl';
|
$smarty->MASTER_TEMPLATE_NAME = 'main_body.tpl';
|
||||||
$smarty->TEMPLATE_NAME = 'smarty_test.tpl';
|
$smarty->TEMPLATE_NAME = 'smarty_test.tpl';
|
||||||
$smarty->CSS_SPECIAL_TEMPLATE_NAME = 'smart_test.css';
|
$smarty->CSS_SPECIAL_TEMPLATE_NAME = 'smart_test.css';
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ $DB_CONFIG = [
|
|||||||
'db_type' => 'pgsql',
|
'db_type' => 'pgsql',
|
||||||
'db_encoding' => '',
|
'db_encoding' => '',
|
||||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||||
'db_debug' => true, // turn on logging or not
|
|
||||||
],
|
],
|
||||||
// same as above, but uses pg bouncer
|
// same as above, but uses pg bouncer
|
||||||
'test_pgbouncer' => [
|
'test_pgbouncer' => [
|
||||||
@@ -35,7 +34,6 @@ $DB_CONFIG = [
|
|||||||
'db_type' => 'pgsql',
|
'db_type' => 'pgsql',
|
||||||
'db_encoding' => '',
|
'db_encoding' => '',
|
||||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||||
'db_debug' => true, // turn on logging or not
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,6 @@ if (!$login->loginActionRun()) {
|
|||||||
//------------------------------ logging end
|
//------------------------------ logging end
|
||||||
|
|
||||||
// pass on DEBUG flag to JS via smarty variable
|
// pass on DEBUG flag to JS via smarty variable
|
||||||
$smarty->DATA['JS_DEBUG'] = $log->getJsDebug();
|
$smarty->DATA['JS_DEBUG'] = $log->loggingLevelIsDebug();
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -395,12 +395,10 @@ class IO
|
|||||||
* main DB concstructor with auto connection to DB and failure set on failed connection
|
* main DB concstructor with auto connection to DB and failure set on failed connection
|
||||||
* @param array<mixed> $db_config DB configuration array
|
* @param array<mixed> $db_config DB configuration array
|
||||||
* @param \CoreLibs\Logging\Logging $log Logging class
|
* @param \CoreLibs\Logging\Logging $log Logging class
|
||||||
* @param bool|null $db_debug_override Overrides debug settings in db_config
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
array $db_config,
|
array $db_config,
|
||||||
\CoreLibs\Logging\Logging $log,
|
\CoreLibs\Logging\Logging $log
|
||||||
?bool $db_debug_override = null
|
|
||||||
) {
|
) {
|
||||||
// attach logger
|
// attach logger
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
@@ -417,15 +415,10 @@ class IO
|
|||||||
$this->db_ssl = !empty($db_config['db_ssl']) ? $db_config['db_ssl'] : 'allow';
|
$this->db_ssl = !empty($db_config['db_ssl']) ? $db_config['db_ssl'] : 'allow';
|
||||||
// set debug, either via global var, or from config, else set to false
|
// set debug, either via global var, or from config, else set to false
|
||||||
$this->dbSetDebug(
|
$this->dbSetDebug(
|
||||||
// override
|
// set if logging level is Debug
|
||||||
$db_debug_override ??
|
$this->log->getLoggingLevel()->includes(
|
||||||
// from db config setting
|
\CoreLibs\Logging\Logger\Level::Debug
|
||||||
$db_config['db_debug'] ??
|
)
|
||||||
// [DEPRECATED] should be handled from outside
|
|
||||||
$_SESSION['DB_DEBUG'] ??
|
|
||||||
// [DEPRECATED] globals should be deprecated
|
|
||||||
$GLOBALS['DB_DEBUG'] ??
|
|
||||||
false
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// set loop protection max count
|
// set loop protection max count
|
||||||
@@ -664,6 +657,8 @@ class IO
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* calls the basic class debug with strip command
|
* calls the basic class debug with strip command
|
||||||
|
* for internal calls, will always create a message
|
||||||
|
*
|
||||||
* @param string $debug_id group id for debug
|
* @param string $debug_id group id for debug
|
||||||
* @param string $error_string error message or debug data
|
* @param string $error_string error message or debug data
|
||||||
* @param string $id db debug group
|
* @param string $id db debug group
|
||||||
@@ -672,7 +667,7 @@ class IO
|
|||||||
* Will be printed after main error string
|
* Will be printed after main error string
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function __dbDebug(
|
private function __dbDebugMessage(
|
||||||
string $debug_id,
|
string $debug_id,
|
||||||
string $error_string,
|
string $error_string,
|
||||||
string $id = '',
|
string $id = '',
|
||||||
@@ -682,24 +677,24 @@ class IO
|
|||||||
// NOTE prefix allows html for echo output, will be stripped on file print
|
// NOTE prefix allows html for echo output, will be stripped on file print
|
||||||
$prefix = '';
|
$prefix = '';
|
||||||
if ($id) {
|
if ($id) {
|
||||||
$prefix .= '[<span style="color: #920069;">' . $id . '</span>] ';
|
$prefix .= '[' . $id . '] ';
|
||||||
}
|
}
|
||||||
if ($type) {
|
if ($type) {
|
||||||
$prefix .= '{<span style="font-style: italic; color: #3f0092;">' . $type . '</span>} ';
|
$prefix .= '{' . $type . '} ';
|
||||||
}
|
}
|
||||||
switch ($id) {
|
switch ($id) {
|
||||||
case 'DB_ERROR':
|
case 'DB_ERROR':
|
||||||
$prefix .= '<span style="color: red;"><b>DB-Error</b>:</span>';
|
$prefix .= 'DB-Error:';
|
||||||
break;
|
break;
|
||||||
case 'DB_WARNING':
|
case 'DB_WARNING':
|
||||||
$prefix .= '<span style="color: orange;"><b>DB-Warning</b>:</span>';
|
$prefix .= 'DB-Warning:';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ($prefix) {
|
if ($prefix) {
|
||||||
$prefix .= '- ';
|
$prefix .= '- ';
|
||||||
}
|
}
|
||||||
if ($error_data !== []) {
|
if ($error_data !== []) {
|
||||||
$error_string .= '<br>['
|
$error_string .= "\n" . '['
|
||||||
. \CoreLibs\Debug\Support::prAr($error_data)
|
. \CoreLibs\Debug\Support::prAr($error_data)
|
||||||
. ']';
|
. ']';
|
||||||
}
|
}
|
||||||
@@ -716,6 +711,30 @@ class IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main call from anywhere in all classes for launching debug messages
|
||||||
|
* will abort if dbDebug not set
|
||||||
|
*
|
||||||
|
* @param string $debug_id group id for debug
|
||||||
|
* @param string $error_string error message or debug data
|
||||||
|
* @param string $id db debug group
|
||||||
|
* @param string $type query identifier (Q, I, etc)
|
||||||
|
* @param array<mixed> $error_data Optional error data as array
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function __dbDebug(
|
||||||
|
string $debug_id,
|
||||||
|
string $error_string,
|
||||||
|
string $id = '',
|
||||||
|
string $type = '',
|
||||||
|
array $error_data = []
|
||||||
|
): void {
|
||||||
|
if (!$this->dbGetDebug()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->__dbDebugMessage($debug_id, $error_string, $id, $type, $error_data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset warnings and errors before run
|
* Reset warnings and errors before run
|
||||||
* Is called on base queries to reset error before each run
|
* Is called on base queries to reset error before each run
|
||||||
@@ -778,7 +797,7 @@ class IO
|
|||||||
$db_error_string = $db_prefix . ' ' . $db_error_string;
|
$db_error_string = $db_prefix . ' ' . $db_error_string;
|
||||||
}
|
}
|
||||||
if ($db_error_string) {
|
if ($db_error_string) {
|
||||||
$this->__dbDebug('db', $db_error_string, 'DB_ERROR', $where_called);
|
$this->__dbDebugMessage('db', $db_error_string, 'DB_ERROR', $where_called);
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
$where_called,
|
$where_called,
|
||||||
@@ -835,7 +854,7 @@ class IO
|
|||||||
$error_id = (string)$error_id;
|
$error_id = (string)$error_id;
|
||||||
[$where_called, $pg_error_string] = $this->__dbErrorPreprocessor($cursor);
|
[$where_called, $pg_error_string] = $this->__dbErrorPreprocessor($cursor);
|
||||||
// write error msg ...
|
// write error msg ...
|
||||||
$this->__dbDebug(
|
$this->__dbDebugMessage(
|
||||||
'db',
|
'db',
|
||||||
$error_id . ': ' . ($this->error_string[$error_id] ?? '[UNKNOWN ERROR]')
|
$error_id . ': ' . ($this->error_string[$error_id] ?? '[UNKNOWN ERROR]')
|
||||||
. ($msg ? ', ' . $msg : ''),
|
. ($msg ? ', ' . $msg : ''),
|
||||||
@@ -861,7 +880,7 @@ class IO
|
|||||||
): void {
|
): void {
|
||||||
$warning_id = (string)$warning_id;
|
$warning_id = (string)$warning_id;
|
||||||
[$where_called, $pg_error_string] = $this->__dbErrorPreprocessor($cursor);
|
[$where_called, $pg_error_string] = $this->__dbErrorPreprocessor($cursor);
|
||||||
$this->__dbDebug(
|
$this->__dbDebugMessage(
|
||||||
'db',
|
'db',
|
||||||
$warning_id . ': ' . ($this->error_string[$warning_id] ?? '[UNKNOWN WARNING')
|
$warning_id . ': ' . ($this->error_string[$warning_id] ?? '[UNKNOWN WARNING')
|
||||||
. ($msg ? ', ' . $msg : ''),
|
. ($msg ? ', ' . $msg : ''),
|
||||||
@@ -1166,17 +1185,15 @@ class IO
|
|||||||
}
|
}
|
||||||
// $this->debug('DB IO', 'Q: '.$this->query.', RETURN: '.$this->returning_id);
|
// $this->debug('DB IO', 'Q: '.$this->query.', RETURN: '.$this->returning_id);
|
||||||
// for DEBUG, only on first time ;)
|
// for DEBUG, only on first time ;)
|
||||||
if ($this->db_debug) {
|
$this->__dbDebug(
|
||||||
$this->__dbDebug(
|
'db',
|
||||||
'db',
|
$this->__dbDebugPrepare(
|
||||||
$this->__dbDebugPrepare(
|
$this->query,
|
||||||
$this->query,
|
$this->params
|
||||||
$this->params
|
),
|
||||||
),
|
'__dbPrepareExec',
|
||||||
'__dbPrepareExec',
|
($this->params === [] ? 'Q' : 'Qp')
|
||||||
($this->params === [] ? 'Q' : 'Qp')
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
// import protection, hash needed
|
// import protection, hash needed
|
||||||
$query_hash = $this->dbGetQueryHash($this->query, $this->params);
|
$query_hash = $this->dbGetQueryHash($this->query, $this->params);
|
||||||
// if the array index does not exists set it 0
|
// if the array index does not exists set it 0
|
||||||
@@ -1194,7 +1211,7 @@ class IO
|
|||||||
$this->query_called[$query_hash] > $this->MAX_QUERY_CALL
|
$this->query_called[$query_hash] > $this->MAX_QUERY_CALL
|
||||||
) {
|
) {
|
||||||
$this->__dbError(30, false, $this->query);
|
$this->__dbError(30, false, $this->query);
|
||||||
$this->__dbDebug(
|
$this->__dbDebugMessage(
|
||||||
'db',
|
'db',
|
||||||
$this->__dbDebugPrepare(
|
$this->__dbDebugPrepare(
|
||||||
$this->query,
|
$this->query,
|
||||||
@@ -1222,9 +1239,7 @@ class IO
|
|||||||
// if either the cursor is false
|
// if either the cursor is false
|
||||||
if ($this->cursor === false || $this->db_functions->__dbLastErrorQuery()) {
|
if ($this->cursor === false || $this->db_functions->__dbLastErrorQuery()) {
|
||||||
// printout Query if debug is turned on
|
// printout Query if debug is turned on
|
||||||
if ($this->db_debug) {
|
$this->__dbDebug('db', $this->query, 'dbExec', 'Q[nc]');
|
||||||
$this->__dbDebug('db', $this->query, 'dbExec', 'Q[nc]');
|
|
||||||
}
|
|
||||||
// internal error handling
|
// internal error handling
|
||||||
$this->__dbError(13, $this->cursor);
|
$this->__dbError(13, $this->cursor);
|
||||||
return false;
|
return false;
|
||||||
@@ -1460,10 +1475,11 @@ class IO
|
|||||||
$string .= 'at host {b}\'' . $this->db_host . '\'{/b} ';
|
$string .= 'at host {b}\'' . $this->db_host . '\'{/b} ';
|
||||||
$string .= 'on port {b}\'' . $this->db_port . '\'{/b} ';
|
$string .= 'on port {b}\'' . $this->db_port . '\'{/b} ';
|
||||||
$string .= 'with ssl mode {b}\'' . $this->db_ssl . '\'{/b}{br}';
|
$string .= 'with ssl mode {b}\'' . $this->db_ssl . '\'{/b}{br}';
|
||||||
$string .= '{b}-DB-info->{/b} DB IO Class debug output: {b}' . ($this->db_debug ? 'Yes' : 'No') . '{/b}';
|
$string .= '{b}-DB-info->{/b} DB IO Class debug output: {b}'
|
||||||
|
. ($this->dbGetDebug() ? 'Yes' : 'No') . '{/b}';
|
||||||
if ($log === true) {
|
if ($log === true) {
|
||||||
// if debug, remove / change b
|
// if debug, remove / change b
|
||||||
$this->__dbDebug('db', str_replace(
|
$this->__dbDebugMessage('db', str_replace(
|
||||||
$html_tags,
|
$html_tags,
|
||||||
$replace_text,
|
$replace_text,
|
||||||
$string
|
$string
|
||||||
@@ -1605,7 +1621,7 @@ class IO
|
|||||||
if (is_array($array)) {
|
if (is_array($array)) {
|
||||||
$this->nbsp = '';
|
$this->nbsp = '';
|
||||||
$string .= $this->__printArray($array);
|
$string .= $this->__printArray($array);
|
||||||
$this->__dbDebug('db', $string, 'dbDumpData');
|
$this->__dbDebugMessage('db', $string, 'dbDumpData');
|
||||||
}
|
}
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
@@ -1985,17 +2001,15 @@ class IO
|
|||||||
// checks if the params count given matches the expected count
|
// checks if the params count given matches the expected count
|
||||||
if ($this->__dbCheckQueryParams($query, count($params)) === false) {
|
if ($this->__dbCheckQueryParams($query, count($params)) === false) {
|
||||||
// in case we got an error print out query
|
// in case we got an error print out query
|
||||||
if ($this->db_debug) {
|
$this->__dbDebug(
|
||||||
$this->__dbDebug(
|
'db',
|
||||||
'db',
|
$this->__dbDebugPrepare(
|
||||||
$this->__dbDebugPrepare(
|
$this->query,
|
||||||
$this->query,
|
$this->params
|
||||||
$this->params
|
),
|
||||||
),
|
'dbReturn',
|
||||||
'dbReturn',
|
($this->params === [] ? 'Q[e]' : 'Qp[e]')
|
||||||
($this->params === [] ? 'Q[e]' : 'Qp[e]')
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// set first call to false
|
// set first call to false
|
||||||
@@ -2018,17 +2032,15 @@ class IO
|
|||||||
if (!$this->cursor_ext[$query_hash]['cursor']) {
|
if (!$this->cursor_ext[$query_hash]['cursor']) {
|
||||||
$this->cursor_ext[$query_hash]['log'][] = 'No cursor';
|
$this->cursor_ext[$query_hash]['log'][] = 'No cursor';
|
||||||
// for DEBUG, print out each query executed
|
// for DEBUG, print out each query executed
|
||||||
if ($this->db_debug) {
|
$this->__dbDebug(
|
||||||
$this->__dbDebug(
|
'db',
|
||||||
'db',
|
$this->__dbDebugPrepare(
|
||||||
$this->__dbDebugPrepare(
|
$this->cursor_ext[$query_hash]['query'],
|
||||||
$this->cursor_ext[$query_hash]['query'],
|
$this->cursor_ext[$query_hash]['params']
|
||||||
$this->cursor_ext[$query_hash]['params']
|
),
|
||||||
),
|
'dbReturn',
|
||||||
'dbReturn',
|
($this->cursor_ext[$query_hash]['params'] === [] ? 'Q' : 'Qp'),
|
||||||
($this->cursor_ext[$query_hash]['params'] === [] ? 'Q' : 'Qp'),
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
// if no DB Handler try to reconnect
|
// if no DB Handler try to reconnect
|
||||||
if (!$this->dbh) {
|
if (!$this->dbh) {
|
||||||
// if reconnect fails drop out
|
// if reconnect fails drop out
|
||||||
@@ -2055,17 +2067,15 @@ class IO
|
|||||||
}
|
}
|
||||||
// if still no cursor ...
|
// if still no cursor ...
|
||||||
if (!$this->cursor_ext[$query_hash]['cursor']) {
|
if (!$this->cursor_ext[$query_hash]['cursor']) {
|
||||||
if ($this->db_debug) {
|
$this->__dbDebug(
|
||||||
$this->__dbDebug(
|
'db',
|
||||||
'db',
|
$this->__dbDebugPrepare(
|
||||||
$this->__dbDebugPrepare(
|
$this->cursor_ext[$query_hash]['query'],
|
||||||
$this->cursor_ext[$query_hash]['query'],
|
$this->cursor_ext[$query_hash]['params']
|
||||||
$this->cursor_ext[$query_hash]['params']
|
),
|
||||||
),
|
'dbReturn',
|
||||||
'dbReturn',
|
($this->cursor_ext[$query_hash]['params'] === [] ? 'Q[e]' : 'Qp[e]'),
|
||||||
($this->cursor_ext[$query_hash]['params'] === [] ? 'Q[e]' : 'Qp[e]'),
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
// internal error handling
|
// internal error handling
|
||||||
$this->__dbError(13, $this->cursor_ext[$query_hash]['cursor']);
|
$this->__dbError(13, $this->cursor_ext[$query_hash]['cursor']);
|
||||||
return false;
|
return false;
|
||||||
@@ -2720,17 +2730,15 @@ class IO
|
|||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->db_debug) {
|
$this->__dbDebug(
|
||||||
$this->__dbDebug(
|
'db',
|
||||||
'db',
|
$this->__dbDebugPrepare(
|
||||||
$this->__dbDebugPrepare(
|
$this->prepare_cursor[$stm_name]['query'],
|
||||||
$this->prepare_cursor[$stm_name]['query'],
|
$data
|
||||||
$data
|
),
|
||||||
),
|
'dbExecPrep',
|
||||||
'dbExecPrep',
|
'Qpe'
|
||||||
'Qpe'
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
// if the count does not match
|
// if the count does not match
|
||||||
if ($this->prepare_cursor[$stm_name]['count'] != count($data)) {
|
if ($this->prepare_cursor[$stm_name]['count'] != count($data)) {
|
||||||
$this->__dbError(
|
$this->__dbError(
|
||||||
@@ -3115,16 +3123,13 @@ class IO
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* switches the debug flag on or off
|
* switches the debug flag on or off
|
||||||
* if none given, then return current set only
|
*
|
||||||
* @param bool|null $debug true/false or null for just getting current set
|
* @param bool $debug True/False to turn debugging in this calss on or off
|
||||||
* @return bool Current debug flag as set
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function dbSetDebug(?bool $debug = null): bool
|
public function dbSetDebug(bool $debug): void
|
||||||
{
|
{
|
||||||
if ($debug !== null) {
|
$this->db_debug = $debug;
|
||||||
$this->db_debug = $debug;
|
|
||||||
}
|
|
||||||
return $this->db_debug;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3132,9 +3137,11 @@ class IO
|
|||||||
* OR
|
* OR
|
||||||
* with the optional parameter fix sets debug
|
* with the optional parameter fix sets debug
|
||||||
* returns current set stats
|
* returns current set stats
|
||||||
|
*
|
||||||
* @param bool|null $debug Flag to turn debug on off or null for toggle
|
* @param bool|null $debug Flag to turn debug on off or null for toggle
|
||||||
* @return bool Current debug status
|
* @return bool Current debug status
|
||||||
* True for debug is on, False for off
|
* True for debug is on, False for off
|
||||||
|
* @deprecated Use dbSetDebug and dbGetDebug
|
||||||
*/
|
*/
|
||||||
public function dbToggleDebug(?bool $debug = null): bool
|
public function dbToggleDebug(?bool $debug = null): bool
|
||||||
{
|
{
|
||||||
@@ -3148,6 +3155,7 @@ class IO
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return current set db debug flag status
|
* Return current set db debug flag status
|
||||||
|
*
|
||||||
* @return bool Current debug status
|
* @return bool Current debug status
|
||||||
*/
|
*/
|
||||||
public function dbGetDebug(): bool
|
public function dbGetDebug(): bool
|
||||||
|
|||||||
@@ -177,7 +177,6 @@ class Support
|
|||||||
$caller_level = 1;
|
$caller_level = 1;
|
||||||
$caller_list = self::getCallerMethodList();
|
$caller_list = self::getCallerMethodList();
|
||||||
if ($caller_list[0] == 'dV') {
|
if ($caller_list[0] == 'dV') {
|
||||||
echo "Raise caller level<br>: " . $caller_list[0] . "<br>";
|
|
||||||
$caller_level = 2;
|
$caller_level = 2;
|
||||||
}
|
}
|
||||||
// we need to strip the string in <small></small that is
|
// we need to strip the string in <small></small that is
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ class Logging
|
|||||||
$settings['mandatory'] && !isset($options[$name]) &&
|
$settings['mandatory'] && !isset($options[$name]) &&
|
||||||
empty($settings['alias'])
|
empty($settings['alias'])
|
||||||
) {
|
) {
|
||||||
throw new \InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'Missing mandatory option: "' . $name . '"',
|
'Missing mandatory option: "' . $name . '"',
|
||||||
E_USER_WARNING
|
E_USER_WARNING
|
||||||
);
|
);
|
||||||
@@ -230,7 +230,7 @@ class Logging
|
|||||||
switch ($settings['type']) {
|
switch ($settings['type']) {
|
||||||
case 'bool':
|
case 'bool':
|
||||||
if (!is_bool($this->options[$name])) {
|
if (!is_bool($this->options[$name])) {
|
||||||
throw new \InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'Option: "' . $name . '" is not of type bool',
|
'Option: "' . $name . '" is not of type bool',
|
||||||
E_USER_ERROR
|
E_USER_ERROR
|
||||||
);
|
);
|
||||||
@@ -238,7 +238,7 @@ class Logging
|
|||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
if (!is_string($this->options[$name])) {
|
if (!is_string($this->options[$name])) {
|
||||||
throw new \InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'Option: "' . $name . '" is not of type string',
|
'Option: "' . $name . '" is not of type string',
|
||||||
E_USER_ERROR
|
E_USER_ERROR
|
||||||
);
|
);
|
||||||
@@ -249,7 +249,7 @@ class Logging
|
|||||||
empty($settings['type_info']) ||
|
empty($settings['type_info']) ||
|
||||||
!$this->options[$name] instanceof $settings['type_info']
|
!$this->options[$name] instanceof $settings['type_info']
|
||||||
) {
|
) {
|
||||||
throw new \InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'Option: "' . $name . '" is not of instance '
|
'Option: "' . $name . '" is not of instance '
|
||||||
. ($settings['type_info'] ?? 'NO INSTANCE DEFINED'),
|
. ($settings['type_info'] ?? 'NO INSTANCE DEFINED'),
|
||||||
E_USER_ERROR
|
E_USER_ERROR
|
||||||
@@ -675,9 +675,11 @@ class Logging
|
|||||||
*
|
*
|
||||||
* @return bool True, we are at debug level
|
* @return bool True, we are at debug level
|
||||||
*/
|
*/
|
||||||
public function getJsDebug(): bool
|
public function loggingLevelIsDebug(): bool
|
||||||
{
|
{
|
||||||
return $this->log_level === Level::Debug ? true : false;
|
return $this->getLoggingLevel()->includes(
|
||||||
|
Level::Debug
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// log file id set (file name prefix)
|
// log file id set (file name prefix)
|
||||||
|
|||||||
Reference in New Issue
Block a user