rngInstance is now located in BaseFrameworkSystem
authorRoland Häder <roland@mxchange.org>
Fri, 7 Aug 2009 23:14:52 +0000 (23:14 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 7 Aug 2009 23:14:52 +0000 (23:14 +0000)
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/crypto/class_CryptoHelper.php
inc/classes/main/helper/captcha/class_BaseCaptcha.php
inc/classes/main/streams/class_BaseStream.php

index a3edd83..16c04ed 100644 (file)
@@ -73,10 +73,15 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $controllerInstance = null;
 
+       /**
+        * Instance of an RNG
+        */
+       private $rngInstance = null;
+
        /**
         * The real class name
         */
-       private $realClass      = 'FrameworkSystem';
+       private $realClass      = 'BaseFrameworkSystem';
 
        /**
         * Thousands seperator
@@ -1140,6 +1145,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Return result
                return $isLoaded;
        }
+
+       /**
+        * Setter for RNG instance
+        *
+        * @param       $rngInstance    An instance of a random number generator (RNG)
+        * @return      void
+        */
+       protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
+               $this->rngInstance = $rngInstance;
+       }
+
+       /**
+        * Getter for RNG instance
+        *
+        * @return      $rngInstance    An instance of a random number generator (RNG)
+        */
+       public final function getRngInstance () {
+               return $this->rngInstance;
+       }
 }
 
 // [EOF]
index 2335f5d..c135b18 100644 (file)
@@ -105,7 +105,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
                // Do we have mcrypt loaded?
                if ($this->isPhpExtensionLoaded('mcrypt')) {
                        // Then use it
-                       $this->cryptoStreamInstance = ObjectFactory::createObjectByName('McryptStream', array($this->rngInstance()));
+                       $this->cryptoStreamInstance = ObjectFactory::createObjectByName('McryptStream', array($this->getRngInstance()));
                } else {
                        // If nothing works ...
                        $this->cryptoStreamInstance = ObjectFactory::createObjectByName('NullCryptoStream');
@@ -119,7 +119,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
         */
        protected function initHasher () {
                // Initialize the random number generator which is required by some crypto methods
-               $this->rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
+               $this->setRngInstance(ObjectFactory::createObjectByConfiguredName('rng_class'));
 
                // Generate a salt for the hasher
                $this->generateSalt();
@@ -132,7 +132,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
         */
        private function generateSalt () {
                // Get a random string from the RNG
-               $randomString = $this->rngInstance->randomString();
+               $randomString = $this->getRngInstance()->randomString();
 
                // Get config entry for salt length
                $length = $this->getConfigInstance()->getConfigEntry('salt_length');
@@ -171,7 +171,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
                //* DEBUG: */ echo "salt=".$salt."/plain=".$str."<br />\n";
                $hashed = $salt . md5(sprintf($this->getConfigInstance()->getConfigEntry('hash_mask'),
                        $salt,
-                       $this->rngInstance->getFixedSalt(),
+                       $this->getRngInstance()->getFixedSalt(),
                        $str
                ));
 
index 9cef207..e619058 100644 (file)
@@ -27,11 +27,6 @@ class BaseCaptcha extends BaseHelper {
         */
        private $helperInstance = null;
 
-       /**
-        * Instance of an RNG
-        */
-       private $rngInstance = null;
-
        /**
         * Protected constructor
         *
@@ -51,16 +46,7 @@ class BaseCaptcha extends BaseHelper {
         */
        protected final function initializeRandomNumberGenerator (FrameworkInterface $extraInstance = null) {
                // Get an RNG from factory
-               $this->rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class', array($extraInstance));
-       }
-
-       /**
-        * Getter for RNG instance
-        *
-        * @return      $rngInstance    An instance of a random number generator (RNG)
-        */
-       public final function getRngInstance () {
-               return $this->rngInstance;
+               $this->setRngInstance(ObjectFactory::createObjectByConfiguredName('rng_class', array($extraInstance)));
        }
 
        /**
index 728e6c3..e226545 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseStream extends BaseFrameworkSystem {
-       /**
-        * Random number generator instance (RNG)
-        */
-       private $rngInstance = null;
-
        /**
         * Protected constructor
         *
@@ -41,25 +36,6 @@ class BaseStream extends BaseFrameworkSystem {
                $this->removeNumberFormaters();
                $this->removeSystemArray();
        }
-
-       /**
-        * Setter for RNG instance
-        *
-        * @param       $rngInstance    An RNG instance
-        * @return      void
-        */
-       protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
-               $this->rngInstance = $rngInstance;
-       }
-
-       /**
-        * Getter for RNG instance
-        *
-        * @return      $rngInstance    An RNG instance
-        */
-       protected final function getRngInstance () {
-               return $this->rngInstance;
-       }
 }
 
 // [EOF]