Renamed Registry -> GenericRegistry to make it clear that this registry does
[core.git] / framework / main / classes / file_directories / directory / class_FrameworkDirectoryPointer.php
index 64688af..4c03302 100644 (file)
@@ -1,10 +1,11 @@
 <?php
 // Own namespace
-namespace CoreFramework\Filesytem\Pointer;
+namespace Org\Mxchange\CoreFramework\Filesytem\Pointer;
 
 // Import framework stuff
-use CoreFramework\Filesystem\FrameworkDirectory;
-use CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Filesystem\FrameworkDirectory;
+use Org\Mxchange\CoreFramework\Generic\NullPointerException;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
 // Import SPL stuff
 use \DirectoryIterator;
@@ -69,44 +70,26 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         * 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
         * @return      $pointerInstance        A prepared instance of FrameworkDirectoryPointer
-        * @throws      PathIsEmptyException    If the provided path name is empty
+        * @throws      NullPointerException    If the provided path name is null
         * @throws      InvalidPathStringException      If the provided path name is not a string
         * @throws      PathIsNoDirectoryException      If the provided path name is not valid
         * @throws      PathReadProtectedException      If the provided path name is read-protected
-        * @todo        Get rid of inConstructor, could be old-lost code.
         */
-       public static final function createFrameworkDirectoryPointer ($pathName, $inConstructor = false) {
+       public static final function createFrameworkDirectoryPointer ($pathName) {
                // Some pre-sanity checks...
                if (is_null($pathName)) {
                        // No pathname given
-                       if ($inConstructor) {
-                               return NULL;
-                       } else {
-                               throw new PathIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-                       }
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
                } elseif (!is_string($pathName)) {
                        // Is not a string
-                       if ($inConstructor) {
-                               return NULL;
-                       } else {
-                               throw new InvalidPathStringException(NULL, self::EXCEPTION_INVALID_STRING);
-                       }
+                       throw new InvalidPathStringException(NULL, self::EXCEPTION_INVALID_STRING);
                } elseif (!is_dir($pathName)) {
                        // Not a directory
-                       if ($inConstructor) {
-                               return NULL;
-                       } else {
-                               throw new PathIsNoDirectoryException($pathName, self::EXCEPTION_INVALID_PATH_NAME);
-                       }
+                       throw new PathIsNoDirectoryException($pathName, self::EXCEPTION_INVALID_PATH_NAME);
                } elseif (!is_readable($pathName)) {
                        // Not readable
-                       if ($inConstructor) {
-                               return NULL;
-                       } else {
-                               throw new PathReadProtectedException($pathName, self::EXCEPTION_READ_PROTECED_PATH);
-                       }
+                       throw new PathReadProtectedException($pathName, self::EXCEPTION_READ_PROTECED_PATH);
                }
 
                // Create new instance
@@ -150,7 +133,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         * Read lines from the current directory pointer except some parts
         *
         * @param       $except         Some parts of a directory we want to ignore. Valid: directory and file names, other values will be silently ignored
-        * @return      string          Directory and/or file names read from the current directory pointer
+        * @return      SplFileInfo             An instance of a SplFileInfo class
         */
        public function readDirectoryExcept (array $except = array()) {
                // No exceptions given?
@@ -165,7 +148,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
                }
 
                // Init raw line
-               $rawLine = NULL;
+               $fileInfoInstance = NULL;
 
                // Read a raw line...
                $currentEntry = $this->readRawDirectory();
@@ -174,17 +157,17 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
                // Shall we exclude directories?
                if (is_object($currentEntry)) {
                        // Get file name
-                       $rawLine = $currentEntry->getFilename();
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawLine[' . gettype($rawLine) . ']=' . $rawLine . ',isDot=' . intval($this->getDirectoryIteratorInstance()->isDot()));
+                       $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($rawLine, $except))) {
+                       if (($this->getDirectoryIteratorInstance()->isDot()) || (in_array($fileInfoInstance, $except))) {
                                // To next entry
                                $this->getDirectoryIteratorInstance()->next();
 
                                // Exclude this part
-                               $rawLine = $this->readDirectoryExcept($except);
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawline[' . gettype($rawLine) . ']=' . $rawLine . ' - Recursive call!');
+                               $fileInfoInstance = $this->readDirectoryExcept($except);
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: fileInfoInstance[' . gettype($fileInfoInstance) . ']=' . $fileInfoInstance . ' - Recursive call!');
                        } // END - if
                } // END - if
 
@@ -192,8 +175,8 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
                $this->getDirectoryIteratorInstance()->next();
 
                // Return read line
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawLine[' . gettype($rawLine) . ']=' . $rawLine);
-               return $rawLine;
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: fileInfoInstance[' . gettype($fileInfoInstance) . ']=' . $fileInfoInstance);
+               return $fileInfoInstance;
        }
 
        /**