Nope, this will add hashes to the list ...
[core.git] / framework / main / classes / lists / class_BaseList.php
index 4c32332c9ad4c6a803ab6610375874a1e114aa93..dfe9803a35ac3e71d0febbb378ce0155d8989b86 100644 (file)
@@ -6,6 +6,11 @@ namespace CoreFramework\Lists;
 use CoreFramework\Factory\ObjectFactory;
 use CoreFramework\Generic\FrameworkInterface;
 use CoreFramework\Object\BaseFrameworkSystem;
+use CoreFramework\Visitor\Visitable;
+
+// Import SPL stuff
+use \IteratorAggregate;
+use \Countable;
 
 /**
  * A general list class
@@ -35,6 +40,11 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
        const EXCEPTION_GROUP_NOT_FOUND     = 0xf21;
        const EXCEPTION_INVALID_HASH        = 0xf22;
 
+       /**
+        * Call-back instance
+        */
+       private $callbackInstance = NULL;
+
        /**
         * List groups array
         */
@@ -61,6 +71,16 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
                parent::__construct($className);
        }
 
+       /**
+        * Setter for call-back instance
+        *
+        * @param       $callbackInstance       An instance of a FrameworkInterface class
+        * @return      void
+        */
+       public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
+               $this->callbackInstance = $callbackInstance;
+       }
+
        /**
         * Getter for iterator instance from this list
         *
@@ -143,11 +163,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
                $hash = $this->generateHash($groupName, $subGroup, $visitableInstance);
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName  . ',subGroup=' . $subGroup . ',hash=' . $hash . ' - Calling addEntry() ...');
-
-               // Now add it to the group list and hash it
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',this->listGroups[' . $groupName . ']=' . $this->listGroups[$groupName]->__toString());
-               //$this->listGroups[$groupName]->addEntry($subGroup, $hash);
 
                // Add the hash to the index
                array_push($this->listIndex, $hash);
@@ -194,7 +210,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
                        if ($this->isHashValid($hash)) {
                                // Add it
                                array_push($array, $this->listEntries[$hash]);
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: hash=' . $hash . ',array(' . count($array) . ')=' . print_r($array, TRUE) . ' - ADDED!');
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: hash=' . $hash . ',array(' . count($array) . ')=' . print_r($array, true) . ' - ADDED!');
                        } // END - if
                } // END - foreach
 
@@ -227,7 +243,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
                $hash = $this->generateHash($groupName, $groupName, $entry);
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',entry=' . print_r($entry, TRUE) . ', hash=' . $hash);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',entry=' . print_r($entry, true) . ', hash=' . $hash);
 
                // Add the hash to the index
                array_push($this->listIndex, $hash);
@@ -303,15 +319,15 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
                } elseif ((is_array($entry)) && (isset($entry['id']))) {
                        // Supported array found
                        $entry2 = crc32($entry['id']) . ':' . count($entry);
-               } elseif ((is_array($entry)) && (isset($entry[BasePool::SOCKET_ARRAY_RESOURCE])) && (isset($entry[BasePool::SOCKET_ARRAY_CONN_TYPE]))) {
-                       // Is a socket resource array
-                       $entry2 = crc32($entry[BasePool::SOCKET_ARRAY_RESOURCE] . ':' . $entry[BasePool::SOCKET_ARRAY_CONN_TYPE]);
+               } elseif (($this->callbackInstance instanceof FrameworkInterface) && (method_exists($this->callbackInstance, 'generateListHashFromEntry'))) {
+                       // Call it instead
+                       $entry2 = $this->callbackInstance->generateListHashFromEntry($entry);
                } else {
                        // Unsupported type detected
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST[' . __METHOD__ . ':' . __LINE__ . ']: Entry type ' . gettype($entry) . ' is unsupported.');
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST[' . __METHOD__ . ':' . __LINE__ . ']: Entry type ' . gettype($entry) . ' is unsupported (this->callbackInstance=' . $this->callbackInstance . ').');
 
-                       // @TODO Extend this somehow?
-                       $entry2 = gettype($entry);
+                       // At least take all keys from array
+                       $entry2 = gettype($entry) . ':' . implode(':', array_keys($entry));
                }
 
                // Construct string which we shall hash