From e0f20f9209644e666a0e40176c42b0e18dbb01f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 19 Feb 2023 08:02:18 +0100 Subject: [PATCH] Continued: - more debug logging added - rewrote old $this->outputLine() "logging" to logger middleware - added more checks on parameter --- .../classes/class_BaseFrameworkSystem.php | 187 ++++++++++++++---- 1 file changed, 152 insertions(+), 35 deletions(-) diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index dc2410c3..0e9a1b44 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -485,14 +485,23 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac * * @param $str A string (maybe) without trailing slash * @return $str A string with an auto-appended trailing slash + * @throws InvalidArgumentException If a paramter has an invalid value */ public final function addMissingTrailingSlash (string $str) { + // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: str=%s - CALLED!', $str)); + if (empty($str)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "str" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Is there a trailing slash? if (substr($str, -1, 1) != '/') { $str .= '/'; } // Return string with trailing slash + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: str=%s - EXIT!', $str)); return $str; } @@ -501,8 +510,16 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac * * @param $message Optional message to show in debug output * @return void + * @throws InvalidArgumentException If a paramter has an invalid value */ public final function debugInstance (string $message = '') { + // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: message=%s - CALLED!', $message)); + if (empty($message)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Restore the error handler to avoid trouble with missing array elements or undeclared variables restore_error_handler(); @@ -549,8 +566,16 @@ Loaded includes: * @param $message An optional message to output * @param $doExit Whether exit the program (true is default) * @return void + * @throws InvalidArgumentException If a paramter has an invalid value */ public function debugBackTrace (string $message = '', bool $doExit = true) { + // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: message=%s,doExit=%d - CALLED!', $message, intval($doExit))); + if (empty($message)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Sorry, there is no other way getting this nice backtrace if (!empty($message)) { // Output message @@ -563,7 +588,8 @@ Loaded includes: // Exit program? if ($doExit === true) { - exit(); + // Yes, with error code + exit(255); } } @@ -611,8 +637,16 @@ Loaded includes: * * @param $message Message to output * @return void + * @throws InvalidArgumentException If a paramter has an invalid value */ public function outputLine (string $message) { + // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: message=%s - CALLED!', $message)); + if (empty($message)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Simply output it print($message . PHP_EOL); } @@ -622,8 +656,16 @@ Loaded includes: * * @param $phpCode Unmarked PHP code * @return $markedCode Marked PHP code + * @throws InvalidArgumentException If a paramter has an invalid value */ public function markupCode (string $phpCode) { + // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: phpCode=%s - CALLED!', $phpCode)); + if (empty($phpCode)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "phpCode" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Init marked code $markedCode = ''; @@ -802,9 +844,17 @@ Loaded includes: * * @param $message The message we shall output to the developer * @return void + * @throws InvalidArgumentException If a paramter has an invalid value * @todo Write a logging mechanism for productive mode */ public function deprecationWarning (string $message) { + // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: message=%s - CALLED!', $message)); + if (empty($message)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Is developer mode active? if (FrameworkBootstrap::getConfigurationInstance()->isEnabled('developer_mode')) { // Debug instance is there? @@ -820,6 +870,9 @@ Loaded includes: // @TODO Finish this part! DebugMiddleware::getSelfInstance()->partialStub('Developer mode inactive. Message:' . $message); } + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -831,6 +884,7 @@ Loaded includes: */ public final function isPhpExtensionLoaded (string $phpExtension) { // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: phpExtension=%s - CALLED!', $phpExtension)); if (empty($phpExtension)) { // Throw IAE throw new InvalidArgumentException('Parameter "phpExtension" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -840,6 +894,7 @@ Loaded includes: $isLoaded = in_array($phpExtension, get_loaded_extensions()); // Return result + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isLoaded=%d - EXIT!', intval($isLoaded))); return $isLoaded; } @@ -851,9 +906,11 @@ Loaded includes: */ public function getMilliTime () { // Get the time of day as float + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: CALLED!'); $milliTime = gettimeofday(true); // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: milliTime=%s - EXIT!', $milliTime)); return $milliTime; } @@ -865,6 +922,7 @@ Loaded includes: */ public function idle (int $milliSeconds) { // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: milliSeconds=%s - CALLED!', $milliSeconds)); if ($milliSeconds < 1) { // Throw IAE throw new InvalidArgumentException(sprintf('milliSeconds=%d are not a reasonable value to idle', $milliSeconds)); @@ -889,6 +947,7 @@ Loaded includes: } // Return result + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: hasSlept=%d - EXIT!', intval($hasSlept))); return $hasSlept; } @@ -901,6 +960,7 @@ Loaded includes: */ protected function isBase64Encoded (string $encodedData) { // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: encodedData=%s - CALLED!', $encodedData)); if (empty($encodedData)) { // Throw IAE throw new InvalidArgumentException('Parameter "encodedData" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -910,6 +970,7 @@ Loaded includes: $isBase64 = (@base64_decode($encodedData, true) !== false); // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isBase64=%d - EXIT!', intval($isBase64))); return $isBase64; } @@ -947,6 +1008,7 @@ Loaded includes: */ protected final function isGenericArrayElementSet (string $keyGroup, string $subGroup, string $key, string $element) { // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,element=%s - CALLED!', $keyGroup, $subGroup, $key, $element)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -962,10 +1024,10 @@ Loaded includes: } // Is it there? - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element); $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]); // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isset=%d - EXIT!', intval($isset))); return $isset; } /** @@ -979,6 +1041,7 @@ Loaded includes: */ protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, string $key) { // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s - CALLED!', $keyGroup, $subGroup, $key)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -991,10 +1054,10 @@ Loaded includes: } // Is it there? - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key); $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]); // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isset=%d - EXIT!', intval($isset))); return $isset; } @@ -1008,7 +1071,7 @@ Loaded includes: */ protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s - CALLED!', $keyGroup, $subGroup)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1021,6 +1084,7 @@ Loaded includes: $isset = isset($this->genericArray[$keyGroup][$subGroup]); // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isset=%d - EXIT!', intval($isset))); return $isset; } @@ -1035,7 +1099,7 @@ Loaded includes: */ protected final function getGenericSubArray (string $keyGroup, string $subGroup) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s - CALLED!', $keyGroup, $subGroup)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1048,6 +1112,7 @@ Loaded includes: } // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->genericArray[%s][%s][]=%s - EXIT!', $keyGroup, $subGroup, gettype($this->genericArray[$keyGroup][$subGroup]))); return $this->genericArray[$keyGroup][$subGroup]; } @@ -1062,7 +1127,7 @@ Loaded includes: */ protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, string $key) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s - CALLED!', $keyGroup, $subGroup, $key)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1076,6 +1141,9 @@ Loaded includes: // Remove it unset($this->genericArray[$keyGroup][$subGroup][$key]); + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -1090,7 +1158,7 @@ Loaded includes: */ protected final function unsetGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,element=%s - CALLED!', $keyGroup, $subGroup, $key, $element)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1107,6 +1175,9 @@ Loaded includes: // Remove it unset($this->genericArray[$keyGroup][$subGroup][$key][$element]); + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -1119,9 +1190,9 @@ Loaded includes: * @return void * @throws InvalidArgumentException If a parameter is not valid */ - protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, $key, string $value, string $appendGlue = '') { + protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, string $key, string $value, string $appendGlue = '') { // Check parameter - //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true) . ',appendGlue=' . $appendGlue); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,value=%s,appendGlue=%s - CALLED!', $keyGroup, $subGroup, $key, $value, $appendGlue)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1141,6 +1212,9 @@ Loaded includes: // Add it $this->genericArray[$keyGroup][$subGroup][$key] = $value; } + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -1156,7 +1230,7 @@ Loaded includes: */ protected final function appendStringToGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, string $value, string $appendGlue = '') { // Check parameter - //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true) . ',appendGlue=' . $appendGlue); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,element=%s,value=%s,appendGlue=%s - CALLED!', $keyGroup, $subGroup, $key, $element, $value, $appendGlue)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1179,6 +1253,9 @@ Loaded includes: // Add it $this->setGenericArrayElement($keyGroup, $subGroup, $key, $element, $value); } + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -1194,7 +1271,7 @@ Loaded includes: */ protected final function initGenericArrayGroup (string $keyGroup, string $subGroup, bool $forceInit = false) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,forceInit=%d - CALLED!', $keyGroup, $subGroup, intval($forceInit))); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1208,6 +1285,9 @@ Loaded includes: // Initialize it $this->genericArray[$keyGroup][$subGroup] = []; + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -1221,9 +1301,9 @@ Loaded includes: * @throws InvalidArgumentException If a parameter is not valid * @throws BadMethodCallException If key/sub group has already been initialized */ - protected final function initGenericArrayKey (string $keyGroup, string $subGroup, $key, bool $forceInit = false) { + protected final function initGenericArrayKey (string $keyGroup, string $subGroup, string $key, bool $forceInit = false) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,forceInit=%d - CALLED!', $keyGroup, $subGroup, $key, intval($forceInit))); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1240,6 +1320,9 @@ Loaded includes: // Initialize it $this->genericArray[$keyGroup][$subGroup][$key] = []; + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -1256,7 +1339,7 @@ Loaded includes: */ protected final function initGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, bool $forceInit = false) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,element=%s,forceInit=%d - CALLED!', $keyGroup, $subGroup, $key, $element, intval($forceInit))); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1276,6 +1359,9 @@ Loaded includes: // Initialize it $this->genericArray[$keyGroup][$subGroup][$key][$element] = []; + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -1290,7 +1376,7 @@ Loaded includes: */ protected final function pushValueToGenericArrayKey (string $keyGroup, string $subGroup, string $key, $value) { // Check parameter - //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,value[]=%s - CALLED!', $keyGroup, $subGroup, $key, gettype($value))); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1310,7 +1396,7 @@ Loaded includes: // Return count //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true)); - //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: count=%d - EXIT!', $count)); return $count; } @@ -1327,7 +1413,7 @@ Loaded includes: */ protected final function pushValueToGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, $value) { // Check parameter - //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,element=%s,value[]=%s - CALLED!', $keyGroup, $subGroup, $key, $element, gettype($value))); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1342,6 +1428,7 @@ Loaded includes: throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) { // Initialize array + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: Invoking this->initGenericArrayElement(%s,%s,%s,%s) ...', $keyGroup, $subGroup, $key, $element)); $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element); } @@ -1350,7 +1437,7 @@ Loaded includes: // Return count //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true)); - //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: count=%d - EXIT!', $count)); return $count; } @@ -1366,7 +1453,7 @@ Loaded includes: */ protected final function popGenericArrayElement (string $keyGroup, string $subGroup, string $key) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s - CALLED!', $keyGroup, $subGroup, $key)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1386,7 +1473,7 @@ Loaded includes: // Return value //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true)); - //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: value[]=%s - EXIT!', gettype($value))); return $value; } @@ -1402,7 +1489,7 @@ Loaded includes: */ protected final function shiftGenericArrayElement (string $keyGroup, string $subGroup, string $key) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s - CALLED!', $keyGroup, $subGroup, $key)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1422,7 +1509,7 @@ Loaded includes: // Return value //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true)); - //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: value[]=%s - EXIT!', gettype($value))); return $value; } @@ -1436,7 +1523,7 @@ Loaded includes: */ protected final function countGenericArray (string $keyGroup) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s - CALLED!', $keyGroup)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1449,7 +1536,7 @@ Loaded includes: $count = count($this->genericArray[$keyGroup]); // Return it - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: count=%d - EXIT!', $count)); return $count; } @@ -1464,7 +1551,7 @@ Loaded includes: */ protected final function countGenericArrayGroup (string $keyGroup, string $subGroup) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s - CALLED!', $keyGroup, $subGroup)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1480,7 +1567,7 @@ Loaded includes: $count = count($this->genericArray[$keyGroup][$subGroup]); // Return it - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: count=%d - EXIT!', $count)); return $count; } @@ -1496,7 +1583,7 @@ Loaded includes: */ protected final function countGenericArrayElements (string $keyGroup, string $subGroup, string $key) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s - CALLED!', $keyGroup, $subGroup, $key)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1518,7 +1605,7 @@ Loaded includes: $count = count($this->genericArray[$keyGroup][$subGroup][$key]); // Return it - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: count=%d - EXIT!', $count)); return $count; } @@ -1532,7 +1619,7 @@ Loaded includes: */ protected final function getGenericArray (string $keyGroup) { // Check parameters - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s - CALLED!', $keyGroup)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1542,6 +1629,7 @@ Loaded includes: } // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->genericArray[%s][]=%s - EXIT!', $keyGroup, gettype($this->genericArray[$keyGroup]))); return $this->genericArray[$keyGroup]; } @@ -1558,7 +1646,7 @@ Loaded includes: */ protected final function setGenericArrayKey (string $keyGroup, string $subGroup, string $key, $value) { // Check parameters - //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,value[]=%s - CALLED!', $keyGroup, $subGroup, $key, gettype($value))); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1575,6 +1663,9 @@ Loaded includes: // Set value here $this->genericArray[$keyGroup][$subGroup][$key] = $value; + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -1589,7 +1680,7 @@ Loaded includes: */ protected final function getGenericArrayKey (string $keyGroup, string $subGroup, string $key) { // Check parameters - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s - CALLED!', $keyGroup, $subGroup, $key)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1605,6 +1696,7 @@ Loaded includes: } // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->genericArray[%s][%s][%s][]=%s - EXIT!', $keyGroup, $subGroup, $key, gettype($this->genericArray[$keyGroup][$subGroup][$key]))); return $this->genericArray[$keyGroup][$subGroup][$key]; } @@ -1621,7 +1713,7 @@ Loaded includes: */ protected final function setGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, $value) { // Check parameter - //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,element=%s,value[]=%s - CALLED!', $keyGroup, $subGroup, $key, $element, gettype($value))); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1641,6 +1733,9 @@ Loaded includes: // Then set it $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value; + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -1656,7 +1751,7 @@ Loaded includes: */ protected final function getGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s,element=%s - CALLED!', $keyGroup, $subGroup, $key, $element)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1675,6 +1770,7 @@ Loaded includes: } // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->genericArray[%s][%s][%s][%s][]=%s - EXIT!', $keyGroup, $subGroup, $key, gettype($this->genericArray[$keyGroup][$subGroup][$key][$element]))); return $this->genericArray[$keyGroup][$subGroup][$key][$element]; } @@ -1688,7 +1784,7 @@ Loaded includes: */ protected final function isValidGenericArrayGroup (string $keyGroup, string $subGroup) { // Check parameter - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s - CALLED!', $keyGroup, $subGroup)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1701,6 +1797,7 @@ Loaded includes: $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup)))); // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isValid=%d - EXIT!', intval($isValid))); return $isValid; } @@ -1714,7 +1811,7 @@ Loaded includes: */ protected final function isValidGenericArrayKey (string $keyGroup, string $subGroup, string $key) { // Check parameters - //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: keyGroup=%s,subGroup=%s,key=%s - CALLED!', $keyGroup, $subGroup, $key)); if (empty($keyGroup)) { // Throw IAE throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -1730,6 +1827,7 @@ Loaded includes: $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key)))); // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isValid=%d - EXIT!', intval($isValid))); return $isValid; } @@ -1740,10 +1838,14 @@ Loaded includes: */ protected function initWebOutputInstance () { // Init web output instance + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: CALLED!'); $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class'); // Set it locally $this->setWebOutputInstance($outputInstance); + + // Trace mesage + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: EXIT!'); } /** @@ -1754,9 +1856,11 @@ Loaded includes: */ public static final function translateBooleanToYesNo (bool $boolean) { // "Translate" it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: boolean=%d - CALLED!', intval($boolean))); $translated = ($boolean === true) ? 'Y' : 'N'; // ... and return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: translated=%s - EXIT!', $translated)); return $translated; } @@ -1771,9 +1875,11 @@ Loaded includes: */ protected static function createTempPathForFile (SplFileInfo $infoInstance) { // Get config entry + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: infoInstance=%s - CALLED!', $infoInstance->__toString())); $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path'); // Is the path writeable? + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: basePath=%s', $basePath)); if (!is_writable($basePath)) { // Path is write-protected throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN); @@ -1789,6 +1895,7 @@ Loaded includes: } // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: tempInstance=%s - EXIT!', $tempInstance->__toString())); return $tempInstance; } @@ -1796,9 +1903,17 @@ Loaded includes: * "Getter" for a printable state name * * @return $stateName Name of the node's state in a printable format + * @throws BadMethodCallException If this instance doesn't have a callable getter for stateInstance * @todo Move this class away from this monolithic place (not whole class is monolithic) */ public final function getPrintableState () { + // Check if getter is there + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: CALLED!'); + if (!is_callable($this, 'getStateInstance')) { + // Throw BMCE + throw new BadMethodCallException(sprintf('this=%s has no callable getter for stateInstance', $this->__toString()), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL); + } + // Default is 'null' $stateName = 'null'; @@ -1806,12 +1921,14 @@ Loaded includes: $stateInstance = $this->getStateInstance(); // Is it an instance of Stateable? + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: stateInstance[]=%s', gettype($stateInstance))); if ($stateInstance instanceof Stateable) { // Then use that state name $stateName = $stateInstance->getStateName(); } // Return result + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: stateName=%s - EXIT!', $stateName)); return $stateName; } -- 2.39.5