added call-back instance support
authorRoland Häder <roland@mxchange.org>
Tue, 30 May 2017 13:03:48 +0000 (15:03 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 30 May 2017 13:03:48 +0000 (15:03 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/lists/class_BaseList.php

index df6e7c0..5111b8d 100644 (file)
@@ -41,6 +41,11 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
        const EXCEPTION_INVALID_HASH        = 0xf22;
 
        /**
+        * Call-back instance
+        */
+       private $callbackInstance = NULL;
+
+       /**
         * List groups array
         */
        private $listGroups = array();
@@ -67,6 +72,16 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
        }
 
        /**
+        * 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
         *
         * @return      $iteratorInstance       An instance of a Iterator class
@@ -308,6 +323,9 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
                } elseif ((is_array($entry)) && (isset($entry['id']))) {
                        // Supported array found
                        $entry2 = crc32($entry['id']) . ':' . count($entry);
+               } elseif (($this->callbackInstance instanceof FrameworkInterface) && (is_callable(array($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.');