*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
protected function __construct ($className) {
// Call parent constructor
parent::__construct($className);
-
- // Remove some attributes
- $this->removeNumberFormaters();
- $this->removeSystemArray();
}
/**
*/
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;
// Add the instance itself to the list
$this->listEntries[$hash] = $instance;
- //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - START');
+ //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - FINISHED');
}
/**
// Generate hash
$hash = $this->generateHash($groupName, $groupName, $entry);
- //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): hash='.$hash.'');
+ //* DEBUG: */ $this->debugOutput(__METHOD__ . ': groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
// Add the hash to the index
$this->listIndex[] = $hash;
//* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED');
}
+ /**
+ * Removes given entry from the list group
+ *
+ * @param $groupName Group where we should remove the entry from
+ * @param $entry The entry we should remove
+ * @return void
+ * @throws NoListGroupException If the given group is not found
+ */
+ public function removeEntry ($groupName, $entry) {
+ //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - START');
+ // Is the group already added?
+ if (!$this->isGroupSet($groupName)) {
+ // Throw the exception here
+ throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
+ } // END - if
+
+ // Generate hash
+ $hash = $this->generateHash($groupName, $groupName, $entry);
+ //* DEBUG: */ $this->debugOutput(__METHOD__ . ': groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
+
+ // Remove it from the list ...
+ unset($this->listEntries[$hash]);
+
+ // ... and hash list as well
+ unset($this->listIndex[array_search($hash, $this->listIndex)]);
+ //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED');
+ }
+
/**
* Generates a hash from given group, sub group and entry
*
} 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.');
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)) {
// Return it
return $entry;
}
+
+ /**
+ * Gets a full array from given group name
+ *
+ * @param $groupName The group name to get a list for
+ * @return $entries The array with all entries
+ * @throws NoListGroupException If the specified group is invalid
+ */
+ public function getArrayFromGroup ($groupName) {
+ // Is the group valid?
+ if (!$this->isGroupSet($groupName)) {
+ // Throw the exception here
+ throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
+ } // END - if
+
+ // Init the entries' array
+ $entries = array();
+
+ // Get an iterator
+ $iteratorInstance = $this->listGroups[$groupName]->getIterator();
+
+ // Go through all entries
+ while ($iteratorInstance->valid()) {
+ // Get key
+ $entryIndex = $iteratorInstance->key();
+
+ // ... and the final entry which is the stored instance
+ $entry = $this->getEntry($entryIndex);
+
+ // Add it to the list
+ $entries[$iteratorInstance->current()] = $entry;
+
+ // Skip to next one
+ $iteratorInstance->next();
+ } // END - while
+
+ // Return the list
+ return $entries;
+ }
+
+ /**
+ * 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);
+ } // END - if
+
+ // Set the entry
+ $this->listEntries[$hash] = $entryArray;
+ }
}
//