Some fixes/improvements:
[core.git] / inc / classes / main / io / class_FrameworkDirectoryPointer.php
index e0a0c4e5bfcae51f016229ba1e1d758302787ad7..ba9b58c24945b44cb914d2a5cd55c45e94ebc336 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007 - 2009 Roland Haeder, this is free software
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -30,7 +30,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem {
        /**
         * The directory pointer
         */
-       private $dirPointer = null;
+       private $dirPointer = NULL;
 
        /**
         * Protected constructor
@@ -38,10 +38,6 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
-
-               // Clean-up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
        }
 
        /**
@@ -62,50 +58,49 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem {
         * Create a directory pointer based on the given path. The path will also
         * be verified here.
         *
-        * @param               $pathName                                       The path name we shall pass
-        *                                                                      to opendir()
-        * @param               $inConstructor                          If we are in de/con-structor
-        *                                                                      or from somewhere else
-        * @throws      PathIsEmptyException            If the provided path name
+        * @param       $pathName               The path name we shall pass to opendir()
+        * @param       $inConstructor  If we are in de/con-structor or from somewhere
+        *                                                      else
+        * @return      $pointerInstance        A prepared instance of
+        *                                                              FrameworkDirectoryPointer
+        * @throws      PathIsEmptyException    If the provided path name
         *                                                                      is empty
         * @throws      InvalidPathStringException      If the provided path name is
-        *                                                                      not a string
+        *                                                                              not a string
         * @throws      PathIsNoDirectoryException      If the provided path name is
-        *                                                                      not valid
+        *                                                                              not valid
         * @throws      PathReadProtectedException      If the provided path name is
-        *                                                                      read-protected
+        *                                                                              read-protected
         * @throws      DirPointerNotOpened                     If opendir() returns not a
-        *                                                                      directory resource
-        * @return      $pointerInstance                        A prepared instance of
-        *                                                                      FrameworkDirectoryPointer
+        *                                                                              directory resource
         */
-       public final static function createFrameworkDirectoryPointer ($pathName, $inConstructor = false) {
+       public static final function createFrameworkDirectoryPointer ($pathName, $inConstructor = false) {
                // Some pre-sanity checks...
                if (is_null($pathName)) {
                        // No pathname given
                        if ($inConstructor) {
-                               return null;
+                               return NULL;
                        } else {
                                throw new PathIsEmptyException(null, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
                        }
                } elseif (!is_string($pathName)) {
                        // Is not a string
                        if ($inConstructor) {
-                               return null;
+                               return NULL;
                        } else {
                                throw new InvalidPathStringException(null, self::EXCEPTION_INVALID_STRING);
                        }
                } elseif (!is_dir($pathName)) {
                        // Not a directory
                        if ($inConstructor) {
-                               return null;
+                               return NULL;
                        } else {
                                throw new PathIsNoDirectoryException($pathName, self::EXCEPTION_INVALID_PATH_NAME);
                        }
                } elseif (!is_readable($pathName)) {
                        // Not readable
                        if ($inConstructor) {
-                               return null;
+                               return NULL;
                        } else {
                                throw new PathReadProtectedException($pathName, self::EXCEPTION_READ_PROTECED_PATH);
                        }
@@ -116,7 +111,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem {
                if (!is_resource($dirPointer)) {
                        // Something bad happend
                        if ($inConstructor) {
-                               return null;
+                               return NULL;
                        } else {
                                throw new DirPointerNotOpenedException($pathName, self::EXCEPTION_DIR_POINTER_INVALID);
                        }
@@ -153,26 +148,29 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem {
         * @return      string  Directory and/or file names read from the current
         *                                      directory pointer
         */
-       public function readDirectoryExcept ($except = '') {
-               if ((empty($except)) || (!is_array($except)) || (count($except) == 0)) {
+       public function readDirectoryExcept (array $except = array()) {
+               if (count($except) == 0) {
                        // No exception given, so read all data
                        return $this->readRawDirectory();
-               }
+               } // END - if
 
                // Read a raw line...
                $rawLine = $this->readRawDirectory();
 
                // Shall we exclude directories?
-               if ((!is_null($rawLine)) && ($rawLine !== false) && (in_array($rawLine, $except))) {
-                       // Exclude this part
-                       return $this->readDirectoryExcept($except);
-               } elseif ((!is_null($rawLine)) && ($rawLine !== false)) {
+               if ((!is_null($rawLine)) && ($rawLine !== false) && (!in_array($rawLine, $except))) {
                        // Return read data
+                       //* NOISY-DEBUG: */ $this->debugOutput('DIRECTORY: rawLine[' . gettype($rawLine) . ']=' . $rawLine);
                        return $rawLine;
+               } elseif ((!is_null($rawLine)) && ($rawLine !== false)) {
+                       // Exclude this part
+                       //* NOISY-DEBUG: */ $this->debugOutput('DIRECTORY: rawline[' . gettype($rawLine) . ']=' . $rawLine . ' - Recursive call!');
+                       return $this->readDirectoryExcept($except);
                }
 
                // End pointer reached
-               return null;
+               //* NOISY-DEBUG: */ $this->debugOutput('DIRECTORY: Returning NULL!');
+               return NULL;
        }
 
        /**
@@ -184,7 +182,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem {
        public function closeDirectory () {
                // Close the directory pointer and reset the instance variable
                @closedir($this->getPointer());
-               $this->setPointer(null);
+               $this->setPointer(NULL);
                $this->setPathName('');
        }
 
@@ -201,7 +199,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem {
                        $this->dirPointer = $dirPointer;
                } else {
                        // Throw exception
-                       throw new InvalidDirectoryResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER);
+                       throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
                }
        }