]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/class_BaseFrameworkSystem.php
Continued:
[core.git] / framework / main / classes / class_BaseFrameworkSystem.php
index 6280c51517baf79ba8460022e22ec6aa36cb887d..38a45f3de6487ae05416f5e7fbff5ab4508723ec 100644 (file)
@@ -4,13 +4,13 @@ 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\PathWriteProtectedException;
 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
+use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
@@ -18,7 +18,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;
@@ -32,7 +32,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 - 2021 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -50,11 +50,6 @@ use \SplFileInfo;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
-       /**
-        * Length of output from hash()
-        */
-       private static $hashLength = NULL;
-
        /**
         * Self-referencing instance
         */
@@ -497,7 +492,7 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
         * @param       $message        Optional message to show in debug output
         * @return      void
         */
-       public final function debugInstance ($message = '') {
+       public final function debugInstance (string $message = '') {
                // Restore the error handler to avoid trouble with missing array elements or undeclared variables
                restore_error_handler();
 
@@ -544,7 +539,7 @@ Loaded includes:
         * @param       $str    String with control characters
         * @return      $str    Replaced string
         */
-       protected function replaceControlCharacters ($str) {
+       protected function replaceControlCharacters (string $str) {
                // Replace them
                $str = str_replace(
                        chr(13), '[r]', str_replace(
@@ -563,7 +558,7 @@ Loaded includes:
         * @param       $message        An optional message to display
         * @return      void
         */
-       protected function partialStub ($message = '') {
+       protected function partialStub (string $message = '') {
                // Init variable
                $stubMessage = 'Partial stub!';
 
@@ -591,7 +586,7 @@ Loaded includes:
         * @param       $doExit         Whether exit the program (true is default)
         * @return      void
         */
-       public function debugBackTrace ($message = '', $doExit = true) {
+       public function debugBackTrace (string $message = '', bool $doExit = true) {
                // Sorry, there is no other way getting this nice backtrace
                if (!empty($message)) {
                        // Output message
@@ -616,9 +611,12 @@ Loaded includes:
         * @return      $debugInstance  An instance of a debugger class
         * @deprecated  Not fully, as the new Logger facilities are not finished yet.
         */
-       public final static function createDebugInstance ($className, $lineNumber = NULL) {
-               // Is the instance set?
-               if (!GenericRegistry::getRegistry()->instanceExists('debug')) {
+       public final static function createDebugInstance (string $className, int $lineNumber = NULL) {
+               // Validate parameter
+               if (empty($className)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "className" is empty');
+               } elseif (!GenericRegistry::getRegistry()->instanceExists('debug')) {
                        // Init debug instance
                        $debugInstance = NULL;
 
@@ -628,7 +626,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
@@ -651,7 +649,7 @@ Loaded includes:
         * @param       $message        Message to output
         * @return      void
         */
-       public function outputLine ($message) {
+       public function outputLine (string $message) {
                // Simply output it
                print($message . PHP_EOL);
        }
@@ -666,7 +664,7 @@ Loaded includes:
         * @paran       $stripTags      Whether to strip tags (default: false)
         * @return      void
         */
-       public function debugOutput ($message, $doPrint = true, $stripTags = false) {
+       public function debugOutput (string $message, bool $doPrint = true, bool $stripTags = false) {
                // Set debug instance to NULL
                $debugInstance = NULL;
 
@@ -733,7 +731,7 @@ Loaded includes:
         * @param       $phpCode                Unmarked PHP code
         * @return      $markedCode             Marked PHP code
         */
-       public function markupCode ($phpCode) {
+       public function markupCode (string $phpCode) {
                // Init marked code
                $markedCode = '';
 
@@ -831,10 +829,10 @@ Loaded includes:
                        $fieldValue = $fieldArray[$fieldName2];
                } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
                        // Missing field entry, may require debugging
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
                } else {
                        // Missing field entry, may require debugging
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldName=' . $fieldName . ' not found!');
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: fieldName=' . $fieldName . ' not found!');
                }
 
                // Return it
@@ -879,7 +877,7 @@ Loaded includes:
         * @return      void
         * @todo        Write a logging mechanism for productive mode
         */
-       public function deprecationWarning ($message) {
+       public function deprecationWarning (string $message) {
                // Is developer mode active?
                if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
                        // Debug instance is there?
@@ -903,7 +901,7 @@ Loaded includes:
         * @param       $phpExtension   The PHP extension we shall check
         * @return      $isLoaded       Whether the PHP extension is loaded
         */
-       public final function isPhpExtensionLoaded ($phpExtension) {
+       public final function isPhpExtensionLoaded (string $phpExtension) {
                // Is it loaded?
                $isLoaded = in_array($phpExtension, get_loaded_extensions());
 
@@ -930,7 +928,7 @@ Loaded includes:
         *
         * @return      $hasSlept       Whether it goes fine
         */
-       public function idle ($milliSeconds) {
+       public function idle (int $milliSeconds) {
                // Sleep is fine by default
                $hasSlept = true;
 
@@ -959,7 +957,7 @@ Loaded includes:
         * @param       $encodedData    Encoded data we shall check
         * @return      $isBase64               Whether the encoded data is Base64
         */
-       protected function isBase64Encoded ($encodedData) {
+       protected function isBase64Encoded (string $encodedData) {
                // Determine it
                $isBase64 = (@base64_decode($encodedData, true) !== false);
 
@@ -967,26 +965,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
         *
@@ -1002,48 +980,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 ($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
         *
@@ -1054,10 +997,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
@@ -1072,10 +1013,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
@@ -1091,10 +1030,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
@@ -1116,10 +1053,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];
        }
 
@@ -1132,10 +1067,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]);
        }
 
@@ -1641,11 +1574,8 @@ Loaded includes:
         * @return      void
         */
        protected function initWebOutputInstance () {
-               // Get application instance
-               $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
-
                // Init web output instance
-               $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));
+               $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
 
                // Set it locally
                $this->setWebOutputInstance($outputInstance);