*/
private $visitorInstance = NULL;
+ /**
+ * DHT instance
+ */
+ private $dhtInstance = NULL;
+
/**
* An instance of a database wrapper class
*/
* @return void
*/
public static final function __callStatic ($methodName, $args) {
- // Implode all given arguments
+ // Init argument string
$argsString = '';
+
+ // Is it empty or an array?
if (empty($args)) {
// No arguments
$argsString = 'NULL';
* @param $fileIoInstance An instance to the file I/O sub-system
* @return void
*/
- public final function setFileIoInstance (FileIoHandler $fileIoInstance) {
+ public final function setFileIoInstance (IoHandler $fileIoInstance) {
$this->fileIoInstance = $fileIoInstance;
}
}
/**
- * Setter for BaseDatabaseWrapper instance
+ * Setter for DatabaseWrapper instance
*
- * @param $wrapperInstance An instance of an BaseDatabaseWrapper
+ * @param $wrapperInstance An instance of an DatabaseWrapper
* @return void
*/
- public final function setWrapperInstance (BaseDatabaseWrapper $wrapperInstance) {
+ public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
$this->wrapperInstance = $wrapperInstance;
}
/**
- * Getter for BaseDatabaseWrapper instance
+ * Getter for DatabaseWrapper instance
*
- * @return $wrapperInstance An instance of an BaseDatabaseWrapper
+ * @return $wrapperInstance An instance of an DatabaseWrapper
*/
public final function getWrapperInstance () {
return $this->wrapperInstance;
return $this->visitorInstance;
}
+ /**
+ * Setter for DHT instance
+ *
+ * @param $dhtInstance A Distributable instance
+ * @return void
+ */
+ protected final function setDhtInstance (Distributable $dhtInstance) {
+ $this->dhtInstance = $dhtInstance;
+ }
+
+ /**
+ * Getter for DHT instance
+ *
+ * @return $dhtInstance A Distributable instance
+ */
+ protected final function getDhtInstance () {
+ return $this->dhtInstance;
+ }
+
/**
* Setter for raw package Data
*
* @param $doExit Whether exit the program (true is default)
* @return void
*/
- public function debugBackTrace ($message = '', $doExit = true) {
+ public function debugBackTrace ($message = '', $doExit = TRUE) {
// Sorry, there is no other way getting this nice backtrace
if (!empty($message)) {
// Output message
}
/**
- * Converts even very large decimal numbers, also with negative sign, to a
- * hexadecimal string.
+ * Converts even very large decimal numbers, also signed, to a hexadecimal
+ * string.
*
* This work is based on comment #97756 on php.net documentation page at:
* <http://de.php.net/manual/en/function.hexdec.php#97756>
// Encode the decimal number into a hexadecimal string
$hex = '';
do {
- $hex = self::$dechex[($dec % 16)] . $hex;
- $dec /= 16;
+ $hex = self::$dechex[($dec % (2 ^ 4))] . $hex;
+ $dec /= (2 ^ 4);
} while ($dec >= 1);
/*
- * We need hexadecimal strings with leading zeros if the length cannot
- * be divided by 2
+ * Leading zeros are required for hex-decimal "numbers". In some
+ * situations more leading zeros are wanted, so check for both
+ * conditions.
*/
if ($maxLength > 0) {
// Prepend more zeros
- $hex = $this->prependStringToString($hex, '0', $maxLength);
+ $hex = str_pad($hex, $maxLength, '0', STR_PAD_LEFT);
} elseif ((strlen($hex) % 2) != 0) {
+ // Only make string's length dividable by 2
$hex = '0' . $hex;
}
return $asc;
}
- /**
- * Prepends a given string $prepend to $str with a given total length
- *
- * @param $str Given original string which should be prepended
- * @param $prepend The string to prepend
- * @param $length Total length of the final string
- * @return $strFinal Final prepended string
- */
- protected function prependStringToString ($str, $prepend, $length) {
- // Set final string to original string by default
- $strFinal = $str;
-
- // Can it devided
- if (strlen($str) < $length) {
- // Difference between total length and length of original string
- $diff = $length - strlen($str);
-
- // Prepend the string
- $prepend = str_repeat($prepend, ($diff / strlen($prepend) + 1));
-
- // Make sure it will definedly fit
- assert(strlen($prepend) >= $diff);
-
- // Cut it a little down
- $prepend = substr($prepend, 0, $diff);
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('prepend('.strlen($prepend).')='.$prepend.',diff='.$diff.',length='.$length);
-
- // Construct the final prepended string
- $strFinal = $prepend . $str;
- } // END - if
-
- // Return it
- return $strFinal;
- }
-
/**
* Checks whether the given encoded data was encoded with Base64
*
// Return result
return $ret;
}
+
+ /**
+ * Checks whether start/end marker are set
+ *
+ * @param $data Data to be checked
+ * @return $isset Whether start/end marker are set
+ */
+ public final function ifStartEndMarkersSet ($data) {
+ // Determine it
+ $isset = ((substr($data, 0, strlen(BaseRawDataHandler::STREAM_START_MARKER)) == BaseRawDataHandler::STREAM_START_MARKER) && (substr($data, -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER), strlen(BaseRawDataHandler::STREAM_END_MARKER)) == BaseRawDataHandler::STREAM_END_MARKER));
+
+ // ... and return it
+ return $isset;
+ }
}
// [EOF]