本文整理汇总了PHP中RecursiveDirectoryIterator::current方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveDirectoryIterator::current方法的具体用法?PHP RecursiveDirectoryIterator::current怎么用?PHP RecursiveDirectoryIterator::current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveDirectoryIterator
的用法示例。
在下文中一共展示了RecursiveDirectoryIterator::current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: current
/**
* {@inheritdoc}
*/
public function current()
{
$current = parent::current();
if ($this->normalizeCurrent) {
$current = str_replace('\\', '/', $current);
}
return $current;
}
示例2: current
public function current()
{
$file = parent::current();
if ($file instanceof SplFileInfo) {
// Wrap into sfFilebasePluginFile to provide additional methods
// for analyzing file-type
$file = new sfFilebasePluginFile($file, $this->filebase);
if ($file->isDir()) {
$file = new sfFilebasePluginDirectory($file, $this->filebase);
} elseif ($file->isImage()) {
$file = new sfFilebasePluginImage($file, $this->filebase);
}
}
return $file;
}
开发者ID:joshiausdemwald,项目名称:sfFilebasePlugin,代码行数:15,代码来源:sfFilebasePluginRecursiveDirectoryIterator.php
示例3: _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);
}
示例4: 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();
}
}
示例5: gettype
<?php
$it1 = new RecursiveDirectoryIterator(dirname(__FILE__), FileSystemIterator::CURRENT_AS_PATHNAME);
$it1->rewind();
echo gettype($it1->current()) . "\n";
$it2 = new RecursiveDirectoryIterator(dirname(__FILE__));
$it2->rewind();
echo gettype($it2->current()) . "\n";
示例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: current
/**
* Return an instance of SplFileInfo with support for relative paths
*
* @return SplFileInfo File information
*/
public function current()
{
return new SplFileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname());
}
示例10: 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;
}
示例11: array
<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'));
$items = array_merge($items, $tmp);
示例12: current
function current()
{
echo __FUNCTION__ . "\n";
return parent::current();
}
示例13: _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;
}
}
}
示例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: current
/**
* Current.
* Please, see \RecursiveDirectoryIterator::current() method.
*
* @return mixed
*/
public function current()
{
$out = parent::current();
if (null !== $this->_splFileInfoClass && $out instanceof \SplFileInfo) {
$out->setInfoClass($this->_splFileInfoClass);
$out = $out->getFileInfo();
if ($out instanceof \Hoa\Iterator\SplFileInfo) {
$out->setRelativePath($this->getRelativePath());
}
}
return $out;
}