]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 24 Aug 2025 09:42:33 +0000 (11:42 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 24 Aug 2025 09:42:33 +0000 (11:42 +0200)
- moved getPrintableState() to own StateUtils class
- renamed method to generatePrintableState()

framework/main/classes/class_BaseFrameworkSystem.php
framework/main/classes/utils/states/class_StateUtils.php [new file with mode: 0644]

index f14443e6e1d1b97ff81da8b6216fa6cca822c26e..c00b40df8d85412c29bcf1f683c576b405554c84 100644 (file)
@@ -18,7 +18,6 @@ use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
 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;
 
@@ -225,7 +224,7 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
        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?
@@ -237,11 +236,8 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
                        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 = '(';
 
@@ -268,12 +264,9 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
 
                                        // 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
@@ -297,9 +290,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
                        $methodName,
                        $argsString
                ));
-
-               // Return nothing
-               return;
        }
 
        /**
@@ -1857,46 +1847,6 @@ Loaded includes:
                // 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;
        }
 
 }
diff --git a/framework/main/classes/utils/states/class_StateUtils.php b/framework/main/classes/utils/states/class_StateUtils.php
new file mode 100644 (file)
index 0000000..97c967f
--- /dev/null
@@ -0,0 +1,82 @@
+<?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;
+       }
+
+}