if (self::$startupTime == 0) {
// Then set it
self::$startupTime = microtime(true);
- } // END - if
+ }
}
/**
* @args $args Arguments passed to the method
* @return void
*/
- public final function __call ($methodName, $args) {
+ public final function __call (string $methodName, array $args = NULL) {
// Set self-instance
self::$instance = $this;
* @return void
* @throws InvalidArgumentException If self::$instance is not a framework's own object
*/
- public static final function __callStatic ($methodName, $args) {
- // Trace message
- //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
-
+ public static final function __callStatic (string $methodName, array $args = NULL) {
// Init argument string and class name
+ //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
$argsString = '';
$className = 'unknown';
// Comma for next one
$argsString .= ', ';
- } // END - foreach
+ }
// Last comma found?
if (substr($argsString, -2, 1) == ',') {
// Remove last comma
$argsString = substr($argsString, 0, -2);
- } // END - if
+ }
// Close braces
$argsString .= ')';
- } else {
- // Invalid arguments!
- $argsString = sprintf('!INVALID:%s!', gettype($args));
}
// Output stub message
* @param $value Value to store
* @return void
*/
- public final function __set ($name, $value) {
+ public final function __set (string $name, $value) {
$this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
$name,
gettype($value),
* @param $name Name of the field/attribute
* @return void
*/
- public final function __get ($name) {
+ public final function __get (string $name) {
$this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
$name
));
* @param $name Name of the field/attribute
* @return void
*/
- public final function __unset ($name) {
+ public final function __unset (string $name) {
$this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
$name
));
* @param $realClass Class name (string)
* @return void
*/
- public final function setRealClass ($realClass) {
+ public final function setRealClass (string $realClass) {
// Set real class
- $this->realClass = (string) $realClass;
+ $this->realClass = $realClass;
}
/**
// Is there a trailing slash?
if (substr($str, -1, 1) != '/') {
$str .= '/';
- } // END - if
+ }
// Return string with trailing slash
return $str;
$content = sprintf('<div class="debug_message">
Message: %s
</div>' . PHP_EOL, $message);
- } // END - if
+ }
// Generate the output
$content .= sprintf('<pre>%s</pre>',
if (!empty($message)) {
// Then add it as well
$stubMessage .= ' Message: ' . $message;
- } // END - if
+ }
// Debug instance is there?
if (!is_null($this->getDebugInstance())) {
if (!empty($message)) {
// Output message
printf('Message: %s<br />' . PHP_EOL, $message);
- } // END - if
+ }
print('<pre>');
debug_print_backtrace();
// Exit program?
if ($doExit === true) {
exit();
- } // END - if
+ }
}
/**
if ($doPrint === false) {
// Die here if not printed
exit();
- } // END - if
+ }
} else {
// Are debug times enabled?
if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
// Prepent it
$message = $this->getPrintableExecutionTime() . $message;
- } // END - if
+ }
// Put directly out
if ($doPrint === true) {
$errorArray['message'],
$errorArray['type']
);
- } // END - if
+ }
// Add line number to the code
foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
($lineNo + 1),
htmlentities($code, ENT_QUOTES)
);
- } // END - foreach
+ }
// Return the code
return $markedCode;
}
- /**
- * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
- * beatiful for web-based front-ends. If null is given a message id
- * null_timestamp will be resolved and returned.
- *
- * @param $timestamp Timestamp to prepare (filter) for display
- * @return $readable A readable timestamp
- */
- public function doFilterFormatTimestamp ($timestamp) {
- // Default value to return
- $readable = '???';
-
- // Is the timestamp null?
- if (is_null($timestamp)) {
- // Get a message string
- $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
- } else {
- switch ($this->getLanguageInstance()->getLanguageCode()) {
- case 'de': // German format is a bit different to default
- // Split the GMT stamp up
- $dateTime = explode(' ', $timestamp );
- $dateArray = explode('-', $dateTime[0]);
- $timeArray = explode(':', $dateTime[1]);
-
- // Construct the timestamp
- $readable = sprintf(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('german_date_time'),
- $dateArray[0],
- $dateArray[1],
- $dateArray[2],
- $timeArray[0],
- $timeArray[1],
- $timeArray[2]
- );
- break;
-
- default: // Default is pass-through
- $readable = $timestamp;
- break;
- } // END - switch
- }
-
- // Return the stamp
- return $readable;
- }
-
- /**
- * Filter a given number into a localized number
- *
- * @param $value The raw value from e.g. database
- * @return $localized Localized value
- */
- public function doFilterFormatNumber ($value) {
- // Generate it from config and localize dependencies
- switch ($this->getLanguageInstance()->getLanguageCode()) {
- case 'de': // German format is a bit different to default
- $localized = number_format($value, FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('decimals'), ',', '.');
- break;
-
- default: // US, etc.
- $localized = number_format($value, FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('decimals'), '.', ',');
- break;
- } // END - switch
-
- // Return it
- return $localized;
- }
-
/**
* "Getter" for databse entry
*
if (!$this->getResultInstance() instanceof SearchableResult) {
// Throw an exception here
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } // END - if
+ }
// Rewind it
$this->getResultInstance()->rewind();
if ($this->getResultInstance()->valid() === false) {
// @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
- } // END - if
+ }
// Get next entry
$this->getResultInstance()->next();
if (is_null($resultInstance)) {
// Then the user instance is no longer valid (expired cookies?)
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } // END - if
+ }
// Get current array
$fieldArray = $resultInstance->current();
if (is_null($resultInstance)) {
// Then the user instance is no longer valid (expired cookies?)
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } // END - if
+ }
// Get current array
$fieldArray = $resultInstance->current();
// Yes, then send the whole result to the database layer
$wrapperInstance->doUpdateByResult($this->getResultInstance());
- } // END - if
+ }
}
/**
if (is_null(self::$hashLength)) {
// No, then hash a string and save its length.
self::$hashLength = strlen(self::hash('abc123'));
- } // END - if
+ }
// Return it
return self::$hashLength;
if ($castValue === true) {
// Cast to biggest numeric type
$ret = (double) $ret;
- } // END - if
+ }
// Assert only if requested
if ($assertMismatch === true) {
// Has the whole value changed?
assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
- } // END - if
+ }
// Return result
return $ret;
if ($assertMismatch === true) {
// Has the whole value changed?
assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
- } // END - if
+ }
// Return result
return $ret;
// No, then abort here
trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
exit;
- } // END - if
+ }
// Debug message
//* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
// Already initialized
trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
exit;
- } // END - if
+ }
// Initialize it
$this->genericArray[$keyGroup][$subGroup] = array();
// Already initialized
trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
exit;
- } // END - if
+ }
// Initialize it
$this->genericArray[$keyGroup][$subGroup][$key] = array();
// Already initialized
trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
exit;
- } // END - if
+ }
// Initialize it
$this->genericArray[$keyGroup][$subGroup][$key][$element] = array();
if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
// Initialize array
$this->initGenericArrayKey($keyGroup, $subGroup, $key);
- } // END - if
+ }
// Then push it
$count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
// Initialize array
$this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
- } // END - if
+ }
// Then push it
$count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
// Not found
trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
exit;
- } // END - if
+ }
// Then "pop" it
$value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
// Not found
trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
exit;
- } // END - if
+ }
// Then "shift" it
$value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
// Abort here
trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
exit;
- } // END - if
+ }
// Then count it
$count = count($this->genericArray[$keyGroup]);
// Abort here
trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
exit;
- } // END - if
+ }
// Then count it
$count = count($this->genericArray[$keyGroup][$subGroup]);
// Then abort here
trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
exit;
- } // END - if
+ }
// Return it
return $this->genericArray[$keyGroup];
// Then abort here
trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
exit;
- } // END - if
+ }
// Return it
return $this->genericArray[$keyGroup][$subGroup][$key];
// Then abort here
trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
exit;
- } // END - if
+ }
// Return it
return $this->genericArray[$keyGroup][$subGroup][$key][$element];
if (!is_writable($basePath)) {
// Path is write-protected
throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
- } // END - if
+ }
// Add it
$tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
// Not reachable
throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
- } // END - if
+ }
// Return it
return $tempInstance;
if ($stateInstance instanceof Stateable) {
// Then use that state name
$stateName = $stateInstance->getStateName();
- } // END - if
+ }
// Return result
return $stateName;
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Utils\Number;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+
+/**
+ * A number utility class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+final class NumberUtils extends BaseFrameworkSystem {
+
+ /**
+ * Private constructor, no instance needed. If PHP would have a static initializer ...
+ *
+ * @return void
+ */
+ private function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Filter a given number into a localized number
+ *
+ * @param $value The raw value from e.g. database
+ * @return $localized Localized value
+ * @todo Won't work as getLanguageInstance() is still in monolithic BaseFrameworkSystem
+ */
+ public static function doFilterFormatNumber ($value) {
+ // Generate it from config and localize dependencies
+ switch (FrameworkBootstrap::getLanguageInstance()->getLanguageCode()) {
+ case 'de': // German format is a bit different to default
+ $localized = number_format($value, FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('decimals'), ',', '.');
+ break;
+
+ default: // US, etc.
+ $localized = number_format($value, FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('decimals'), '.', ',');
+ break;
+ }
+
+ // Return it
+ return $localized;
+ }
+
+ /**
+ * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
+ * beatiful for web-based front-ends. If null is given a message id
+ * null_timestamp will be resolved and returned.
+ *
+ * @param $timestamp Timestamp to prepare (filter) for display
+ * @return $readable A readable timestamp
+ * @todo Won't work as getLanguageInstance() is still in monolithic BaseFrameworkSystem
+ */
+ public static function doFilterFormatTimestamp ($timestamp) {
+ // Default value to return
+ $readable = '???';
+
+ // Is the timestamp null?
+ if (is_null($timestamp)) {
+ // Get a message string
+ $readable = FrameworkBootstrap::getLanguageInstance()->getMessage('null_timestamp');
+ } else {
+ switch (FrameworkBootstrap::getLanguageInstance()->getLanguageCode()) {
+ case 'de': // German format is a bit different to default
+ // Split the GMT stamp up
+ $dateTime = explode(' ', $timestamp );
+ $dateArray = explode('-', $dateTime[0]);
+ $timeArray = explode(':', $dateTime[1]);
+
+ // Construct the timestamp
+ $readable = sprintf(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('german_date_time'),
+ $dateArray[0],
+ $dateArray[1],
+ $dateArray[2],
+ $timeArray[0],
+ $timeArray[1],
+ $timeArray[2]
+ );
+ break;
+
+ default: // Default is pass-through
+ $readable = $timestamp;
+ break;
+ }
+ }
+
+ // Return the stamp
+ return $readable;
+ }
+
+}