]> git.mxchange.org Git - core.git/commitdiff
Rewrites
authorRoland Häder <roland@mxchange.org>
Sun, 26 Aug 2012 21:45:10 +0000 (21:45 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 26 Aug 2012 21:45:10 +0000 (21:45 +0000)
- Added method createUuid() which will check if the PECL extension uuid is
  loaded and use that for e.g. more entropy
- RandomNumberGenerator is now singelton (to save memory)
- TODO added

inc/classes/main/commands/web/class_WebResendLinkCommand.php
inc/classes/main/crypto/class_CryptoHelper.php
inc/classes/main/menu/class_BaseMenu.php
inc/classes/main/rng/class_RandomNumberGenerator.php

index 2cd6a82fffc118fe21d17e50d6d7c2d014fdc8e6..3757d4b71a63599aa2b028e4ed000e9e5fc46d92 100644 (file)
@@ -64,6 +64,7 @@ class WebResendLinkCommand extends BaseCommand implements Commandable {
                $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
 
                // Get a RNG instance (Random Number Generator)
+               // @TODO Rewrite this code to make use of generateRandomString() from 'hub' project
                $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
 
                // Generate a pseudo-random string
index aa4ef8878e235e628772b7809e4769fd28819bbb..7fc481d4fee5a89ba5ab4e187af48fe692e2b71c 100644 (file)
@@ -123,7 +123,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
         */
        private function generateSalt () {
                // Get a random string from the RNG
-               $randomString = $this->getRngInstance()->randomString();
+               $randomString = $this->getRngInstance()->randomString() . $this->createUuid();
 
                // Get config entry for salt length
                $length = $this->getConfigInstance()->getConfigEntry('salt_length');
@@ -132,6 +132,26 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
                $this->salt = substr(sha1($randomString), -$length, $length);
        }
 
+       /**
+        * Returns a UUID (Universal Unique IDentifier) if PECL extension uuid was
+        * found or an empty string it not.
+        *
+        * @return      $uuid   UUID with leading dash or empty string
+        */
+       public function createUuid () {
+               // Init empty UUID
+               $uuid = '';
+
+               // Is the UUID extension loaded? (see pecl)
+               if ((extension_loaded('uuid')) && (function_exists('uuid_create'))) {
+                       // Then add it as well
+                       $uuid = uuid_create();
+               } // END - if
+
+               // Return it
+               return $uuid;
+       }
+
        /**
         * Hashes a string with salt and returns the hash. If an old previous hash
         * is supplied the method will use the first X chars of that hash for hashing
index 69672112211647fcb77c454f12bc82e2f81b0952..ffebece3880843c0b44305879c3f97e67f3013e0 100644 (file)
@@ -47,23 +47,23 @@ class BaseMenu extends BaseFrameworkSystem {
                $this->setTemplateInstance($templateInstance);
 
                // Load the menu template for all
-               $this->getTemplateInstance()->loadMenuTemplate('generic_menu_entries');
+               $templateInstance->loadMenuTemplate('generic_menu_entries');
 
                // Get the 'page' from request instance
                $page = $this->getApplicationInstance()->getRequestInstance()->getRequestElement('page');
 
                // Load the menu template for this page
                try {
-                       $this->getTemplateInstance()->loadMenuTemplate($page . '_menu_entries');
+                       $templateInstance->loadMenuTemplate($page . '_menu_entries');
                } catch (FileIoException $e) {
                        // @TODO Should we log it here? We should, because it will be silently ignored.
                }
 
                // Get the prepared content
-               $menuContent = $this->getTemplateInstance()->getRawTemplateData();
+               $menuContent = $templateInstance->getRawTemplateData();
 
                // Render it here
-               $this->getTemplateInstance()->renderXmlContent($menuContent);
+               $templateInstance->renderXmlContent($menuContent);
                //exit(__METHOD__ . ':!OK');
        }
 
index bc8c42d46a097da8fc2efea087b33b6ebd9f191e..6b26fe848510cbd30a320ce818efae737ad85214 100644 (file)
@@ -47,6 +47,11 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
         */
        private $rndStrLen = 0;
 
+       /**
+        * Self instance
+        */
+       private static $selfInstance = NULL;
+
        /**
         * Protected constructor
         *
@@ -65,11 +70,20 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
         * @return      $rngInstance    An instance of this random number generator
         */
        public static final function createRandomNumberGenerator (FrameworkInterface $extraInstance = NULL) {
-               // Get a new instance
-               $rngInstance = new RandomNumberGenerator();
+               // Is self instance set?
+               if (is_null(self::$selfInstance)) {
+                       // Get a new instance
+                       $rngInstance = new RandomNumberGenerator();
 
-               // Initialize the RNG now
-               $rngInstance->initRng($extraInstance);
+                       // Initialize the RNG now
+                       $rngInstance->initRng($extraInstance);
+
+                       // Set it "self"
+                       self::$selfInstance = $rngInstance;
+               } else {
+                       // Use from self instance
+                       $rngInstance = self::$selfInstance;
+               }
 
                // Return the instance
                return $rngInstance;