X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fclass_BaseFrameworkSystem.php;h=db8d9776e79de2c89de69da25e8385afaba929d1;hp=c890cc23c0529f3c0109a00ed19e3c19f68da5f4;hb=acb9e8776771abf9789ef9b7dd8dc92ed8c9fdd8;hpb=50861b4a1cc38134c915eb989ad249bbe6c8e601 diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index c890cc23..db8d9776 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -128,6 +128,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $databaseInstance = null; + /** + * A helper instance for the form + */ + private $helperInstance = null; + + /** + * An instance of a source + */ + private $sourceInstance = null; + /** * The real class name */ @@ -202,6 +212,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b; const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c; const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d; + const EXCEPTION_UNSPPORTED_OPERATION = 0x02e; const EXCEPTION_MISSING_ELEMENT = 0x030; const EXCEPTION_HEADERS_ALREADY_SENT = 0x031; const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032; @@ -214,6 +225,46 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039; const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x040; + // Hexadecimal->Decimal translation array + private static $hexdec = array( + '0' => 0, + '1' => 1, + '2' => 2, + '3' => 3, + '4' => 4, + '5' => 5, + '6' => 6, + '7' => 7, + '8' => 8, + '9' => 9, + 'a' => 10, + 'b' => 11, + 'c' => 12, + 'd' => 13, + 'e' => 14, + 'f' => 15 + ); + + // Decimal->hexadecimal translation array + private static $dechex = array( + 0 => '0', + 1 => '1', + 2 => '2', + 3 => '3', + 4 => '4', + 5 => '5', + 6 => '6', + 7 => '7', + 8 => '8', + 9 => '9', + 10 => 'a', + 11 => 'b', + 12 => 'c', + 13 => 'd', + 14 => 'e', + 15 => 'f' + ); + /** * Protected super constructor * @@ -310,6 +361,45 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $this->realClass; } + /** + * Magic function to catch setting of missing but set class fields/attributes + * + * @param $name Name of the field/attribute + * @param $value Value to store + * @return void + */ + public final function __set ($name, $value) { + $this->debugBackTrace(sprintf("Tried to set a missing field. name=%s, value[%s]=%s", + $name, + gettype($value), + $value + )); + } + + /** + * Magic function to catch getting of missing fields/attributes + * + * @param $name Name of the field/attribute + * @return void + */ + public final function __get ($name) { + $this->debugBackTrace(sprintf("Tried to get a missing field. name=%s", + $name + )); + } + + /** + * Magic function to catch unsetting of missing fields/attributes + * + * @param $name Name of the field/attribute + * @return void + */ + public final function __unset ($name) { + $this->debugBackTrace(sprintf("Tried to unset a missing field. name=%s", + $name + )); + } + /** * Setter for database result instance * @@ -825,10 +915,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * Outputs a debug backtrace and stops further script execution * + * @param $message An optional message to output * @return void */ - public function debugBackTrace () { + public function debugBackTrace ($message = '') { // Sorry, there is no other way getting this nice backtrace + if (!empty($message)) { + // Output message + printf("Message: %s
\n", $message); + } // END - if + print("
\n");
 		debug_print_backtrace();
 		print("
"); @@ -1439,6 +1535,44 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $this->socketResource; } + /** + * Setter for helper instance + * + * @param $helperInstance An instance of a helper class + * @return void + */ + protected final function setHelperInstance (Helper $helperInstance) { + $this->helperInstance = $helperInstance; + } + + /** + * Getter for helper instance + * + * @return $helperInstance An instance of a helper class + */ + public final function getHelperInstance () { + return $this->helperInstance; + } + + /** + * Setter for a Sourceable instance + * + * @param $sourceInstance The Sourceable instance + * @return void + */ + protected final function setSourceInstance (Sourceable $sourceInstance) { + $this->sourceInstance = $sourceInstance; + } + + /** + * Getter for a Sourceable instance + * + * @param $sourceInstance The Sourceable instance + */ + protected final function getSourceInstance () { + return $this->sourceInstance; + } + /** * Setter for raw package Data * @@ -1457,6 +1591,127 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { public function getPackageData () { return $this->packageData; } + + /** + * Converts a hexadecimal string, even with negative sign as first string to + * a decimal number using BC functions. + * + * This work is based on comment #86673 on php.net documentation page at: + * + * + * @param $hex Hexadecimal string + * @return $dec Decimal number + */ + public final function hex2dec ($hex) { + // Convert to all lower-case + $hex = strtolower($hex); + + // Detect sign (negative/positive numbers) + $sign = ''; + if (substr($hex, 0, 1) == '-') { + $sign = '-'; + $hex = substr($hex, 1); + } // END - if + + // Decode the hexadecimal string into a decimal number + $dec = 0; + for ($i = strlen($hex) - 1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) { + $factor = self:$hexdec[substr($hex, $i, 1)]; + $dec = bcadd($dec, bcmul($factor, $e)); + } // END - for + + // Return the decimal number + return $sign . $dec; + } + + /** + * Converts even very large decimal numbers, also with negative sign, to a + * hexadecimal string. + * + * This work is based on comment #97756 on php.net documentation page at: + * + * + * @param $dec Decimal number, even with negative sign + * @return $hex Hexadecimal string + */ + public final function dec2hex ($dec) { + // Detect sign (negative/positive numbers) + $sign = ''; + if ($dec < 0) { + $sign = '-'; + $dec = abs($dec); + } // END - if + + // Encode the decimal number into a hexadecimal string + $hex = ''; + do { + $hex = self:$dechex[($dec % 16)] . $hex; + $dec /= 16; + } while ($dec >= 1); + + // Return the hexadecimal string + return $sign . $hex; + } + + /** + * Converts a ASCII string (0 to 255) into a decimal number. + * + * @param $asc The ASCII string to be converted + * @return $dec Decimal number + */ + public final function asc2dec ($asc) { + // Convert it into a hexadecimal number + $hex = bin2hex($asc); + + // And back into a decimal number + $dec = $this->hex2dec($hex); + + // Return it + return $dec; + } + + /** + * Converts a decimal number into an ASCII string. + * + * @param $dec Decimal number + * @return $asc An ASCII string + */ + public final function dec2asc ($deg) { + // First convert the number into a hexadecimal string + $hex = $this->dec2hex($deg); + + // Then convert it into the ASCII string + $asc = $this->hex2asc($hex); + + // Return it + return $asc; + } + + /** + * Converts a hexadecimal number into an ASCII string. Negative numbers + * are not allowed. + * + * @param $hex Hexadecimal string + * @return $asc An ASCII string + */ + public final function hex2asc ($hex) { + // Check for length, it must be devideable by 2 + assert((strlen($hex) % 2) == 0); + + // Walk the string + $asc = ''; + for ($idx = 0; $idx < strlen($hex); $idx+=2) { + // Get the decimal number of the chunk + $part = hexdec(substr($hex, $idx, 2)); + $this->debugOutput(__FUNCTION__ . ': part(' . strlen($part) . ')=' . $part); + + // Add it to the final string + $asc .= chr($part); + } // END - for + + // Return the final string + return $asc; + } } // [EOF]