application/hub/exceptions.php -text
application/hub/exceptions/.htaccess -text
application/hub/exceptions/lists/.htaccess -text
+application/hub/exceptions/lists/class_InvalidListHashException.php -text
application/hub/exceptions/lists/class_ListGroupAlreadyAddedException.php -text
application/hub/exceptions/lists/class_NoListGroupException.php -text
application/hub/init.php -text
db/.htaccess -text
db/news/.htaccess -text
db/node_data/.htaccess -text
+db/node_list/.htaccess -text
docs/COPYING -text
docs/COPYING.documents -text
docs/COPYING.software -text
--- /dev/null
+<?php
+/**
+ * This exception is thrown when a hash is invalid
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class InvalidListHashException extends FrameworkException {
+ /**
+ * The super constructor for all exceptions
+ *
+ * @param $messageArray Error message array
+ * @param $code Error code
+ * @return void
+ */
+ public function __construct (array $messageArray, $code) {
+ // Construct the message
+ $message = sprintf("[%s] Hash <span class=\"exception_reason\">%s</span> with key <span class=\"exception_reason\">%s</span> is invalid.",
+ $messageArray[0]->__toString(),
+ $messageArray[1],
+ $messageArray[2]
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class ShutdownPoolIterator extends BaseIterator implements Iterator {
+ /**
+ * Key for the global list index
+ */
+ private $indexKey = 0;
+
/**
* Protected constructor
*
* Getter for current value from group or generic
*
* @return $current Current value in iteration
+ * @throws IndexOutOfBoundsException If $indexKey is out of bounds
*/
public function current () {
// Default is null
$current = null;
- $this->partialStub('Please implement this method.');
+ // Is the entry valid?
+ if (!$this->valid()) {
+ // Throw an exception here
+ throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
+ } // END - if
+
+ // Now get the entry
+ $current = $this->getListInstance()->getEntry($this->key());
// Return it
return $current;
/**
* Getter for key from group or generic
*
- * @return $key Current key in iteration
+ * @return $indexKey Current key in iteration
*/
public function key () {
- // Default is null
- $key = null;
-
- $this->partialStub('Please implement this method.');
-
- // Return it
- return $key;
+ return $this->indexKey;
}
/**
* @return void
*/
public function next () {
- $this->partialStub('Please implement this method.');
+ $this->indexKey++;
}
/**
* @return void
*/
public function rewind () {
- $this->partialStub('Please implement this method.');
+ $this->indexKey = 0;
}
/**
* Checks wether the current entry is valid (not at the end of the list)
*
- * @return void
+ * @return $isValid Wether the current entry is there
*/
public function valid () {
- $this->partialStub('Please implement this method.');
+ // Check for total active clients and if we are not at the end
+ $isValid = ($this->key() < $this->getListInstance()->count());
+
+ // Return result
+ return $isValid;
}
}
// Visit this listener
$visitorInstance->visitListener($this);
- // Visit the pool
- $this->getPoolInstance()->accept($visitor);
+ // Visit the pool if set
+ if ($this->getPoolInstance() instanceof Poolable) {
+ $this->getPoolInstance()->accept($visitor);
+ } // END - if
// Debug message
$this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class BaseList extends BaseHubSystem implements IteratorAggregate {
+class BaseList extends BaseHubSystem implements IteratorAggregate, Countable {
// Exception constants
const EXCEPTION_GROUP_ALREADY_ADDED = 0xf20;
const EXCEPTION_GROUP_NOT_FOUND = 0xf21;
+ const EXCEPTION_INVALID_HASH = 0xf22;
/**
* List groups array
} elseif ($entry instanceof FrameworkInterface) {
// Own instance detected
$entry2 = $entry->hashCode();
- } elseif (!is_array($entry)) {
- // Non-array found, use it directly with type
- $entry2 = gettype($entry) . ':' . $entry2;
+ } elseif ((is_int($entry)) || (is_float($entry)) || (is_resource($entry))) {
+ // Integer/float/resource detected
+ $entry2 = gettype($entry) . ':' . $entry;
+ } elseif (is_string($entry)) {
+ // String found
+ $entry2 = crc32($entry) . ':' . strlen($entry);
} else {
- // Arrays are unsupported at the momement
- $this->debugOutut(__METHOD__ . ': entry is an array. UNSUPPORTED!');
+ // Unsupported type detected
+ $this->debugOutut(__METHOD__ . ': entry type ' . gettype($entry) . ' is unsupported.');
// @TODO Extend this somehow?
$entry2 = gettype($entry);
// And return it
return $hash;
}
+
+ /**
+ * Counts all entries in this list
+ *
+ * @return $count All entries in this list
+ */
+ public final function count () {
+ return count($this->listIndex);
+ }
+
+ /**
+ * Checks wether the given hash is valid
+ *
+ * @param $hash The hash we should validate
+ * @return $isValid Wether the given hash is valid
+ */
+ public final function isHashValid ($hash) {
+ // Check it
+ $isValid = ((in_array($hash, $this->listIndex)) && (isset($this->listEntries[$hash])));
+
+ // Return the result
+ return $isValid;
+ }
+
+ /**
+ * 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
+ */
+ public function getEntry ($hashIndex) {
+ // Get the hash value
+ $hash = $this->listIndex[$hashIndex];
+
+ // Is the hash valid?
+ if (!$this->isHashValid($hash)) {
+ // Throw an exception here
+ throw new InvalidListHashException(array($this, $hash, $hashIndex), self::EXCEPTION_INVALID_HASH);
+ } // END - if
+
+ // Now copy the entry
+ $entry = $this->listEntries[$hash];
+
+ // Return it
+ return $entry;
+ }
}
//
--- /dev/null
+Deny from all