本文整理汇总了PHP中RecursiveDirectoryIterator::valid方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveDirectoryIterator::valid方法的具体用法?PHP RecursiveDirectoryIterator::valid怎么用?PHP RecursiveDirectoryIterator::valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveDirectoryIterator
的用法示例。
在下文中一共展示了RecursiveDirectoryIterator::valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: valid
/**
* 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;
}
开发者ID:joshiausdemwald,项目名称:sfFilebasePlugin,代码行数:22,代码来源:sfFilebasePluginRecursiveDirectoryIterator.php
示例2: _deleteFolder
/**
* 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);
}
示例3: load_tests
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();
}
}
示例4: getExamples
/**
* 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->getPathInfo();
$info = pathinfo($filename);
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;
}
}
$ret[$example] = array($class, $template, $output);
}
$files->next();
}
return $ret;
}
示例5: parseDir
/**
* 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();
}
}
示例6: getFileAndFoldernamesInPath
/**
* 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;
}
示例7: addFolder
/**
* @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();
}
示例8: retrieveFileAndFoldersInPath
/**
* 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);
}
示例9: scanDirectory
/**
* @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;
}
示例10: _recurseDirectory
/**
* 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();
}
}
示例11: array
return;
}
mysql_connection_select(DATABASE);
// set parameter defaults
$formImportDir = @$_REQUEST['formImportDir'];
// outName returns the hml direct.
$resourceUriRoot = @$_REQUEST['resourceUriRoot'];
// URI prefix for the resources upload with forms.
//if no style given then try default, if default doesn't exist we our put raw xml
$importData = array();
$info = new SplFileInfo($formImportDir);
$i = 0;
$xmlForms = array("form" => array(), "resource" => array());
if ($info->isDir()) {
$iterator = new RecursiveDirectoryIterator($formImportDir);
while ($iterator->valid()) {
if ($iterator->isFile()) {
$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 . "-");
}
示例12: _fetch
/**
*
* 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;
}
}
}
示例13: valid
function valid()
{
if (parent::valid()) {
if (!parent::isDir() || parent::isDot()) {
parent::next();
return $this->valid();
}
return TRUE;
}
return FALSE;
}
示例14: testBz2Create
/**
* 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());
}
示例15: array
<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'));