X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ffile_directories%2Fdirectory%2Fclass_FrameworkDirectoryPointer.php;h=52a197b1abfe23c0e10e1e9579f3e2757bab6605;hb=498e6b065ce47804bff4e1073592a2cc8e28f8ef;hp=8bcb3ccfc839d71c9721c61380b38cc5b7f15fba;hpb=78a010fef84895720e796842208f01dfb619c332;p=core.git diff --git a/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php b/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php index 8bcb3ccf..52a197b1 100644 --- a/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php +++ b/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php @@ -1,10 +1,14 @@ * @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 * @@ -69,44 +73,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 @@ -123,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; } @@ -133,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; } @@ -150,50 +135,49 @@ 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()) { + 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; } // Init raw line - $rawLine = NULL; + $fileInfoInstance = NULL; // 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 - $rawLine = $currentEntry->getFilename(); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawLine[' . gettype($rawLine) . ']=' . $rawLine . ',isDot=' . intval($this->getDirectoryIteratorInstance()->isDot())); + $fileInfoInstance = $currentEntry; // Is it a dot-directory or excluded? - if (($this->getDirectoryIteratorInstance()->isDot()) || (in_array($rawLine, $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 - $rawLine = $this->readDirectoryExcept($except); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawline[' . gettype($rawLine) . ']=' . $rawLine . ' - 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__ . ']: rawLine[' . gettype($rawLine) . ']=' . $rawLine); - return $rawLine; + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: fileInfoInstance[%s]=%s - EXIT!', gettype($fileInfoInstance), $fileInfoInstance)); + return $fileInfoInstance; } /** @@ -204,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(''); }