]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/class_BaseFrameworkSystem.php
Continued:
[core.git] / framework / main / classes / class_BaseFrameworkSystem.php
index 526346cacc65ecae92248aecf79338a3160a0979..31ee5443b198f948a24b2c71043e5f0ed250a9b2 100644 (file)
@@ -4,9 +4,9 @@ namespace Org\Mxchange\CoreFramework\Object;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
-use Org\Mxchange\CoreFramework\Criteria\Criteria;
 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
-use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Filesystem\FileIoException;
 use Org\Mxchange\CoreFramework\Filesystem\PathWriteProtectedException;
 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
@@ -19,7 +19,7 @@ use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
 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\String\StringUtils;
+use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
 
 // Import SPL stuff
 use \stdClass;
@@ -33,7 +33,7 @@ use \SplFileInfo;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -52,14 +52,18 @@ use \SplFileInfo;
  */
 abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        /**
-        * Length of output from hash()
+        * Self-referencing instance
         */
-       private static $hashLength = NULL;
+       private static $selfInstance = NULL;
 
        /**
-        * Self-referencing instance
+        * Stub methods
         */
-       private static $selfInstance = NULL;
+       private static $stubMethods = [
+               'partialStub' => true,
+               '__call' => true,
+               '__callStatic' => true,
+       ];
 
        /**
         * The real class name
@@ -350,7 +354,7 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
         * @throws      UnsupportedOperationException   Objects of this framework cannot be serialized
         */
        public final function __sleep () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException([$this, __FUNCTION__], self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -360,7 +364,7 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
         * @throws      UnsupportedOperationException   Objects of this framework cannot be serialized
         */
        public final function __wakeup () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException([$this, __FUNCTION__], self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -370,7 +374,7 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
         * @throws      UnsupportedOperationException   Objects of this framework cannot be serialized
         */
        public final function __invoke () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException([$this, __FUNCTION__], self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -539,25 +543,6 @@ Loaded includes:
                ));
        }
 
-       /**
-        * Replaces control characters with printable output
-        *
-        * @param       $str    String with control characters
-        * @return      $str    Replaced string
-        */
-       protected function replaceControlCharacters (string $str) {
-               // Replace them
-               $str = str_replace(
-                       chr(13), '[r]', str_replace(
-                       chr(10), '[n]', str_replace(
-                       chr(9) , '[t]',
-                       $str
-               )));
-
-               // Return it
-               return $str;
-       }
-
        /**
         * Output a partial stub message for the caller method
         *
@@ -618,8 +603,11 @@ Loaded includes:
         * @deprecated  Not fully, as the new Logger facilities are not finished yet.
         */
        public final static function createDebugInstance (string $className, int $lineNumber = NULL) {
-               // Is the instance set?
-               if (!GenericRegistry::getRegistry()->instanceExists('debug')) {
+               // Validate parameter
+               if (empty($className)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "className" is empty');
+               } elseif (!GenericRegistry::getRegistry()->instanceExists('debug')) {
                        // Init debug instance
                        $debugInstance = NULL;
 
@@ -629,7 +617,7 @@ Loaded includes:
                                $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
                        } catch (NullPointerException $e) {
                                // Didn't work, no instance there
-                               exit(sprintf('Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, $e->__toString(), $e->getMessage(), $className, $lineNumber));
+                               exit(sprintf('[%s:%d]: Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, __METHOD__, __LINE__, $e->__toString(), $e->getMessage(), $className, $lineNumber));
                        }
 
                        // Empty string should be ignored and used for testing the middleware
@@ -675,7 +663,7 @@ Loaded includes:
                $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
 
                // Is function partialStub/__callStatic ?
-               if (in_array($backtrace[1]['function'], array('partialStub', '__call', '__callStatic'))) {
+               if (isset(self::$stubMethods[$backtrace[1]['function']])) {
                        // Prepend class::function:line from 3rd element
                        $message = sprintf('[%s::%s:%d]: %s',
                                $backtrace[2]['class'],
@@ -968,26 +956,6 @@ Loaded includes:
                return $isBase64;
        }
 
-       /**
-        * Gets a cache key from Criteria instance
-        *
-        * @param       $criteriaInstance       An instance of a Criteria class
-        * @param       $onlyKeys                       Only use these keys for a cache key
-        * @return      $cacheKey                       A cache key suitable for lookup/storage purposes
-        */
-       protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = []) {
-               // Generate it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: criteriaInstance=' . $criteriaInstance->__toString() . ',onlyKeys()=' . count($onlyKeys) . ' - CALLED!');
-               $cacheKey = sprintf('%s@%s',
-                       $this->__toString(),
-                       $criteriaInstance->getCacheKey($onlyKeys)
-               );
-
-               // And return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: cacheKey=' . $cacheKey . ' - EXIT!');
-               return $cacheKey;
-       }
-
        /**
         * Getter for startup time in miliseconds
         *
@@ -1003,48 +971,13 @@ Loaded includes:
         * @return      $executionTime  Current execution time in nice braces
         */
        protected function getPrintableExecutionTime () {
-               // Caculate the execution time
-               $executionTime = microtime(true) - $this->getStartupTime();
-
-               // Pack it in nice braces
-               $executionTime = sprintf('[ %01.5f ] ', $executionTime);
+               // Calculate execution time and pack it in nice braces
+               $executionTime = sprintf('[ %01.5f ] ', (microtime(true) - $this->getStartupTime()));
 
                // And return it
                return $executionTime;
        }
 
-       /**
-        * Hashes a given string with a simple but stronger hash function (no salt)
-        * and hex-encode it.
-        *
-        * @param       $str    The string to be hashed
-        * @return      $hash   The hash from string $str
-        */
-       public static final function hash (string $str) {
-               // Hash given string with (better secure) hasher
-               $hash = bin2hex(mhash(MHASH_SHA256, $str));
-
-               // Return it
-               return $hash;
-       }
-
-       /**
-        * "Getter" for length of hash() output. This will be "cached" to speed up
-        * things.
-        *
-        * @return      $length         Length of hash() output
-        */
-       public static final function getHashLength () {
-               // Is it cashed?
-               if (is_null(self::$hashLength)) {
-                       // No, then hash a string and save its length.
-                       self::$hashLength = strlen(self::hash('abc123'));
-               }
-
-               // Return it
-               return self::$hashLength;
-       }
-
        /**
         * Determines if an element is set in the generic array
         *
@@ -1055,10 +988,8 @@ Loaded includes:
         * @return      $isset          Whether the given key is set
         */
        protected final function isGenericArrayElementSet (string $keyGroup, string $subGroup, $key, $element) {
-               // Debug message
-               //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
-
                // Is it there?
+               //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
                $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
 
                // Return it
@@ -1073,10 +1004,8 @@ Loaded includes:
         * @return      $isset          Whether the given key is set
         */
        protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, $key) {
-               // Debug message
-               //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
-
                // Is it there?
+               //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
                $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
 
                // Return it
@@ -1092,10 +1021,8 @@ Loaded includes:
         * @return      $isset          Whether the given group is set
         */
        protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) {
-               // Debug message
-               //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
-
                // Is it there?
+               //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
                $isset = isset($this->genericArray[$keyGroup][$subGroup]);
 
                // Return it
@@ -1117,10 +1044,8 @@ Loaded includes:
                        exit;
                }
 
-               // Debug message
-               //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
-
                // Return it
+               //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
                return $this->genericArray[$keyGroup][$subGroup];
        }
 
@@ -1133,10 +1058,8 @@ Loaded includes:
         * @return      void
         */
        protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, $key) {
-               // Debug message
-               //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
-
                // Remove it
+               //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
                unset($this->genericArray[$keyGroup][$subGroup][$key]);
        }
 
@@ -1414,7 +1337,7 @@ Loaded includes:
         * @param       $keyGroup       Main group for the key
         * @return      $count          Count of given group
         */
-       protected final function countGenericArray ($keyGroup) {
+       protected final function countGenericArray (string $keyGroup) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
 
@@ -1502,7 +1425,7 @@ Loaded includes:
         * @param       $keyGroup       Key group to get
         * @return      $array          Whole generic array group
         */
-       protected final function getGenericArray ($keyGroup) {
+       protected final function getGenericArray (string $keyGroup) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
 
@@ -1642,11 +1565,8 @@ Loaded includes:
         * @return      void
         */
        protected function initWebOutputInstance () {
-               // Get application instance
-               $applicationInstance = ApplicationHelper::getSelfInstance();
-
                // Init web output instance
-               $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));
+               $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
 
                // Set it locally
                $this->setWebOutputInstance($outputInstance);
@@ -1659,9 +1579,6 @@ Loaded includes:
         * @return      $translated             Translated boolean value
         */
        public static final function translateBooleanToYesNo (bool $boolean) {
-               // Make sure it is really boolean
-               assert(is_bool($boolean));
-
                // "Translate" it
                $translated = ($boolean === true) ? 'Y' : 'N';