X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Flists%2Fclass_BaseList.php;h=08d60de88167a0d48da4e269b983e8dc52424830;hb=498e6b065ce47804bff4e1073592a2cc8e28f8ef;hp=8d79d1d6c3c70090be933403c05444383e04cfb4;hpb=146c8b3c929a1b0ab17d6605e5ae949ac44899c1;p=core.git diff --git a/framework/main/classes/lists/class_BaseList.php b/framework/main/classes/lists/class_BaseList.php index 8d79d1d6..08d60de8 100644 --- a/framework/main/classes/lists/class_BaseList.php +++ b/framework/main/classes/lists/class_BaseList.php @@ -1,12 +1,12 @@ * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * @@ -34,7 +34,7 @@ use \Countable; * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countable { +abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countable { // Exception constants const EXCEPTION_GROUP_ALREADY_ADDED = 0xf20; const EXCEPTION_GROUP_NOT_FOUND = 0xf21; @@ -43,17 +43,17 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab /** * List groups array */ - private $listGroups = array(); + private $listGroups = []; /** * List entries array */ - private $listEntries = array(); + private $listEntries = []; /** * List index array */ - private $listIndex = array(); + private $listIndex = []; /** * Protected constructor @@ -61,7 +61,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab * @param $className Name of the class * @return void */ - protected function __construct ($className) { + protected function __construct (string $className) { // Call parent constructor parent::__construct($className); } @@ -95,7 +95,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab * @return $isset Whether the group is valid */ public function isGroupSet ($groupName) { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName); return isset($this->listGroups[$groupName]); } @@ -107,7 +107,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab * @throws ListGroupAlreadyAddedException If the given group is already added */ public function addGroup ($groupName) { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!'); // Is the group already added? if ($this->isGroupSet($groupName)) { // Throw the exception here @@ -116,7 +116,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab // Add the group which is a simple array $this->listGroups[$groupName] = ObjectFactory::createObjectByConfiguredName('list_group_class'); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - EXIT!'); } /** @@ -130,7 +130,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab */ public function addInstance ($groupName, $subGroup, Visitable $visitableInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',subGroup=' . $subGroup . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ',subGroup=' . $subGroup . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!'); // Is the group there? if (!$this->isGroupSet($groupName)) { @@ -148,11 +148,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); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',this->listGroups[' . $groupName . ']=' . $this->listGroups[$groupName]->__toString()); // Add the hash to the index array_push($this->listIndex, $hash); @@ -161,7 +157,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab $this->listEntries[$hash] = $visitableInstance; // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',subGroup=' . $subGroup . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ',subGroup=' . $subGroup . ' - EXIT!'); } /** @@ -173,7 +169,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab */ public final function getArrayFromList ($list) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ' - CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ' - CALLED!'); // Is the group there? if ((!is_null($list)) && (!$this->isGroupSet($list))) { @@ -182,7 +178,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab } // END - if // Init array - $array = array(); + $array = []; // Is there another list? if (!is_null($list)) { @@ -193,18 +189,18 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab // Walk through all entries foreach ($this->listIndex as $hash) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: hash=' . $hash); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: hash=' . $hash); // Is the list entry set? 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('BASE-LIST: hash=' . $hash . ',array(' . count($array) . ')=' . print_r($array, true) . ' - ADDED!'); } // END - if } // END - foreach // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ',array()=' . count($array) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ',[]=' . count($array) . ' - EXIT!'); // Return it return $array; @@ -220,7 +216,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab */ public function addEntry ($groupName, $entry) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!'); // Is the group already added? if (!$this->isGroupSet($groupName)) { @@ -232,19 +228,19 @@ 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('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ',entry=' . print_r($entry, true) . ', hash=' . $hash); // Add the hash to the index array_push($this->listIndex, $hash); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',listEntries()=' . count($this->listEntries)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ',listEntries()=' . count($this->listEntries)); // Now add the entry to the list $this->listEntries[$hash] = $entry; // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',listEntries()=' . count($this->listEntries) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ',listEntries()=' . count($this->listEntries) . ' - EXIT!'); } /** @@ -257,7 +253,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab */ public function removeEntry ($groupName, $entry) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!'); // Is the group already added? if (!$this->isGroupSet($groupName)) { @@ -269,7 +265,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=' . $entry . ', hash=' . $hash); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ',entry=' . $entry . ', hash=' . $hash); // Remove it from the list ... unset($this->listEntries[$hash]); @@ -278,7 +274,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab unset($this->listIndex[array_search($hash, $this->listIndex)]); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - EXIT!'); } /** @@ -308,15 +304,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->getCallbackInstance() instanceof FrameworkInterface) && (method_exists($this->getCallbackInstance(), 'generateListHashFromEntry'))) { + // Call it instead + $entry2 = $this->getCallbackInstance()->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: Entry type ' . gettype($entry) . ' is unsupported (this->callbackInstance=' . $this->getCallbackInstance() . ').'); - // @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 @@ -360,8 +356,8 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab $this->listGroups[$groupName]->clearList(); // Clear this list - $this->listIndex = array(); - $this->listEntries = array(); + $this->listIndex = []; + $this->listEntries = []; } /** @@ -440,7 +436,7 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab } // END - if // Init the entries' array - $entries = array(); + $entries = []; // Get an iterator $iteratorInstance = $this->listGroups[$groupName]->getIterator();