]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/rng/class_RandomNumberGenerator.php
Continued:
[core.git] / framework / main / classes / rng / class_RandomNumberGenerator.php
index 515d78810d6ca85f29f1e57bcea61ed4fd6beaf3..91c40bb6968a2375ac00baac7d94b6027e9dc121 100644 (file)
@@ -1,17 +1,18 @@
 <?php
 // Own namespace
-namespace CoreFramework\Crypto\RandomNumber;
+namespace Org\Mxchange\CoreFramework\Crypto\RandomNumber;
 
 // Import framework stuff
-use CoreFramework\Object\BaseFrameworkSystem;
-use CoreFramework\Generic\FrameworkInterface;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 
 /**
  * A standard random number generator
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 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
  *
@@ -65,9 +66,9 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
         * @param       $className      Name of this class
         * @return      void
         */
-       protected function __construct ($className = __CLASS__) {
+       private function __construct () {
                // Call parent constructor
-               parent::__construct($className);
+               parent::__construct(__CLASS__);
        }
 
        /**
@@ -105,23 +106,23 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
         */
        protected function initRng ($extraInstance) {
                // Get the prime number from config
-               $this->prime = $this->getConfigInstance()->getConfigEntry('math_prime');
+               $this->prime = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('math_prime');
 
                // Calculate the extra number which is always the same unless you give
                // a better prime number
                $this->extraNumber = ($this->prime * $this->prime / pow(pi(), 2));
 
                // Seed mt_rand()
-               mt_srand((double) sqrt(microtime(TRUE) * 100000000 * $this->extraNumber));
+               mt_srand((double) sqrt(microtime(true) * 100000000 * $this->extraNumber));
 
                // Set the server IP to cluster
                $serverIp = 'cluster';
 
                // Do we have a single server?
-               if ($this->getConfigInstance()->getConfigEntry('is_single_server') == 'Y') {
+               if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('is_single_server') == 'Y') {
                        // Then use that IP for extra security
-                       $serverIp = $this->getConfigInstance()->detectServerAddress();
-               } // END - if
+                       $serverIp = FrameworkBootstrap::detectServerAddress();
+               }
 
                // Yet-another fixed salt. This is not dependend on server software or date
                if ($extraInstance instanceof FrameworkInterface) {
@@ -129,23 +130,23 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
                        $this->fixedSalt = sha1(
                                $serverIp . ':' .
                                $extraInstance->__toString() . ':' .
-                               json_encode($this->getDatabaseInstance()->getConnectionData())
+                               json_encode(FrameworkBootstrap::getDatabaseInstance()->getConnectionData())
                        );
                } else {
                        // Without extra information
-                       $this->fixedSalt = sha1($serverIp . ':' . json_encode($this->getDatabaseInstance()->getConnectionData()));
+                       $this->fixedSalt = sha1($serverIp . ':' . json_encode(FrameworkBootstrap::getDatabaseInstance()->getConnectionData()));
                }
 
                // One-way data we need for "extra-salting" the random number
                $this->extraSalt = sha1(
                        $this->fixedSalt . ':' .
                        getenv('SERVER_SOFTWARE') . ':' .
-                       $this->getConfigInstance()->getConfigEntry('date_key') . ':' .
-                       $this->getConfigInstance()->getConfigEntry('base_url')
+                       FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('date_key') . ':' .
+                       FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('base_url')
                );
 
                // Get config entry for max salt length
-               $this->rndStrLen = $this->getConfigInstance()->getConfigEntry('rnd_str_length');
+               $this->rndStrLen = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('rnd_str_length');
        }
 
        /**
@@ -158,7 +159,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
                // Is the number <1, then fix it to default length
                if ($length < 1) {
                        $length = $this->rndStrLen;
-               } // END - if
+               }
 
                // Initialize the string
                $randomString = '';
@@ -167,7 +168,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
                for ($idx = 0; $idx < $length; $idx++) {
                        // Add a random character and add it to our string
                        $randomString .= chr($this->randomNumber(0, 255));
-               } // END - for
+               }
 
                // Return the random string a little mixed up
                return str_shuffle($randomString);
@@ -213,9 +214,9 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
                $key = md5($this->getExtraSalt());
 
                // Get key
-               if ($this->getConfigInstance()->getConfigEntry('crypt_fixed_salt') == 'Y') {
+               if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('crypt_fixed_salt') == 'Y') {
                        $key = md5($this->getFixedSalt());
-               } // END - if
+               }
 
                // Return it
                return $key;