*/
private static $decimals = ''; // German
+ /**
+ * In-method cache array
+ */
+ private static $cache = [];
+
/**
* Array with bitmasks and such for pack/unpack methods to support both
* 32-bit and 64-bit systems
*
* @param $str The string, what ever it is needs to be converted
* @return $className Generated class name
+ * @throws InvalidArgumentException If a paramter is invalid
*/
public static final function convertToClassName (string $str) {
// Is the parameter valid?
- /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: str=%s - CALLED!', $str));
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: str=%s - CALLED!', $str));
if (empty($str)) {
// No empty strings, please
throw new InvalidArgumentException('Parameter "str" is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
- }
-
- // Init class name
- $className = '';
-
- // Convert all dashes in underscores
- $str = self::convertDashesToUnderscores($str);
+ } elseif (!isset(self::$cache[$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
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: str=%s - AFTER!', $str));
+ foreach (explode('_', $str) as $strPart) {
+ // Make the class name part lower case and first upper case
+ $className .= ucfirst(strtolower($strPart));
+ }
- // 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));
+ // Set cache
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: self[%s]=%s - SET!', $str, $className));
+ self::$cache[$str] = $className;
}
// Return class name
- /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: className=%s - EXIT!', $className));
- return $className;
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: self[%s]=%s - EXIT!', $str, $className));
+ return self::$cache[$str];
}
/**