use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
use Org\Mxchange\CoreFramework\Registry\Registerable;
use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
/**
* A class holding general data about the application and some methods for
// Get a controller resolver
$resolverClass = sprintf(
'Org\Mxchange\CoreFramework\Tests\Resolver\Controller\%s',
- self::convertToClassName(sprintf(
+ StringUtils::convertToClassName(sprintf(
'%s_%s_controller_resolver',
$this->getAppShortName(),
FrameworkBootstrap::getRequestTypeFromSystem()
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
use Org\Mxchange\CoreFramework\Request\Requestable;
use Org\Mxchange\CoreFramework\Response\Responseable;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \BadMethodCallException;
// Load basic include files to continue bootstrapping
self::loadInclude(new SplFileInfo(sprintf('%smain%sinterfaces%sclass_FrameworkInterface.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
self::loadInclude(new SplFileInfo(sprintf('%smain%sclasses%sclass_BaseFrameworkSystem.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
- self::loadInclude(new SplFileInfo(sprintf('%smain%sclasses%sutils%sclass_StringUtils.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
+ self::loadInclude(new SplFileInfo(sprintf('%smain%sclasses%sutils%sstring%sclass_StringUtils.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
self::loadInclude(new SplFileInfo(sprintf('%smain%sinterfaces%sregistry%sclass_Registerable.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
self::loadInclude(new SplFileInfo(sprintf('%sconfig%sclass_FrameworkConfiguration.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR)));
$requestType = self::getRequestTypeFromSystem();
// Create a new request object
- $requestInstance = ObjectFactory::createObjectByName(sprintf('Org\Mxchange\CoreFramework\Request\%sRequest', BaseFrameworkSystem::convertToClassName($request)));
+ $requestInstance = ObjectFactory::createObjectByName(sprintf('Org\Mxchange\CoreFramework\Request\%sRequest', StringUtils::convertToClassName($request)));
// Remember request instance here
self::setRequestInstance($requestInstance);
} // END - if
// ... and a new response object
- $responseClass = sprintf('Org\Mxchange\CoreFramework\Response\%sResponse', BaseFrameworkSystem::convertToClassName($request));
+ $responseClass = sprintf('Org\Mxchange\CoreFramework\Response\%sResponse', StringUtils::convertToClassName($request));
$responseInstance = ObjectFactory::createObjectByName($responseClass);
// Remember response instance here
// CFG: QUIET-DNS-RESOLVER
$cfg->setConfigEntry('quiet_dns_resolver', FALSE);
-// Remove config from this name-space. Don't worry, no configuration is cleared.
-unset($cfg);
+// CFG: THOUSANDS-SEPARATOR
+$cfg->setConfigEntry('thousands_separator', '.');
+
+// CFG: DECIMALS-SEPARATOR
+$cfg->setConfigEntry('decimals_separator', ',');
use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
use Org\Mxchange\CoreFramework\Registry\Registerable;
-use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \InvalidArgumentException;
use Org\Mxchange\CoreFramework\Stream\Input\InputStream;
use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
use Org\Mxchange\CoreFramework\Stream\Output\OutputStream;
-use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
use Org\Mxchange\CoreFramework\User\ManageableAccount;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
use Org\Mxchange\CoreFramework\Visitor\Visitor;
// Import SPL stuff
*/
private $callbackInstance = NULL;
- /**
- * Thousands separator
- */
- private $thousands = '.'; // German
-
- /**
- * Decimal separator
- */
- private $decimals = ','; // German
-
/**
* Generic array
*/
private $genericArray = array();
- /**
- * Array with bitmasks and such for pack/unpack methods to support both
- * 32-bit and 64-bit systems
- */
- private $packingData = array(
- 32 => array(
- 'step' => 3,
- 'left' => 0xffff0000,
- 'right' => 0x0000ffff,
- 'factor' => 16,
- 'format' => 'II',
- ),
- 64 => array(
- 'step' => 7,
- 'left' => 0xffffffff00000000,
- 'right' => 0x00000000ffffffff,
- 'factor' => 32,
- 'format' => 'NN'
- )
- );
-
- /**
- * Simple 64-bit check, thanks to "Salman A" from stackoverflow.com:
- *
- * The integer size is 4 bytes on 32-bit and 8 bytes on a 64-bit system.
- */
- private $archArrayElement = false;
-
/***********************
* Exception codes.... *
***********************/
// Then set it
self::$startupTime = microtime(true);
} // END - if
-
- // Set array element
- $this->archArrayElement = (PHP_INT_SIZE === 8 ? 64 : 32);
}
/**
return crc32($this->__toString());
}
- /**
- * Formats computer generated price values into human-understandable formats
- * with thousand and decimal separators.
- *
- * @param $value The in computer format value for a price
- * @param $currency The currency symbol (use HTML-valid characters!)
- * @param $decNum Number of decimals after commata
- * @return $price The for the current language formated price string
- * @throws MissingDecimalsThousandsSeparatorException If decimals or
- * thousands separator
- * is missing
- */
- public function formatCurrency ($value, $currency = '€', $decNum = 2) {
- // Are all required attriutes set?
- if ((!isset($this->decimals)) || (!isset($this->thousands))) {
- // Throw an exception
- throw new MissingDecimalsThousandsSeparatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
- } // END - if
-
- // Cast the number
- $value = (float) $value;
-
- // Reformat the US number
- $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
-
- // Return as string...
- return $price;
- }
-
/**
* Appends a trailing slash to a string
*
}
}
- /**
- * Converts e.g. a command from URL to a valid class by keeping out bad characters
- *
- * @param $str The string, what ever it is needs to be converted
- * @return $className Generated class name
- */
- public static final function convertToClassName ($str) {
- // Init class name
- $className = '';
-
- // Convert all dashes in underscores
- $str = StringUtils::convertDashesToUnderscores($str);
-
- // Now use that underscores to get classname parts for hungarian style
- foreach (explode('_', $str) as $strPart) {
- // Make the class name part lower case and first upper case
- $className .= ucfirst(strtolower($strPart));
- } // END - foreach
-
- // Return class name
- return $className;
- }
-
/**
* Marks up the code by adding e.g. line numbers
*
* @return $fieldValue Field value from the user
* @throws NullPointerException If the result instance is null
*/
- public final function getField ($fieldName) {
+ public final function getField (string $fieldName) {
// Default field value
$fieldValue = NULL;
* @return $isSet Whether the given field name is set
* @throws NullPointerException If the result instance is null
*/
- public function isFieldSet ($fieldName) {
+ public function isFieldSet (string $fieldName) {
// Get result instance
$resultInstance = $this->getResultInstance();
* @param $boolean Boolean value
* @return $translated Translated boolean value
*/
- public static final function translateBooleanToYesNo ($boolean) {
+ public static final function translateBooleanToYesNo (bool $boolean) {
// Make sure it is really boolean
assert(is_bool($boolean));
return $translated;
}
- /**
- * Encodes raw data (almost any type) by "serializing" it and then pack it
- * into a "binary format".
- *
- * @param $rawData Raw data (almost any type)
- * @return $encoded Encoded data
- */
- protected function encodeData ($rawData) {
- // Make sure no objects or resources pass through
- assert(!is_object($rawData));
- assert(!is_resource($rawData));
-
- // First "serialize" it (json_encode() is faster than serialize())
- $encoded = $this->packString(json_encode($rawData));
-
- // And return it
- return $encoded;
- }
-
- /**
- * Pack a string into a "binary format". Please execuse me that this is
- * widely undocumented. :-(
- *
- * @param $str Unpacked string
- * @return $packed Packed string
- * @todo Improve documentation
- */
- protected function packString ($str) {
- // Debug message
- //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('str=' . $str . ' - CALLED!');
-
- // First compress the string (gzcompress is okay)
- $str = gzcompress($str);
-
- // Init variable
- $packed = '';
-
- // And start the "encoding" loop
- for ($idx = 0; $idx < strlen($str); $idx += $this->packingData[$this->archArrayElement]['step']) {
- $big = 0;
- for ($i = 0; $i < $this->packingData[$this->archArrayElement]['step']; $i++) {
- $factor = ($this->packingData[$this->archArrayElement]['step'] - 1 - $i);
-
- if (($idx + $i) <= strlen($str)) {
- $ord = ord(substr($str, ($idx + $i), 1));
-
- $add = $ord * pow(256, $factor);
-
- $big += $add;
-
- //print 'idx=' . $idx . ',i=' . $i . ',ord=' . $ord . ',factor=' . $factor . ',add=' . $add . ',big=' . $big . PHP_EOL;
- } // END - if
- } // END - for
-
- $l = ($big & $this->packingData[$this->archArrayElement]['left']) >>$this->packingData[$this->archArrayElement]['factor'];
- $r = $big & $this->packingData[$this->archArrayElement]['right'];
-
- $chunk = str_pad(pack($this->packingData[$this->archArrayElement]['format'], $l, $r), 8, '0', STR_PAD_LEFT);
- //* NOISY-DEBUG */ print 'big=' . $big . ',chunk('.strlen($chunk) . ')='.md5($chunk).PHP_EOL;
-
- $packed .= $chunk;
- } // END - for
-
- // Return it
- //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('packed=' . $packed . ' - EXIT!');
- return $packed;
- }
-
/**
* Creates a full-qualified file name (FQFN) for given file name by adding
* a configured temporary file path to it.
use Org\Mxchange\CoreFramework\Request\Requestable;
use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
use Org\Mxchange\CoreFramework\Response\Responseable;
-use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
/**
* A command for the login area (member/gamer area)
use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
use Org\Mxchange\CoreFramework\Criteria\Search\SearchCriteria;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
-use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
/**
* A general crtieria class
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Loader\NoClassException;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
/**
* The general feature management class. No instance is needed as this class
// Array for call-back
$callable = array(
self::$enabledFeatures[$featureName]['instance'],
- sprintf('featureMethod%s', self::convertToClassName($featureMethod))
+ sprintf('featureMethod%s', StringUtils::convertToClassName($featureMethod))
);
// So is the feature's method callable?
use Org\Mxchange\CoreFramework\Filesystem\Block;
use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
+use Org\Mxchange\CoreFramework\String\Util\StringUtils;
// Import SPL stuff
use \SplFileInfo;
assert(!is_resource($value));
// Encode/convert the value into a "binary format"
- $encoded = $this->encodeData($value);
+ $encoded = StringUtils::encodeData($value);
// Get a strong hash for the "encoded" data
$hash = self::hash($encoded);
use Org\Mxchange\CoreFramework\Generic\NullPointerException;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
/**
* A generic helper class with generic methods
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($fieldName.'='.$fieldValue);
// Now filter it through the value through the filter method
- $filteredValue = call_user_func_array(array($this, 'doFilter' . self::convertToClassName($filterMethod)), array($fieldValue));
+ $filteredValue = call_user_func_array(array($this, 'doFilter' . StringUtils::convertToClassName($filterMethod)), array($fieldValue));
// Assign it with a template variable
$this->getTemplateInstance()->assignVariable('block_' . $fieldName, $filteredValue);
use Org\Mxchange\CoreFramework\Generic\NullPointerException;
use Org\Mxchange\CoreFramework\Helper\Template\HelpableTemplate;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
-use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
/**
// Import framework stuff
use Org\Mxchange\CoreFramework\Request\Requestable;
-use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
/**
* A concrete and secured HTML request class to make HTML requests more abstract
// Import framework stuff
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Resolver\BaseResolver;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \InvalidArgumentException;
'%s\%s%sAction',
$namespace,
$this->getCapitalizedClassPrefix(),
- self::convertToClassName($actionName)
+ StringUtils::convertToClassName($actionName)
);
// Now, let us create the full name of the action class
'%s\%s%sAction',
$this->getNamespace(),
$this->getCapitalizedClassPrefix(),
- self::convertToClassName($actionName)
+ StringUtils::convertToClassName($actionName)
);
// ... and set it
use Org\Mxchange\CoreFramework\Controller\Controller;
use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
/**
* A generic resolver class
$className = $this->getClassPrefix();
// And capitalize it
- $className = self::convertToClassName($className);
+ $className = StringUtils::convertToClassName($className);
// Return it
return $className;
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Request\Requestable;
use Org\Mxchange\CoreFramework\Resolver\BaseResolver;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \InvalidArgumentException;
'%s\%s%sCommand',
$this->getNamespace(),
$this->getCapitalizedClassPrefix(),
- self::convertToClassName($commandName)
+ StringUtils::convertToClassName($commandName)
);
// Create command class name
'%s\%s%sCommand',
$namespace,
$this->getCapitalizedClassPrefix(),
- self::convertToClassName($commandName)
+ StringUtils::convertToClassName($commandName)
);
// Now, let us create the full name of the command class
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
use Org\Mxchange\CoreFramework\Resolver\BaseResolver;
use Org\Mxchange\CoreFramework\Resolver\Controller\ControllerResolver;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \InvalidArgumentException;
'%s\%s%sController',
$this->getNamespace(),
$this->getCapitalizedClassPrefix(),
- self::convertToClassName($controllerName)
+ StringUtils::convertToClassName($controllerName)
);
// ... and set it
$className = sprintf(
'%s\%sController',
$namespace,
- $this->getCapitalizedClassPrefix() . self::convertToClassName($controllerName)
+ $this->getCapitalizedClassPrefix() . StringUtils::convertToClassName($controllerName)
);
$newsControllerName = sprintf(
'%s\%sDefaultNewsController',
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
use Org\Mxchange\CoreFramework\Response\Responseable;
-use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \InvalidArgumentException;
// Is this view helper loaded?
if (!isset($this->helpers[$helperName])) {
// Create a class name
- $className = self::convertToClassName($helperName) . 'ViewHelper';
+ $className = StringUtils::convertToClassName($helperName) . 'ViewHelper';
// Generate new instance
$this->helpers[$helperName] = ObjectFactory::createObjectByName($className);
use Org\Mxchange\CoreFramework\Response\Responseable;
use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \SplFileInfo;
//* DEBUG: */ echo "START: >".$element."<<br />\n";
if (in_array($element, $this->mainNodes)) {
// Okay, main node found!
- $methodName = 'setImage' . self::convertToClassName($element);
+ $methodName = 'setImage' . StringUtils::convertToClassName($element);
} elseif (in_array($element, $this->subNodes)) {
// Sub node found
- $methodName = 'setImageProperty' . self::convertToClassName($element);
+ $methodName = 'setImageProperty' . StringUtils::convertToClassName($element);
} elseif ($element != 'image') {
// Invalid node name found
throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
}
// Construct method name
- $methodName = 'finish' . self::convertToClassName($nodeName);
+ $methodName = 'finish' . StringUtils::convertToClassName($nodeName);
// Call the corresponding method
call_user_func_array(array($this->getImageInstance(), $methodName), array());
$imageType = $this->compileRawCode($imageType);
// Now make a class name of it
- $className = self::convertToClassName($imageType.'_image');
+ $className = StringUtils::convertToClassName($imageType.'_image');
// And try to initiate it
$this->setImageInstance(ObjectFactory::createObjectByName($className, array($this)));
use Org\Mxchange\CoreFramework\Response\Responseable;
use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \UnexpectedValueException;
//* DEBUG: */ echo "START: >".$element."<<br />\n";
if (in_array($element, $this->getMainNodes())) {
// Okay, main node found!
- $methodName = 'setEmail' . self::convertToClassName($element);
+ $methodName = 'setEmail' . StringUtils::convertToClassName($element);
} elseif (in_array($element, $this->getSubNodes())) {
// Sub node found
- $methodName = 'setEmailProperty' . self::convertToClassName($element);
+ $methodName = 'setEmailProperty' . StringUtils::convertToClassName($element);
} elseif ($element != 'text-mail') {
// Invalid node name found
throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
}
// Construct method name
- $methodName = 'finish' . self::convertToClassName($nodeName);
+ $methodName = 'finish' . StringUtils::convertToClassName($nodeName);
// Call the corresponding method
call_user_func_array(array($this, $methodName), array());
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \SplFileInfo;
//* DEBUG: */ echo "START: >".$element."<<br />\n";
if (in_array($element, $this->getMainNodes())) {
// Okay, main node found!
- $methodName = 'start' . self::convertToClassName($element);
+ $methodName = 'start' . StringUtils::convertToClassName($element);
// Set it
$this->setCurrMainNode($element);
} elseif (in_array($element, $this->getSubNodes())) {
// Sub node found
- $methodName = 'start' . self::convertToClassName($element);
+ $methodName = 'start' . StringUtils::convertToClassName($element);
} elseif ($element != 'menu') {
// Invalid node name found
throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
} // END - if
// Construct method name
- $methodName = 'finish' . self::convertToClassName($nodeName);
+ $methodName = 'finish' . StringUtils::convertToClassName($nodeName);
// Call the corresponding method
//* DEBUG: */ echo "call: ".$methodName."<br />\n";
+++ /dev/null
-<?php
-// Own namespace
-namespace Org\Mxchange\CoreFramework\String\Utils;
-
-// Import framework stuff
-use Org\Mxchange\CoreFramework\Configuration\FrameworkConfiguration;
-use Org\Mxchange\CoreFramework\Generic\NullPointerException;
-use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
-
-// Import SPL stuff
-use \InvalidArgumentException;
-
-/**
- * A string 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 StringUtils extends BaseFrameworkSystem {
- /**
- * Private constructor, no instance needed
- *
- * @return void
- */
- private function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Converts dashes to underscores, e.g. useable for configuration entries
- *
- * @param $str The string with maybe dashes inside
- * @return $str The converted string with no dashed, but underscores
- * @throws NullPointerException If $str is null
- * @throws InvalidArgumentException If $str is empty
- */
- public static function convertDashesToUnderscores ($str) {
- // Is it null?
- if (is_null($str)) {
- // Throw NPE
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_string($str)) {
- // Entry is empty
- throw new InvalidArgumentException(sprintf('str[]=%s is not a string', gettype($str)), FrameworkConfiguration::EXCEPTION_CONFIG_KEY_IS_EMPTY);
- } elseif ((is_string($str)) && (empty($str))) {
- // Entry is empty
- throw new InvalidArgumentException('str is empty', FrameworkConfiguration::EXCEPTION_CONFIG_KEY_IS_EMPTY);
- }
-
- // Convert them all
- $str = str_replace('-', '_', $str);
-
- // Return converted string
- return $str;
- }
-
-}
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Utils\String;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Configuration\FrameworkConfiguration;
+use Org\Mxchange\CoreFramework\Generic\NullPointerException;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+
+// Import SPL stuff
+use \InvalidArgumentException;
+
+/**
+ * A string 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 StringUtils extends BaseFrameworkSystem {
+ /**
+ * Thousands separator
+ */
+ private static $thousands = ''; // German
+
+ /**
+ * Decimal separator
+ */
+ private static $decimals = ''; // German
+
+ /**
+ * Array with bitmasks and such for pack/unpack methods to support both
+ * 32-bit and 64-bit systems
+ */
+ private static $packingData = array(
+ 32 => array(
+ 'step' => 3,
+ 'left' => 0xffff0000,
+ 'right' => 0x0000ffff,
+ 'factor' => 16,
+ 'format' => 'II',
+ ),
+ 64 => array(
+ 'step' => 7,
+ 'left' => 0xffffffff00000000,
+ 'right' => 0x00000000ffffffff,
+ 'factor' => 32,
+ 'format' => 'NN'
+ )
+ );
+
+ /**
+ * Simple 64-bit check, thanks to "Salman A" from stackoverflow.com:
+ *
+ * The integer size is 4 bytes on 32-bit and 8 bytes on a 64-bit system.
+ */
+ private static $archArrayElement = 0;
+
+ /**
+ * Private constructor, no instance needed. If PHP would have a static initializer ...
+ *
+ * @return void
+ */
+ private function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Is one not set?
+ if (empty(self::$archArrayElement)) {
+ // Set array element
+ self::$archArrayElement = (PHP_INT_SIZE === 8 ? 64 : 32);
+
+ // Init from configuration
+ self::$thousands = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('thousands_separator');
+ self::$decimals = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('decimals_separator');
+ }
+ }
+
+ /**
+ * Converts dashes to underscores, e.g. useable for configuration entries
+ *
+ * @param $str The string with maybe dashes inside
+ * @return $str The converted string with no dashed, but underscores
+ * @throws NullPointerException If $str is null
+ * @throws InvalidArgumentException If $str is empty
+ */
+ public static function convertDashesToUnderscores ($str) {
+ // Is it null?
+ if (is_null($str)) {
+ // Throw NPE
+ throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ } elseif (!is_string($str)) {
+ // Entry is empty
+ throw new InvalidArgumentException(sprintf('str[]=%s is not a string', gettype($str)), FrameworkConfiguration::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+ } elseif ((is_string($str)) && (empty($str))) {
+ // Entry is empty
+ throw new InvalidArgumentException('str is empty', FrameworkConfiguration::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+ }
+
+ // Convert them all
+ $str = str_replace('-', '_', $str);
+
+ // Return converted string
+ return $str;
+ }
+
+ /**
+ * Encodes raw data (almost any type) by "serializing" it and then pack it
+ * into a "binary format".
+ *
+ * @param $rawData Raw data (almost any type)
+ * @return $encoded Encoded data
+ * @throws InvalidArgumentException If $rawData has a non-serializable data type
+ */
+ public static function encodeData ($rawData) {
+ // Make sure no objects or resources pass through
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: rawData[]=%s - CALLED!', gettype($rawData)));
+ if (is_object($rawData) || is_resource($rawData)) {
+ // Not all variable types should be serialized here
+ throw new InvalidArgumentException(sprintf('rawData[]=%s cannot be serialized.', gettype($rawData)));
+ }
+
+ // Init instance
+ $dummyInstance = new StringUtils();
+
+ // First "serialize" it (json_encode() is faster than serialize())
+ $encoded = self::packString(json_encode($rawData));
+
+ // And return it
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: encoded()=%d - EXIT!', strlen($encoded)));
+ return $encoded;
+ }
+
+ /**
+ * Converts e.g. a command from URL to a valid class by keeping out bad characters
+ *
+ * @param $str The string, what ever it is needs to be converted
+ * @return $className Generated class name
+ */
+ public static final function convertToClassName (string $str) {
+ // Init class name
+ $className = '';
+
+ // Convert all dashes in underscores
+ $str = self::convertDashesToUnderscores($str);
+
+ // Now use that underscores to get classname parts for hungarian style
+ foreach (explode('_', $str) as $strPart) {
+ // Make the class name part lower case and first upper case
+ $className .= ucfirst(strtolower($strPart));
+ }
+
+ // Return class name
+ return $className;
+ }
+
+ /**
+ * Formats computer generated price values into human-understandable formats
+ * with thousand and decimal separators.
+ *
+ * @param $value The in computer format value for a price
+ * @param $currency The currency symbol (use HTML-valid characters!)
+ * @param $decNum Number of decimals after commata
+ * @return $price The for the current language formated price string
+ * @throws MissingDecimalsThousandsSeparatorException If decimals or thousands separator is missing
+ */
+ public static function formatCurrency (float $value, string $currency = '€', int $decNum = 2) {
+ // Init instance
+ $dummyInstance = new StringUtils();
+
+ // Reformat the US number
+ $price = number_format($value, $decNum, self::$decimals, self::$thousands) . $currency;
+
+ // Return as string...
+ return $price;
+ }
+
+ /**
+ * Pack a string into a "binary format". Please execuse me that this is
+ * widely undocumented. :-(
+ *
+ * @param $str Unpacked string
+ * @return $packed Packed string
+ * @todo Improve documentation
+ */
+ private static function packString (string $str) {
+ // First compress the string (gzcompress is okay)
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: str=%s - CALLED!', $str));
+ $str = gzcompress($str);
+
+ // Init variable
+ $packed = '';
+
+ // And start the "encoding" loop
+ for ($idx = 0; $idx < strlen($str); $idx += self::$packingData[self::$archArrayElement]['step']) {
+ $big = 0;
+ for ($i = 0; $i < self::$packingData[self::$archArrayElement]['step']; $i++) {
+ $factor = (self::$packingData[self::$archArrayElement]['step'] - 1 - $i);
+
+ if (($idx + $i) <= strlen($str)) {
+ $ord = ord(substr($str, ($idx + $i), 1));
+
+ $add = $ord * pow(256, $factor);
+
+ $big += $add;
+
+ //print 'idx=' . $idx . ',i=' . $i . ',ord=' . $ord . ',factor=' . $factor . ',add=' . $add . ',big=' . $big . PHP_EOL;
+ }
+ }
+
+ // Left/right parts (low/high?)
+ $l = ($big & self::$packingData[self::$archArrayElement]['left']) >>self::$packingData[self::$archArrayElement]['factor'];
+ $r = $big & self::$packingData[self::$archArrayElement]['right'];
+
+ // Create chunk
+ $chunk = str_pad(pack(self::$packingData[self::$archArrayElement]['format'], $l, $r), 8, '0', STR_PAD_LEFT);
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: big=%d,chunk(%d)=%s', $big, strlen($chunk), md5($chunk)));
+
+ $packed .= $chunk;
+ } // END - for
+
+ // Return it
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: packed=%s - EXIT!', $packed));
+ return $packed;
+ }
+
+}
<?php
-// [EOF]
+// @DEPRECATED
<?php
-// Own namespace
-namespace Org\Mxchange\CoreFramework\Deprecated;
-
-// Import framework stuff
-use Org\Mxchange\CoreFramework\Generic\FrameworkException;
-
-/**
- * An exception thrown when the decimal and thousands separators are missing
- *
- * @author Roland Haeder <webmaster@shipsimu.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.shipsimu.org
- * @deprecated Don't use this anymore
- *
- * 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/>.
- */
-class MissingDecimalsThousandsSeparatorException extends FrameworkException {
- /**
- * The constructor
- *
- * @param $message Message from the exception
- * @param $code Code number for the exception
- * @return void
- */
- public function __construct ($instance, $code) {
- // Add a message around the missing class
- $message = sprintf('[%s:%d] Decimal and thousand seperators are missing.',
- $instance->__toString(),
- $this->getLine()
- );
-
- // Call parent constructor
- parent::__construct($message, $code);
- }
-
-}
+// @DEPRECATED
* @return $fieldValue Field value from the user
* @throws NullPointerException If the result instance is null
*/
- function getField ($fieldName);
+ function getField (string $fieldName);
/**
* Checks if given field is set
* @return $isSet Whether the given field name is set
* @throws NullPointerException If the result instance is null
*/
- function isFieldSet ($fieldName);
+ function isFieldSet (string $fieldName);
/**
* Setter for call-back instance