]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/database/result/class_CachedDatabaseResult.php
Continued:
[core.git] / framework / main / classes / database / result / class_CachedDatabaseResult.php
index 9c2586c974c5c222937514244de8a2b67e320b0f..12593ac5a8436a684e768b2a6fc50ce56c0e041c 100644 (file)
@@ -1,18 +1,18 @@
 <?php
 // Own namespace
 <?php
 // Own namespace
-namespace CoreFramework\Result\Database;
+namespace Org\Mxchange\CoreFramework\Result\Database;
 
 // Import framework stuff
 
 // Import framework stuff
-use CoreFramework\Criteria\Local\LocalSearchCriteria;
-use CoreFramework\Criteria\Local\LocalUpdateCriteria;
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Database\Backend\BaseDatabaseBackend;
-use CoreFramework\Request\Requestable;
-use CoreFramework\Result\Search\SearchableResult;
-use CoreFramework\Result\Update\UpdateableResult;
-use CoreFramework\Wrapper\Database\DatabaseWrapper;
+use Org\Mxchange\CoreFramework\Criteria\Local\LocalSearchCriteria;
+use Org\Mxchange\CoreFramework\Criteria\Local\LocalUpdateCriteria;
+use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
+use Org\Mxchange\CoreFramework\Database\Frontend\DatabaseWrapper;
+use Org\Mxchange\CoreFramework\Database\Backend\BaseDatabaseBackend;
+use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
+use Org\Mxchange\CoreFramework\Result\Update\UpdateableResult;
 
 // Import SPL stuff
 
 // Import SPL stuff
+use \InvalidArgumentException;
 use \SeekableIterator;
 
 /**
 use \SeekableIterator;
 
 /**
@@ -55,12 +55,12 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
        /**
         * Result array
         */
        /**
         * Result array
         */
-       private $resultArray = array();
+       private $resultArray = [];
 
        /**
         * Array of out-dated entries
         */
 
        /**
         * Array of out-dated entries
         */
-       private $outDated = array();
+       private $outDated = [];
 
        /**
         * Affected rows
 
        /**
         * Affected rows
@@ -87,8 +87,18 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
         *
         * @param       $resultArray            The array holding the result from query
         * @return      $resultInstance         An instance of this class
         *
         * @param       $resultArray            The array holding the result from query
         * @return      $resultInstance         An instance of this class
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
        public static final function createCachedDatabaseResult (array $resultArray) {
         */
        public static final function createCachedDatabaseResult (array $resultArray) {
+               // Misses an element?
+               if (count($resultArray) == 0) {
+                       // Cannot be empty
+                       throw new InvalidArgumentException('Array "resultArray" cannot be empty.');
+               } elseif (!array_key_exists(BaseDatabaseBackend::RESULT_INDEX_ROWS, $resultArray)) {
+                       // Yes, then abort here
+                       throw new InvalidArgumentException(sprintf('resultArray(%d)=%s has no element "%s".', count($resultArray), print_r($resultArray, TRUE), BaseDatabaseBackend::RESULT_INDEX_ROWS));
+               }
+
                // Get a new instance
                $resultInstance = new CachedDatabaseResult();
 
                // Get a new instance
                $resultInstance = new CachedDatabaseResult();
 
@@ -140,14 +150,14 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
         */
        public function next () {
                // Default is not valid
         */
        public function next () {
                // Default is not valid
-               $nextValid = FALSE;
+               $nextValid = false;
 
                // Is the result valid?
                if ($this->valid()) {
                        // Next entry found, so count one up and cache it
                        $this->currentPos++;
                        $this->currentRow = $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos];
 
                // Is the result valid?
                if ($this->valid()) {
                        // Next entry found, so count one up and cache it
                        $this->currentPos++;
                        $this->currentRow = $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos];
-                       $nextValid = TRUE;
+                       $nextValid = true;
                } // END - if
 
                // Return the result
                } // END - if
 
                // Return the result
@@ -197,7 +207,7 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
         */
        public function valid () {
                // By default nothing is valid
         */
        public function valid () {
                // By default nothing is valid
-               $isValid = FALSE;
+               $isValid = false;
 
                // Debug message
                //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] this->currentPos=' . $this->currentPos);
 
                // Debug message
                //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] this->currentPos=' . $this->currentPos);
@@ -205,7 +215,7 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
                // Check if all is fine ...
                if (($this->ifStatusIsOkay()) && (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][($this->currentPos + 1)])) && (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][0]))) {
                        // All fine!
                // Check if all is fine ...
                if (($this->ifStatusIsOkay()) && (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][($this->currentPos + 1)])) && (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][0]))) {
                        // All fine!
-                       $isValid = TRUE;
+                       $isValid = true;
                } // END - if
 
                // Return the result
                } // END - if
 
                // Return the result
@@ -249,7 +259,7 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
         */
        public function rewind () {
                $this->currentPos = -1;
         */
        public function rewind () {
                $this->currentPos = -1;
-               $this->currentRow = array();
+               $this->currentRow = [];
        }
 
        /**
        }
 
        /**
@@ -350,10 +360,9 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
         * Adds registration elements to a given dataset instance
         *
         * @param       $criteriaInstance       An instance of a StoreableCriteria class
         * Adds registration elements to a given dataset instance
         *
         * @param       $criteriaInstance       An instance of a StoreableCriteria class
-        * @param       $requestInstance        An instance of a Requestable class
         * @return      void
         */
         * @return      void
         */
-       public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
+       public function addElementsToDataSet (StoreableCriteria $criteriaInstance) {
                // Walk only through out-dated columns
                foreach ($this->outDated as $key => $dummy) {
                        // Does this key exist?
                // Walk only through out-dated columns
                foreach ($this->outDated as $key => $dummy) {
                        // Does this key exist?
@@ -373,7 +382,7 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
         */
        public function find ($key) {
                // By default nothing is found
         */
        public function find ($key) {
                // By default nothing is found
-               $found = FALSE;
+               $found = false;
 
                // Rewind the pointer
                $this->rewind();
 
                // Rewind the pointer
                $this->rewind();
@@ -389,7 +398,7 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
                        // Is the element there?
                        if (isset($currentEntry[$key])) {
                                // Okay, found!
                        // Is the element there?
                        if (isset($currentEntry[$key])) {
                                // Okay, found!
-                               $found = TRUE;
+                               $found = true;
 
                                // So "cache" it
                                $this->foundValue = $currentEntry[$key];
 
                                // So "cache" it
                                $this->foundValue = $currentEntry[$key];