*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Directory {
+class FrameworkDirectoryPointer extends BaseFrameworkSystem implements FrameworkDirectory {
/**
* The current path we are working in
*/
*/
public function __destruct() {
// Is there a resource pointer? Then we have to close the directory here!
- if ($this->getIteratorInstance() instanceof DirectoryIterator) {
+ if ($this->getDirectoryIteratorInstance() instanceof DirectoryIterator) {
// Try to close a directory
$this->closeDirectory();
} // END - if
$iteratorInstance->rewind();
// Set directory pointer and path name
- $pointerInstance->setIteratorInstance($iteratorInstance);
+ $pointerInstance->setDirectoryIteratorInstance($iteratorInstance);
$pointerInstance->setPathName($pathName);
// Return the instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . '] - CALLED!');
// Can the next entry be read?
- assert($this->getIteratorInstance()->valid());
-
- // Default is FALSE
- $currentEntry = FALSE;
+ assert($this->getDirectoryIteratorInstance()->valid());
// Read data from the directory pointer and return it
- $currentEntry = $this->getIteratorInstance()->current();
+ $currentEntry = $this->getDirectoryIteratorInstance()->current();
// Return found entry
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: currentEntry[]=' . gettype($currentEntry) . ' - EXIT!');
// No exception given, so read all files and directories, but not recursive
self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: No exceptions given, please use readRawDirectory() instead!');
return $this->readRawDirectory();
- } elseif (!$this->getIteratorInstance()->valid()) {
+ } elseif (!$this->getDirectoryIteratorInstance()->valid()) {
// No more left to read
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: EOD reached.');
return NULL;
}
if (is_object($currentEntry)) {
// Get file name
$rawLine = $currentEntry->getFilename();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawLine[' . gettype($rawLine) . ']=' . $rawLine);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawLine[' . gettype($rawLine) . ']=' . $rawLine . ',isDot=' . intval($this->getDirectoryIteratorInstance()->isDot()));
- // Is it not excluded?
- if (in_array($rawLine, $except)) {
+ // Is it a dot-directory or excluded?
+ if (($this->getDirectoryIteratorInstance()->isDot()) || (in_array($rawLine, $except))) {
// To next entry
- $this->getIteratorInstance()->next();
+ $this->getDirectoryIteratorInstance()->next();
// Exclude this part
$rawLine = $this->readDirectoryExcept($except);
} // END - if
// To next entry
- $this->getIteratorInstance()->next();
+ $this->getDirectoryIteratorInstance()->next();
// Return read line
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawLine[' . gettype($rawLine) . ']=' . $rawLine);
*/
public function closeDirectory () {
// Close the directory by unsetting it
- $this->setIteratorInstance(NULL);
+ $this->unsetDirectoryIteratorInstance();
$this->setPathName('');
}
/**
* Setter for the directory pointer
*
- * @param $iteratorInstance An instanceof a DirectoryIterator class or NULL to unset ("close") it.
+ * @param $iteratorInstance An instanceof a DirectoryIterator class
* @return void
*/
- protected final function setIteratorInstance (DirectoryIterator $iteratorInstance = NULL) {
- // Set instance (or NULL)
+ protected final function setDirectoryIteratorInstance (DirectoryIterator $iteratorInstance) {
+ // Set instance
$this->iteratorInstance = $iteratorInstance;
}
*
* @return $iteratorInstance The directory pointer which shall be a valid directory resource
*/
- public final function getIteratorInstance () {
+ public final function getDirectoryIteratorInstance () {
return $this->iteratorInstance;
}
+ /**
+ * Remove directory iterator instance (effectively closing it) by setting
+ * it to NULL. This will trigger a call on the destructor which will then
+ * "close" the iterator.
+ *
+ * @param $iteratorInstance An instanceof a DirectoryIterator class
+ * @return void
+ */
+ protected final function unsetDirectoryIteratorInstance () {
+ // "Unset" the instance
+ $this->iteratorInstance = NULL;
+ }
+
/**
* Setter for path name
*