public function next() { parent::next(); while ($this->isDot()) { parent::next(); } }
public function rewind() { if (false === $this->isRewindable()) { return; } parent::next(); parent::rewind(); }
/** * Do nothing for non rewindable stream */ public function rewind() { if (false === $this->isRewindable()) { return; } // @see https://bugs.php.net/bug.php?id=49104 parent::next(); parent::rewind(); }
public function rewind() { if (false === $this->isRewindable()) { return; } if (PHP_VERSION_ID < 50523 || PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50607) { parent::next(); } parent::rewind(); }
/** * Returns true if file is valid. * Valid Files: Directories and Files not beginning with a "." (dot). * * @todo make it more flexible to handle hidden dirs on demand etc, * win/*nix compat * * @return boolean if current file entry is vali */ public function valid() { if (parent::valid()) { if (parent::isDot() || parent::isDir() && strpos(parent::getFilename(), '.') === 0) { parent::next(); // zum nächsten eintrag hüpfen return $this->valid(); // nochmal prüfen } return true; } return false; }
/** * deletes a folder recursively * * @param string $path the folder to delete * * @since 1.0 */ protected static function _deleteFolder($path) { /** * @var \SplFileInfo $item */ $dir = new \RecursiveDirectoryIterator($path); while ($dir->valid()) { $item = $dir->current(); if (!in_array($item->getFilename(), array('.', '..'))) { $isFile = $item->isFile(); $isFile ? unlink($item->getRealPath()) : self::_deleteFolder($item->getRealPath()); } $dir->next(); } rmdir($path); }
private function load_tests(RecursiveDirectoryIterator $dir) { while ($dir->valid()) { $current = $dir->current(); if ($dir->isFile() && preg_match("/(.)Test\\.php\$/", $current->getFilename(), $matches)) { // XXX: handle errors include $current->getPathname(); $x = explode('.', $current->getFilename()); $class = $x[0]; $rclass = new ReflectionClass($class); if ($rclass->getParentClass()->getName() == 'UnitTest') { $this->cases[] = $rclass; } } elseif ($dir->hasChildren() && preg_match("/^\\./", $current->getFilename(), $matches) == 0) { $this->load_tests($dir->getChildren()); } $dir->next(); } }
/** * @param $identifier * @param bool $files * @param bool $folders * @param bool $recursive * @return array */ public function scanDirectory($identifier, $files = true, $folders = true, $recursive = false) { $directoryEntries = []; $iterator = new \RecursiveDirectoryIterator($this->sftpWrapper . $identifier, $this->iteratorFlags); while ($iterator->valid()) { /** @var $entry \SplFileInfo */ $entry = $iterator->current(); $identifier = substr($entry->getPathname(), $this->sftpWrapperLength); if ($files && $entry->isFile()) { $directoryEntries[$identifier] = $this->getShortInfo($identifier, 'file'); } elseif ($folders && $entry->isDir()) { $directoryEntries[$identifier] = $this->getShortInfo($identifier, 'dir'); } $iterator->next(); } if ($recursive) { foreach ($directoryEntries as $directoryEntry) { if ($directoryEntry['type'] === 'dir') { $scanResults = $this->scanDirectory($directoryEntry['identifier'], $files, $folders, $recursive); foreach ($scanResults as $identifier => $info) { $directoryEntries[$identifier] = $info; } } } } return $directoryEntries; }
protected function skipdots() { while ($this->isDot()) { parent::next(); } }
/** * Returns a list with the names of all files and folders in a path, optionally recursive. * Folder names have a trailing slash. * * @param string $path The absolute path * @param bool $recursive If TRUE, recursively fetches files and folders * @return array */ protected function getFileAndFoldernamesInPath($path, $recursive = FALSE) { if ($recursive) { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::CURRENT_AS_FILEINFO)); } else { $iterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::CURRENT_AS_FILEINFO); } $directoryEntries = array(); while ($iterator->valid()) { /** @var $entry \SplFileInfo */ $entry = $iterator->current(); // skip non-files/non-folders, and empty entries if (!$entry->isFile() && !$entry->isDir() || $entry->getFilename() == '') { $iterator->next(); continue; } // skip the pseudo-directories "." and ".." if ($entry->getFilename() == '..' || $entry->getFilename() == '.') { $iterator->next(); continue; } $entryPath = GeneralUtility::fixWindowsFilePath(substr($entry->getPathname(), strlen($path))); if ($entry->isDir()) { $entryPath .= '/'; } $directoryEntries[] = $entryPath; $iterator->next(); } return $directoryEntries; }
/** * Returns a list with the names of all files and folders in a path, optionally recursive. * * @param string $path The absolute path * @param bool $recursive If TRUE, recursively fetches files and folders * @param bool $includeFiles * @param bool $includeDirs * @param string $sort Property name used to sort the items. * Among them may be: '' (empty, no sorting), name, * fileext, size, tstamp and rw. * If a driver does not support the given property, it * should fall back to "name". * @param bool $sortRev TRUE to indicate reverse sorting (last to first) * @return array */ protected function retrieveFileAndFoldersInPath($path, $recursive = false, $includeFiles = true, $includeDirs = true, $sort = '', $sortRev = false) { $pathLength = strlen($this->getAbsoluteBasePath()); $iteratorMode = \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::FOLLOW_SYMLINKS; if ($recursive) { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, $iteratorMode), \RecursiveIteratorIterator::SELF_FIRST); } else { $iterator = new \RecursiveDirectoryIterator($path, $iteratorMode); } $directoryEntries = array(); while ($iterator->valid()) { /** @var $entry \SplFileInfo */ $entry = $iterator->current(); // skip non-files/non-folders, and empty entries if (!$entry->isFile() && !$entry->isDir() || $entry->getFilename() == '' || $entry->isFile() && !$includeFiles || $entry->isDir() && !$includeDirs) { $iterator->next(); continue; } $entryIdentifier = '/' . substr($entry->getPathname(), $pathLength); $entryName = PathUtility::basename($entryIdentifier); if ($entry->isDir()) { $entryIdentifier .= '/'; } $entryArray = array('identifier' => $entryIdentifier, 'name' => $entryName, 'type' => $entry->isDir() ? 'dir' : 'file'); $directoryEntries[$entryIdentifier] = $entryArray; $iterator->next(); } return $this->sortDirectoryEntries($directoryEntries, $sort, $sortRev); }
function valid() { if (parent::valid()) { if (!parent::isDir() || parent::isDot()) { parent::next(); return $this->valid(); } return TRUE; } return FALSE; }
/** * test create BZ2 file * * @since 1.0 */ public function testBz2Create() { /** * @var \SplFileInfo $item */ $file = $this->path . 'test.bz2'; $filesPath = $this->path . 'files' . DS; $creator = new Creator($file); $dir = new \RecursiveDirectoryIterator($filesPath); while ($dir->valid()) { $item = $dir->current(); if ($item->isFile()) { $add = $creator->addFile($item->getRealPath(), $item->getFilename()); $this->assertTrue($add, sprintf('the file %s was not added to the tar file', $item->getFilename())); } $dir->next(); } $this->assertFileExists($file); $this->assertEquals(10, $creator->getFilesCount()); }
/** * @private * * 1. Mimics tmp directory * 2. Find latest cache if $hash is null * 3. Return directory if $hash is '*' */ private static function resolve($key, $hash = null) { $target = sys_get_temp_dir(); if (strrpos($target, DIRECTORY_SEPARATOR) !== strlen($target) - 1) { $target .= DIRECTORY_SEPARATOR; } $target .= md5($key); if (!file_exists($target)) { if ($hash !== '*') { return null; } elseif (mkdir($target) === false) { throw new FrameworkException('Error creating cache folder "' . $target . '", please check folder permissions.'); } } else { if (is_file($target)) { throw new FrameworkException($target . ' is already a file, please specify another path.'); } } $target .= DIRECTORY_SEPARATOR; if ($hash === '*') { return new \RecursiveDirectoryIterator($target, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS); } if ($hash !== null) { $target = "{$target}{$hash}"; if (!is_file($target)) { throw new FrameworkException('Target revision is not a file.'); } return new \SplFileInfo($target); } else { $res = new \RecursiveDirectoryIterator($target, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS); $res->next(); $res->rewind(); $lfile = null; foreach ($res as $file) { if ($file->isFile() && strlen($file->getFilename()) == 32 && ($lfile == null || $lfile->getMTime() < $file->getMTime())) { $lfile = $file; } } if ($lfile === null) { return null; } if (!$lfile->isReadable() || !$lfile->isWritable()) { throw new FrameworkException('Cache cannot be read or written, please check file permission to PHP user.'); } return $lfile; } }
/** * Do nothing for non rewindable stream. */ public function rewind() { if (false === $this->isRewindable()) { return; } // @see https://bugs.php.net/68557 if (PHP_VERSION_ID < 50523 || PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50607) { parent::next(); } parent::rewind(); }
/** * * Recursively iterates through a directory looking for class files. * * Skips CVS directories, and all files and dirs not starting with * a capital letter (such as dot-files). * * @param RecursiveDirectoryIterator $iter Directory iterator. * * @return void * */ protected function _fetch(RecursiveDirectoryIterator $iter) { for ($iter->rewind(); $iter->valid(); $iter->next()) { // preliminaries $path = $iter->current()->getPathname(); $file = basename($path); $capital = ctype_alpha($file[0]) && $file == ucfirst($file); $phpfile = strripos($file, '.php'); // check for valid class files if ($iter->isDot() || !$capital) { // skip dot-files (including dot-file directories), as // well as files/dirs not starting with a capital letter continue; } elseif ($iter->isDir() && $file == 'CVS') { // skip CVS directories continue; } elseif ($iter->isDir() && $iter->hasChildren()) { // descend into child directories $this->_fetch($iter->getChildren()); } elseif ($iter->isFile() && $phpfile) { // map the .php file to a class name $len = strlen($this->_base); $class = substr($path, $len, -4); // drops .php $class = str_replace(DIRECTORY_SEPARATOR, '_', $class); $this->_map[$class] = $path; } } }
$ext = pathinfo($iterator->getPathname(), PATHINFO_EXTENSION); if ($ext == "xml") { // echo $prefix,$j," import ",$dirIterator->getPathname(), "<br>\n"; $xmlForms["form"][$iterator->getFilename()] = $iterator->getPathname(); } else { $filepath = preg_replace("/" . preg_replace("/\\//", "\\\\/", HEURIST_UPLOAD_DIR) . "/", "/", $iterator->getPathname()); // echo $prefix,$j," resource ".$dirIterator->getFilename()." has path ".$filepath, "<br>\n"; $xmlForms["resource"][$iterator->getFilename()] = $filepath; } } else { if ($iterator->isDir() && $iterator->hasChildren(false)) { // echo $i,pathinfo($iterator->getPathname(),PATHINFO_FILENAME), "<br>\n"; processChildDir($iterator->getChildren(), $i . "-"); } } $iterator->next(); $i++; } } else { echo "something is wrong"; } foreach ($xmlForms["form"] as $filename => $path) { list($rtyName, $headers, $row) = parseImportForm($filename, $xmlForms["resource"]); $rtyName = "" . $rtyName; if (!$rtyName) { continue; } if (!array_key_exists($rtyName, $importData)) { $importData[$rtyName] = array(); } if (!array_key_exists($headers, $importData[$rtyName])) {
/** * @inheritdoc */ public function addFolder($path, $parent = '') { /** * @var \SplFileInfo $item */ if (file_exists($path)) { $parent = $parent === null ? '' : $parent . DIRECTORY_SEPARATOR; $innerPath = $parent . basename($path); $dir = new \RecursiveDirectoryIterator($path); $dir->rewind(); while ($dir->valid()) { $item = $dir->current(); if ($item->isDir()) { if (!in_array($item->getFilename(), array('.', '..'))) { $this->addFolder($item->getRealPath(), $innerPath); } } else { $this->addFile($item->getRealPath(), $innerPath . DIRECTORY_SEPARATOR . $item->getFilename(), true); } $dir->next(); } } return $this->updateArchive(); }
function next() { echo __FUNCTION__ . "\n"; return parent::next(); }
/** * parse this directory * * @return none */ protected function parseDir() { $this->clear(); $iter = new RecursiveDirectoryIterator($this->getPath()); while ($iter->valid()) { $curr = (string) $iter->getSubPathname(); if (!$iter->isDot() && $curr[0] != '.') { $this->addItem(Varien_Directory_Factory::getFactory($iter->current(), $this->getRecursion(), $this->getRecursionLevel())); } $iter->next(); } }
/** * Recursive directory function. * * @param RecursiveDirectoryIterator $iterator */ protected function _recurseDirectory($iterator) { while ($iterator->valid()) { if ($iterator->isDir() && !$iterator->isDot()) { if ($iterator->hasChildren()) { $this->_recurseDirectory($iterator->getChildren()); } } elseif ($iterator->isFile()) { $path = $iterator->getPath() . '/' . $iterator->getFilename(); $pathinfo = pathinfo($path); if ($this->_isPhpFile($path)) { $this->addFile($path); } } $iterator->next(); } }
/** * Data provider for testExamples method. * * Assumes that an `examples` directory exists inside parent directory. * This examples directory should contain any number of subdirectories, each of which contains * three files: one Mustache class (.php), one Mustache template (.mustache), and one output file * (.txt). * * This whole mess will be refined later to be more intuitive and less prescriptive, but it'll * do for now. Especially since it means we can have unit tests :) * * @access public * @return array */ public function getExamples() { $basedir = dirname(__FILE__) . '/../examples/'; $ret = array(); $files = new RecursiveDirectoryIterator($basedir); while ($files->valid()) { if ($files->hasChildren() && ($children = $files->getChildren())) { $example = $files->getSubPathname(); $class = null; $template = null; $output = null; foreach ($children as $file) { if (!$file->isFile()) { continue; } $filename = $file->getPathname(); $info = pathinfo($filename); if (isset($info['extension'])) { switch ($info['extension']) { case 'php': $class = $info['filename']; include_once $filename; break; case 'mustache': $template = file_get_contents($filename); break; case 'txt': $output = file_get_contents($filename); break; } } } if (!empty($class)) { $ret[$example] = array($class, $template, $output); } } $files->next(); } return $ret; }
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <!--стили сайта--> <?php Yii::app()->bootstrap->init(); $assets = Yii::app()->getModule('docs')->assetsUrl(); Yii::app()->clientScript->registerCssFile($assets . '/css/styles.css'); ?> </head> <body> <?php $items = array(); $i = new RecursiveDirectoryIterator(Yii::getPathOfAlias('docs.views.documentation')); for ($i->rewind(); $i->valid(); $i->next()) { $item = $i->current(); if (!$i->hasChildren()) { continue; } $folder_name = t($item->getFileName()); $active_folder = false; $tmp = array(); foreach ($i->getChildren() as $child) { list($file) = explode('.', $child->getFileName()); $active = isset($_GET['alias']) && $_GET['alias'] == $file ? true : false; $active_folder = $active_folder || $active; $tmp[] = array('label' => t($file), 'itemOptions' => array(), 'active' => $active, 'url' => Yii::app()->createUrl('/docs/documentation/index', array('alias' => $file, 'folder' => $item->getFileName()))); } if ($active_folder) { $items[] = array('label' => $folder_name, 'itemOptions' => array('class' => 'nav-header'));