]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/iterator/registry/class_RegistryIterator.php
Continued:
[core.git] / framework / main / classes / iterator / registry / class_RegistryIterator.php
index c042707f6db8f4c3e6f96ee4c02b274ab8b00673..b0a28dc5a8301405b961ad9370598a497311d568 100644 (file)
@@ -3,12 +3,14 @@
 namespace Org\Mxchange\CoreFramework\Iterator\Registry;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
 use Org\Mxchange\CoreFramework\Iterator\BaseIterator;
 use Org\Mxchange\CoreFramework\Registry\Register;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Registry\Sub\SubRegistry;
+use Org\Mxchange\CoreFramework\Traits\Registry\RegisterTrait;
 
 // Import SPL stuff
 use \BadMethodCallException;
@@ -19,7 +21,7 @@ use \LogicException;
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -37,6 +39,9 @@ use \LogicException;
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class RegistryIterator extends BaseIterator implements IteratableRegistry {
+       // Load traits
+       use RegisterTrait;
+
        /**
         * All found registry keys
         */
@@ -53,17 +58,12 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
         */
        private $key = NULL;
 
-       /**
-        * Registry instance (implementing Register)
-        */
-       private $registryInstance = NULL;
-
        /**
         * Protected constructor
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
 
@@ -93,25 +93,6 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
                return $iteratorInstance;
        }
 
-       /**
-        * Setter for registry instance
-        *
-        * @param       $registryInstance               An instance of a Register class
-        * @return      void
-        */
-       protected final function setRegistryInstance (Register $registryInstance) {
-               $this->registryInstance = $registryInstance;
-       }
-
-       /**
-        * Getter for registry instance
-        *
-        * @return      $registryInstance       The debug registry instance
-        */
-       protected final function getRegistryInstance () {
-               return $this->registryInstance;
-       }
-
        /**
         * Setter for only-registries array
         *
@@ -142,8 +123,8 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[generic]: entries()=%d', count($entries)));
                if (count($entries) > 0) {
                        // Debugging:
-                       /* DEBUG-DIE: */ die(sprintf('[%s:%d]: UNFINISHED: entries=%s', __METHOD__, __LINE__, print_r($entries, TRUE)));
-               } // END - if
+                       /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: UNFINISHED: entries=%s', __METHOD__, __LINE__, print_r($entries, TRUE)));
+               }
 
                // Get instance registry entries from it
                $entries = $this->getRegistryInstance()->getInstanceRegistry();
@@ -172,7 +153,7 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
 
                                        // Add all sub-registry keys to this registry keys array
                                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[instance]: subRegistryInstances()=%d', count($subRegistryInstances)));
-                                       //* DEBUG-DIE: */ die(sprintf('[%s:%d]: key=%s,subRegistryInstances=%s', __METHOD__, __LINE__, $key, print_r($subRegistryInstances, TRUE)));
+                                       //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: key=%s,subRegistryInstances=%s', __METHOD__, __LINE__, $key, print_r($subRegistryInstances, TRUE)));
                                        foreach (array_keys($subRegistryInstances) as $subKey) {
                                                // Add it
                                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[instance]: Adding key=%s,subKey=%s ...', $key, $subKey));
@@ -202,10 +183,10 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
 
                                // Add key to array
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[instance]: key=%s - Adding ...', $key));
-                               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: key=%s,entry=%s', __METHOD__, __LINE__, $key, print_r($entry, TRUE)));
+                               //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: key=%s,entry=%s', __METHOD__, __LINE__, $key, print_r($entry, TRUE)));
                                array_push($this->registryKeys['instance'], $key);
-                       } // END - foreach
-               } // END - if
+                       }
+               }
 
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY-ITERATOR: EXIT!');
@@ -230,7 +211,7 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
        public function current () {
                // Default is null
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[%s]: CALLED!', $this->key()));
-               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
+               //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
                $current = NULL;
                $entries = [];
 
@@ -248,7 +229,7 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
 
                                // The key should be there
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[%s]: Handling registryKey=%s ...', $this->key(), $registryKey));
-                               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: instances=%s', __METHOD__, __LINE__, print_r($instances, TRUE)));
+                               //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: instances=%s', __METHOD__, __LINE__, print_r($instances, TRUE)));
                                if (!isset($instances[$this->key()])) {
                                        // Skip below code
                                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[%s]: registryKey=%s has no this->key=%s, skipping ...', $this->key(), $registryKey));
@@ -294,7 +275,7 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
        public function next () {
                // Is valid() still TRUE?
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[%s]: CALLED!', $this->key()));
-               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
+               //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
                if (!$this->valid()) {
                        // Bad method call!
                        throw new BadMethodCallException(sprintf('this->key[%s]=%s is no longer valid, but method was called.', gettype($this->key()), $this->key()));
@@ -312,7 +293,7 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[%s]: this->registryKeys[generic]()=%d,this->registryKeys[instance]()=%d', $this->key(), count($this->registryKeys['generic']), count($this->registryKeys['instance'])));
                if (count($this->registryKeys['generic']) > 0) {
                        // First generic array
-                       /* UNFINISHED */ die(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
+                       /* UNFINISHED */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
                } elseif (count($this->registryKeys['instance']) > 0) {
                        // Second instance, current key's index + 1
                        $nextIndex = array_search($this->key(), $this->registryKeys['instance']) + 1;
@@ -346,7 +327,7 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
        public function rewind () {
                // Is current key first key?
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[%s]: CALLED!', $this->key()));
-               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
+               //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
                if (array_search($this->key(), $this->getRegistryKeys()) === 0) {
                        // rewind() cannot rewind first entry!
                        throw new BadMethodCallException(sprintf('this->key=%s is already first element, but method was called.', $this->key()));
@@ -359,7 +340,7 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[%s]: this->registryKeys[generic]()=%d,this->registryKeys[instance]()=%d', $this->key(), count($this->registryKeys['generic']), count($this->registryKeys['instance'])));
                if (count($this->registryKeys['generic']) > 0) {
                        // First generic array
-                       /* UNFINISHED */ die(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
+                       /* UNFINISHED */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
                } elseif (count($this->registryKeys['instance']) > 0) {
                        // Second instance
                        $this->key = $this->registryKeys['instance'][0];
@@ -377,7 +358,7 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry {
        public function valid () {
                // Is the element there?
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[%s]: CALLED!', $this->key()));
-               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), print_r($this->registryKeys, TRUE)));
+               //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), print_r($this->registryKeys, TRUE)));
                $valid = (in_array($this->key(), $this->registryKeys['instance']) || in_array($this->key(), $this->registryKeys['generic']));
 
                // Return flag