]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php
Continued:
[core.git] / framework / main / classes / file_directories / directory / class_FrameworkDirectoryPointer.php
index fe2bd14e405bcb5ac140755d506819593e7ce6bc..52a197b1abfe23c0e10e1e9579f3e2757bab6605 100644 (file)
@@ -18,7 +18,7 @@ use \DirectoryIterator;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2019 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
  *
@@ -109,7 +109,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
                $pointerInstance->setPathName($pathName);
 
                // Return the instance
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: Opened pathName=' . $pathName . ' - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: Opened pathName=' . $pathName . ' - EXIT!');
                return $pointerInstance;
        }
 
@@ -119,16 +119,15 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         * @return      $currentEntry   Current entry from encapsulated iterator
         */
        public function readRawDirectory () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . '] - CALLED!');
-
                // Can the next entry be read?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: CALLED!');
                assert($this->getDirectoryIteratorInstance()->valid());
 
                // Read data from the directory pointer and return it
                $currentEntry = $this->getDirectoryIteratorInstance()->current();
 
                // Return found entry
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: currentEntry[]=' . gettype($currentEntry) . ' - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: currentEntry[%s]=%s - EXIT!', gettype($currentEntry), $currentEntry));
                return $currentEntry;
        }
 
@@ -138,15 +137,16 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         * @param       $except         Some parts of a directory we want to ignore. Valid: directory and file names, other values will be silently ignored
         * @return      SplFileInfo             An instance of a SplFileInfo class
         */
-       public function readDirectoryExcept (array $except = array()) {
+       public function readDirectoryExcept (array $except = []) {
                // No exceptions given?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: except()=%d - CALLED!', count($except)));
                if (count($except) == 0) {
                        // No exception given, so read all files and directories, but not recursive
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: No exceptions given, please use readRawDirectory() instead!');
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: No exceptions given, please use readRawDirectory() instead!');
                        return $this->readRawDirectory();
                } elseif (!$this->getDirectoryIteratorInstance()->valid()) {
                        // No more left to read
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: EOD reached.');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: EOD reached - EXIT!');
                        return NULL;
                }
 
@@ -155,30 +155,28 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
 
                // Read a raw line...
                $currentEntry = $this->readRawDirectory();
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: currentEntry[]=' . gettype($currentEntry));
 
                // Shall we exclude directories?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: currentEntry[]=%s', gettype($currentEntry)));
                if (is_object($currentEntry)) {
                        // Get file name
                        $fileInfoInstance = $currentEntry;
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: fileInfoInstance[' . gettype($fileInfoInstance) . ']=' . $fileInfoInstance . ',isDot=' . intval($this->getDirectoryIteratorInstance()->isDot()));
 
                        // Is it a dot-directory or excluded?
-                       if (($this->getDirectoryIteratorInstance()->isDot()) && (!in_array($fileInfoInstance, $except))) {
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: fileInfoInstance->filename=%s,isDot=%d', $fileInfoInstance->getFilename(), intval($this->getDirectoryIteratorInstance()->isDot())));
+                       while ($this->getDirectoryIteratorInstance()->valid() && ($this->getDirectoryIteratorInstance()->isDot() || in_array($fileInfoInstance->getFilename(), $except))) {
+                               // Update current instance
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: fileInfoInstance->filename=%s,isDot=%d', $fileInfoInstance->getFilename(), intval($this->getDirectoryIteratorInstance()->isDot())));
+                               $fileInfoInstance = $this->readRawDirectory();
+
                                // To next entry
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: Invoking directoryIteratorInstance->next() ...');
                                $this->getDirectoryIteratorInstance()->next();
-
-                               // Exclude this part
-                               $fileInfoInstance = $this->readDirectoryExcept($except);
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: fileInfoInstance[' . gettype($fileInfoInstance) . ']=' . $fileInfoInstance . ' - Recursive call!');
-                       } // END - if
+                       } // END - while
                } // END - if
 
-               // To next entry
-               $this->getDirectoryIteratorInstance()->next();
-
                // Return read line
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: fileInfoInstance[' . gettype($fileInfoInstance) . ']=' . $fileInfoInstance);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: fileInfoInstance[%s]=%s - EXIT!', gettype($fileInfoInstance), $fileInfoInstance));
                return $fileInfoInstance;
        }
 
@@ -190,6 +188,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         */
        public function closeDirectory () {
                // Close the directory by unsetting it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: CALLED!');
                $this->unsetDirectoryIteratorInstance();
                $this->setPathName('');
        }