]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/lists/class_BaseList.php
Exceptions/interfaces/classes added:
[hub.git] / application / hub / main / lists / class_BaseList.php
index 99306aca654d5252e7019735de4a79a59ce426c9..fe416e104c88838004e626fd0070986ac05c9586 100644 (file)
@@ -60,7 +60,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable {
         */
        public function getIterator () {
                // Prepare a default iterator
-               $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class');
+               $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class', array($this));
 
                // And return it
                return $iteratorInstance;
@@ -226,6 +226,9 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable {
                } elseif (is_string($entry)) {
                        // String found
                        $entry2 = crc32($entry) . ':' . strlen($entry);
+               } elseif ((is_array($entry)) && (isset($entry['id']))) {
+                       // Supported array found
+                       $entry2 = crc32($entry['id']) . ':' . count($entry);
                } else {
                        // Unsupported type detected
                        $this->debugOutut(__METHOD__ . ': entry type ' . gettype($entry) . ' is unsupported.');
@@ -267,16 +270,30 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable {
                return $isValid;
        }
 
+       /**
+        * Getter for hash from given hash index
+        *
+        * @param       $hashIndex      Index holding the hash
+        * @return      $hash           The hash
+        */
+       public final function getHash ($hashIndex) {
+               // Get it ...
+               $hash = $this->listIndex[$hashIndex];
+
+               // ... and return it
+               return $hash;
+       }
+
        /**
         * Gets an entry from given hash index
         *
         * @param       $hashIndex      The hash index to resolve the mapped entry
         * @return      $entry          Solved entry from list
-        * @throws      InvalidListHashException If the solved hash index is invalid
+        * @throws      InvalidListHashException        If the solved hash index is invalid
         */
        public function getEntry ($hashIndex) {
                // Get the hash value
-               $hash = $this->listIndex[$hashIndex];
+               $hash = $this->getHash($hashIndex);
 
                // Is the hash valid?
                if (!$this->isHashValid($hash)) {
@@ -290,6 +307,25 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable {
                // Return it
                return $entry;
        }
+
+       /**
+        * Updates the given entry by hash with given array
+        *
+        * @param       $hash           Hash for this entry
+        * @param       $entryArray     Array with entry we should update
+        * @return      void
+        * @throws      InvalidListHashException        If the solved hash index is invalid
+        */
+       public function updateCurrentEntryByHash ($hash, array $entryArray) {
+               // Is the hash valid?
+               if (!$this->isHashValid($hash)) {
+                       // Throw an exception here, hashIndex is unknown at this point
+                       throw new InvalidListHashException(array($this, $hash, -999), self::EXCEPTION_INVALID_HASH);
+               }
+
+               // Set the entry
+               $this->listEntries[$hash] = $entryArray;
+       }
 }
 
 //