]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/class_BaseFrameworkSystem.php
Continued:
[core.git] / framework / main / classes / class_BaseFrameworkSystem.php
index 43146fc0ed40eb52a157c56e72bc6ff0986d2731..e9ce996fe89890f8dea7bb437113e5d2ab07fc8f 100644 (file)
@@ -6,11 +6,12 @@ namespace Org\Mxchange\CoreFramework\Object;
 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;
@@ -481,7 +482,7 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
         * @param       $str    A string (maybe) without trailing slash
         * @return      $str    A string with an auto-appended trailing slash
         */
-       public final function addMissingTrailingSlash ($str) {
+       public final function addMissingTrailingSlash (string $str) {
                // Is there a trailing slash?
                if (substr($str, -1, 1) != '/') {
                        $str .= '/';
@@ -497,7 +498,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 +545,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 +564,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 +592,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,7 +617,7 @@ 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) {
+       public final static function createDebugInstance (string $className, int $lineNumber = NULL) {
                // Is the instance set?
                if (!GenericRegistry::getRegistry()->instanceExists('debug')) {
                        // Init debug instance
@@ -628,7 +629,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 +652,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 +667,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 +734,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 = '';
 
@@ -829,12 +830,12 @@ Loaded includes:
                if ($this->isFieldSet($fieldName)) {
                        // Get it
                        $fieldValue = $fieldArray[$fieldName2];
-               } elseif (defined('DEVELOPER')) {
+               } 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,9 +880,9 @@ 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 (defined('DEVELOPER')) {
+               if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
                        // Debug instance is there?
                        if (!is_null($this->getDebugInstance())) {
                                // Output stub message
@@ -903,7 +904,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 +931,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 +960,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);
 
@@ -1002,11 +1003,8 @@ 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;
@@ -1019,7 +1017,7 @@ Loaded includes:
         * @param       $str    The string to be hashed
         * @return      $hash   The hash from string $str
         */
-       public static final function hash ($str) {
+       public static final function hash (string $str) {
                // Hash given string with (better secure) hasher
                $hash = bin2hex(mhash(MHASH_SHA256, $str));
 
@@ -1053,7 +1051,7 @@ Loaded includes:
         * @param       $element        Element to check
         * @return      $isset          Whether the given key is set
         */
-       protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
+       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);
 
@@ -1071,7 +1069,7 @@ Loaded includes:
         * @param       $key            Key to check
         * @return      $isset          Whether the given key is set
         */
-       protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
+       protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, $key) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
 
@@ -1090,7 +1088,7 @@ Loaded includes:
         * @param       $subGroup       Sub group
         * @return      $isset          Whether the given group is set
         */
-       protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
+       protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
 
@@ -1108,7 +1106,7 @@ Loaded includes:
         * @param       $subGroup       Sub key group
         * @return      $array          An array with all array elements
         */
-       protected final function getGenericSubArray ($keyGroup, $subGroup) {
+       protected final function getGenericSubArray (string $keyGroup, string $subGroup) {
                // Is it there?
                if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
                        // No, then abort here
@@ -1131,7 +1129,7 @@ Loaded includes:
         * @param       $key            Key to unset
         * @return      void
         */
-       protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
+       protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, $key) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
 
@@ -1148,7 +1146,7 @@ Loaded includes:
         * @param       $element        Element to unset
         * @return      void
         */
-       protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
+       protected final function unsetGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
 
@@ -1165,7 +1163,7 @@ Loaded includes:
         * @param       $value          Value to add/append
         * @return      void
         */
-       protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
+       protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, $key, string $value, $appendGlue = '') {
                // Debug message
                //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true) . ',appendGlue=' . $appendGlue);
 
@@ -1189,7 +1187,7 @@ Loaded includes:
         * @param       $value          Value to add/append
         * @return      void
         */
-       protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
+       protected final function appendStringToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
                // Debug message
                //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true) . ',appendGlue=' . $appendGlue);
 
@@ -1213,7 +1211,7 @@ Loaded includes:
         * @param       $value          Value to add/append
         * @return      void
         */
-       protected final function setStringGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
+       protected final function setStringGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
                // Debug message
                //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true) . ',appendGlue=' . $appendGlue);
 
@@ -1230,7 +1228,7 @@ Loaded includes:
         * @param       $forceInit      Optionally force initialization
         * @return      void
         */
-       protected final function initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = false) {
+       protected final function initGenericArrayGroup (string $keyGroup, string $subGroup, bool $forceInit = false) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
 
@@ -1254,7 +1252,7 @@ Loaded includes:
         * @param       $forceInit      Optionally force initialization
         * @return      void
         */
-       protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = false) {
+       protected final function initGenericArrayKey (string $keyGroup, string $subGroup, $key, bool $forceInit = false) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
 
@@ -1279,7 +1277,7 @@ Loaded includes:
         * @param       $forceInit      Optionally force initialization
         * @return      void
         */
-       protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = false) {
+       protected final function initGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, bool $forceInit = false) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
 
@@ -1303,7 +1301,7 @@ Loaded includes:
         * @param       $value          Value to add/append
         * @return      $count          Number of array elements
         */
-       protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
+       protected final function pushValueToGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
                // Debug message
                //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
 
@@ -1332,7 +1330,7 @@ Loaded includes:
         * @param       $value          Value to add/append
         * @return      $count          Number of array elements
         */
-       protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
+       protected final function pushValueToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
                // Debug message
                //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true));
 
@@ -1359,7 +1357,7 @@ Loaded includes:
         * @param       $key            Key to unset
         * @return      $value          Last "popped" value
         */
-       protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
+       protected final function popGenericArrayElement (string $keyGroup, string $subGroup, $key) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
 
@@ -1387,7 +1385,7 @@ Loaded includes:
         * @param       $key            Key to unset
         * @return      $value          Last "popped" value
         */
-       protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
+       protected final function shiftGenericArrayElement (string $keyGroup, string $subGroup, $key) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
 
@@ -1441,7 +1439,7 @@ Loaded includes:
         * @param       $subGroup       Sub group for the key
         * @return      $count          Count of given group
         */
-       protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
+       protected final function countGenericArrayGroup (string $keyGroup, string $subGroup) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
 
@@ -1470,7 +1468,7 @@ Loaded includes:
         * @para        $key            Key to count
         * @return      $count          Count of given key
         */
-       protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
+       protected final function countGenericArrayElements (string $keyGroup, string $subGroup, $key) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
 
@@ -1525,7 +1523,7 @@ Loaded includes:
         * @param       $value          Mixed value from generic array element
         * @return      void
         */
-       protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
+       protected final function setGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
                // Debug message
                //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
 
@@ -1541,7 +1539,7 @@ Loaded includes:
         * @param       $key            Key to unset
         * @return      $value          Mixed value from generic array element
         */
-       protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
+       protected final function getGenericArrayKey (string $keyGroup, string $subGroup, $key) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
 
@@ -1566,7 +1564,7 @@ Loaded includes:
         * @param       $value          Value to set
         * @return      void
         */
-       protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
+       protected final function setGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
                // Debug message
                //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true));
 
@@ -1583,7 +1581,7 @@ Loaded includes:
         * @param       $element        Element to look for
         * @return      $value          Mixed value from generic array element
         */
-       protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
+       protected final function getGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
 
@@ -1605,7 +1603,7 @@ Loaded includes:
         * @param       $subGroup       Sub group for the key
         * @return      $isValid        Whether given sub group is valid
         */
-       protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
+       protected final function isValidGenericArrayGroup (string $keyGroup, string $subGroup) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
 
@@ -1624,7 +1622,7 @@ Loaded includes:
         * @param       $key            Key to check
         * @return      $isValid        Whether given sub group is valid
         */
-       protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
+       protected final function isValidGenericArrayKey (string $keyGroup, string $subGroup, $key) {
                // Debug message
                //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
 
@@ -1642,7 +1640,7 @@ Loaded includes:
         */
        protected function initWebOutputInstance () {
                // Get application instance
-               $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
+               $applicationInstance = ApplicationHelper::getSelfInstance();
 
                // Init web output instance
                $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));