use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
-use Org\Mxchange\CoreFramework\State\Stateable;
use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
public static final function __callStatic (string $methodName, array $args = NULL): void {
// Init argument string and class name
//* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
- $argsString = '';
+ $argsString = 'NULLL';
$className = 'unknown';
// Is self-instance set?
throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$selfInstance)), self::EXCEPTION_SELF_INSTANCE);
}
- // Is it NULL, empty or an array?
- if (is_null($args)) {
- // No arguments
- $argsString = 'NULL';
- } elseif (is_array($args)) {
+ // Are arguments being set?
+ if (is_array($args)) {
// Start braces
$argsString = '(';
// Is an other object, maybe no __toString() available
$argsString .= $reflection->getName();
- } elseif ($arg === true) {
- // ... is boolean 'true'
- $argsString .= 'true';
- } elseif ($arg === false) {
- // ... is boolean 'false'
- $argsString .= 'false';
+ } elseif (is_bool($arg)) {
+ // ... is boolean
+ $argsString .= $arg === true ? 'true' : 'false';
}
// Comma for next one
$methodName,
$argsString
));
-
- // Return nothing
- return;
}
/**
// Return it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fileInfoInstance=%s - EXIT!', $fileInfoInstance->__toString()));
return $fileInfoInstance;
- }
-
- /**
- * "Getter" for a printable state name
- *
- * @return $stateName Name of the node's state in a printable format
- * @throws BadMethodCallException If this instance doesn't have a callable getter for stateInstance
- * @deprecated Monolithic method, should be moved to proper classes
- */
- public final function getPrintableState (): string {
- // Check if getter is there
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: CALLED!');
- if (!is_callable($this, 'getStateInstance')) {
- // Throw BMCE
- throw new BadMethodCallException(sprintf('this=%s has no callable getter for stateInstance', $this->__toString()), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
- }
-
- // This method is deprecated
- $this->deprecationWarning('Monolithic method, should be moved to proper classes');
-
- // Default is 'null'
- $stateInstance = NULL;
- $stateName = 'null';
-
- // Check if state instance is there
- if ($this->isStateInstanceSet()) {
- // Get the state instance
- $stateInstance = $this->getStateInstance();
- }
-
- // Is it an instance of Stateable?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: stateInstance[]=%s', gettype($stateInstance)));
- if ($stateInstance instanceof Stateable) {
- // Then use that state name
- $stateName = $stateInstance->getStateName();
- }
-
- // Return result
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: stateName=%s - EXIT!', $stateName));
- return $stateName;
}
}
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Utils\State;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\State\Stateable;
+
+// Import SPL stuff
+use \BadMethodCallException;
+
+/**
+ * An utilities class for states
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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/>.
+ */
+class StateUtils extends BaseFrameworkSystem {
+ /**
+ * Utilities classes don't have instances of themselves somewhere
+ *
+ * @return void
+ */
+ private function __construct () {
+ // No objects of utilities classes
+ }
+
+ /**
+ * Generates a printable (string) name for given instance's state instance
+ *
+ * @param $instance An instance of a FrameworkInterface class
+ * @return $stateName Name of the node's state in a printable format
+ * @throws BadMethodCallException If this instance doesn't have a callable getter for stateInstance
+ */
+ public static final function generatePrintableState (FrameworkInterface $instance): string {
+ // Check if getter is there
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: CALLED!');
+ if (!is_callable($instance, 'getStateInstance')) {
+ // Throw BMCE
+ throw new BadMethodCallException(sprintf('instance=%s has no callable getter for stateInstance', $instance->__toString()), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
+ }
+
+ // Default is 'null'
+ $stateInstance = NULL;
+ $stateName = 'null';
+
+ // Check if state instance is there
+ if ($instance->isStateInstanceSet()) {
+ // Get the state instance
+ $stateInstance = $instance->getStateInstance();
+ }
+
+ // Is it an instance of Stateable?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: stateInstance[]=%s', gettype($stateInstance)));
+ if ($stateInstance instanceof Stateable) {
+ // Then use that state name
+ $stateName = $stateInstance->getStateName();
+ }
+
+ // Return result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: stateName=%s - EXIT!', $stateName));
+ return $stateName;
+ }
+
+}