]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 6 Mar 2018 21:49:02 +0000 (22:49 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 6 Mar 2018 21:49:02 +0000 (22:49 +0100)
- $databaseInstance is now moved to FrameworkBootstrap as the old getter/setter
  were using registry pattern, then a getter invocation to check if the
  instance has already been set will result to an NPE as getInstance() makes
  this sure

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/bootstrap/class_FrameworkBootstrap.php
framework/main/classes/database/class_BaseDatabaseWrapper.php
framework/main/classes/database/frontend/class_UserDatabaseWrapper.php
framework/main/classes/database/frontend/class_UserPointsDatabaseWrapper.php
framework/main/classes/rng/class_RandomNumberGenerator.php

index cb8aaffde3a6b2eb0e4cd97058eb93becc9f8752..26c419daf0dc42f1a124627a896c3e919e968338 100644 (file)
@@ -68,6 +68,11 @@ final class FrameworkBootstrap {
         */
        private static $configurationInstance = NULL;
 
+       /**
+        * Database instance
+        */
+       private static $databaseInstance = NULL;
+
        /*
         * Includes applications may have. They will be tried in the given order,
         * some will become soon deprecated.
@@ -117,24 +122,6 @@ final class FrameworkBootstrap {
                return self::$configurationInstance;
        }
 
-       /**
-        * Getter for request instance
-        *
-        * @return      $requestInstance        An instance of a Requestable class
-        */
-       public static function getRequestInstance () {
-               return self::$requestInstance;
-       }
-
-       /**
-        * Getter for response instance
-        *
-        * @return      $responseInstance       An instance of a Responseable class
-        */
-       public static function getResponseInstance () {
-               return self::$responseInstance;
-       }
-
        /**
         * "Getter" to get response/request type from analysis of the system.
         *
@@ -398,7 +385,7 @@ final class FrameworkBootstrap {
                $applicationInstance = ApplicationHelper::getSelfInstance();
 
                // Is the database instance already set?
-               if ($applicationInstance->getDatabaseInstance() instanceof DatabaseConnector) {
+               if (self::getDatabaseInstance() instanceof DatabaseConnector) {
                        // Yes, then abort here
                        throw new BadMethodCallException('Method called twice.');
                } // END - if
@@ -410,7 +397,7 @@ final class FrameworkBootstrap {
                $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getSelfInstance(), $databaseInstance);
 
                // Set it in application helper
-               $applicationInstance->setDatabaseInstance($connectionInstance);
+               self::setDatabaseInstance($connectionInstance);
        }
 
        /**
@@ -656,6 +643,25 @@ final class FrameworkBootstrap {
                self::getConfigurationInstance()->setConfigEntry('detected_full_app_path', $applicationPath);
                self::getConfigurationInstance()->setConfigEntry('detected_app_name'     , $application);
        }
+
+       /**
+        * Getter for request instance
+        *
+        * @return      $requestInstance        An instance of a Requestable class
+        */
+       public static function getRequestInstance () {
+               return self::$requestInstance;
+       }
+
+       /**
+        * Getter for response instance
+        *
+        * @return      $responseInstance       An instance of a Responseable class
+        */
+       public static function getResponseInstance () {
+               return self::$responseInstance;
+       }
+
        /**
         * Setter for request instance
         *
@@ -676,4 +682,24 @@ final class FrameworkBootstrap {
                self::$responseInstance = $responseInstance;
        }
 
+       /**
+        * Setter for database instance
+        *
+        * @param       $databaseInstance       An instance of a DatabaseConnection class
+        * @return      void
+        */
+       public static function setDatabaseInstance (DatabaseConnection $databaseInstance) {
+               self::$databaseInstance = $databaseInstance;
+       }
+
+       /**
+        * Getter for database instance
+        *
+        * @return      $databaseInstance       An instance of a DatabaseConnection class
+        */
+       public static function getDatabaseInstance () {
+               // Return instance
+               return self::$databaseInstance;
+       }
+
 }
index d8b47b5825101ec018b7320db9368baa1f396653..4456a0d1f11405e182e50855742fa2a2d2f28076 100644 (file)
@@ -3,6 +3,7 @@
 namespace Org\Mxchange\CoreFramework\Database\Frontend;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Criteria\Criteria;
 use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
 use Org\Mxchange\CoreFramework\Database\Backend\BaseDatabaseBackend;
@@ -112,7 +113,7 @@ abstract class BaseDatabaseWrapper extends BaseFrameworkSystem {
                } // END - if
 
                // Handle it over to the middleware
-               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
+               FrameworkBootstrap::getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
        }
 
        /**
@@ -140,7 +141,7 @@ abstract class BaseDatabaseWrapper extends BaseFrameworkSystem {
                } // END - if
 
                // Handle it over to the middleware
-               $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
+               FrameworkBootstrap::getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
        }
 
        /**
@@ -149,7 +150,7 @@ abstract class BaseDatabaseWrapper extends BaseFrameworkSystem {
         * @return      $indexKey       Index key
         */
        public final function getIndexKey () {
-               return $this->getDatabaseInstance()->getIndexKey();
+               return FrameworkBootstrap::getDatabaseInstance()->getIndexKey();
        }
 
        /**
@@ -158,7 +159,7 @@ abstract class BaseDatabaseWrapper extends BaseFrameworkSystem {
         * @return      $lastException  Last exception or NULL if none occured
         */
        public final function getLastException () {
-               return $this->getDatabaseInstance()->getLastException();
+               return FrameworkBootstrap::getDatabaseInstance()->getLastException();
        }
 
        /**
@@ -191,7 +192,7 @@ abstract class BaseDatabaseWrapper extends BaseFrameworkSystem {
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-WRAPPER: Quering database, cacheKey=' . $cacheKey);
 
                        // Now it's time to ask the database layer for this select statement
-                       $result = $this->getDatabaseInstance()->doSelectByTableCriteria($this->getTableName(), $criteriaInstance);
+                       $result = FrameworkBootstrap::getDatabaseInstance()->doSelectByTableCriteria($this->getTableName(), $criteriaInstance);
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-WRAPPER: result[]=' . gettype($result));
 
                        // Cache the result if not null
@@ -205,7 +206,7 @@ abstract class BaseDatabaseWrapper extends BaseFrameworkSystem {
                                // This invalid result must be wrapped
                                $result = array(
                                        BaseDatabaseBackend::RESULT_INDEX_STATUS    => 'invalid',
-                                       BaseDatabaseBackend::RESULT_INDEX_EXCEPTION => $this->getDatabaseInstance()->getLastException()
+                                       BaseDatabaseBackend::RESULT_INDEX_EXCEPTION => FrameworkBootstrap::getDatabaseInstance()->getLastException()
                                );
                        }
                }
@@ -252,7 +253,7 @@ abstract class BaseDatabaseWrapper extends BaseFrameworkSystem {
         */
        public final function getPrimaryKeyValue () {
                // Get the table name and a database instance and ask for it
-               $primaryKey = $this->getDatabaseInstance()->getPrimaryKeyOfTable($this->getTableName());
+               $primaryKey = FrameworkBootstrap::getDatabaseInstance()->getPrimaryKeyOfTable($this->getTableName());
 
                // Return value
                return $primaryKey;
@@ -265,7 +266,7 @@ abstract class BaseDatabaseWrapper extends BaseFrameworkSystem {
         */
        public final function countTotalRows () {
                // Get the table name and a database instance and ask for it
-               $count = $this->getDatabaseInstance()->countTotalRows($this->getTableName());
+               $count = FrameworkBootstrap::getDatabaseInstance()->countTotalRows($this->getTableName());
 
                // Return value
                return $count;
@@ -279,7 +280,7 @@ abstract class BaseDatabaseWrapper extends BaseFrameworkSystem {
         */
        public function removeNonPublicDataFromArray (array $data) {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('WRAPPER[' . $this->__toString() . ']: Calling this->getDatabaseInstance()->removeNonPublicDataFromArray(data) ...');
-               $data = $this->getDatabaseInstance()->removeNonPublicDataFromArray($data);
+               $data = FrameworkBootstrap::getDatabaseInstance()->removeNonPublicDataFromArray($data);
 
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('WRAPPER[' . $this->__toString() . ']: data[]=' . gettype($data));
                return $data;
index 9ed16737a210e71fd2b7f2d5ea2f4f20ce1a0e9c..2ef483224dd19d2960cbfaa8ca6a758264ab4267 100644 (file)
@@ -3,6 +3,7 @@
 namespace Org\Mxchange\CoreFramework\Database\Frontend\User;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Database\Frontend\BaseDatabaseWrapper;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
@@ -138,7 +139,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper implements ManageableAccou
                $resultInstance->addElementsToDataSet($dataSetInstance);
 
                // "Update" this request with the database
-               $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
+               FrameworkBootstrap::getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
        }
 
 }
index d9242d8aa8b60e547b6da819533a2191726fc8ee..8a19464ebfe08ff0d55e220b6c7a1a11d082e364 100644 (file)
@@ -3,6 +3,7 @@
 namespace Org\Mxchange\CoreFramework\Database\Frontend\Points;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Database\Frontend\BaseDatabaseWrapper;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
@@ -112,7 +113,7 @@ class UserPointsDatabaseWrapper extends BaseDatabaseWrapper implements BookableP
                $dataSetInstance->setUniqueKey(self::DB_COLUMN_POINTS_UID);
 
                // "Update" this request with the database
-               $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
+               FrameworkBootstrap::getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
        }
 
 }
index e1a34ea8849b63cf2914f0dec618aea6c15284ca..25c4c2c99e81f39ebe5818fa7a583ae0c15bd79a 100644 (file)
@@ -130,11 +130,11 @@ 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