本文整理汇总了PHP中RecursiveIteratorIterator::rewind方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveIteratorIterator::rewind方法的具体用法?PHP RecursiveIteratorIterator::rewind怎么用?PHP RecursiveIteratorIterator::rewind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveIteratorIterator
的用法示例。
在下文中一共展示了RecursiveIteratorIterator::rewind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Parse
/**
* Parse a tarball of .gcov files.
**/
public function Parse($handle)
{
global $CDASH_BACKUP_DIRECTORY;
// This function receives an open file handle, but we really just need
// the path to this file so that we can extract it.
$meta_data = stream_get_meta_data($handle);
$filename = $meta_data["uri"];
fclose($handle);
// Create a new directory where we can extract our tarball.
$pathParts = pathinfo($filename);
$dirName = $CDASH_BACKUP_DIRECTORY . "/" . $pathParts['filename'];
mkdir($dirName);
// Extract the tarball.
$phar = new PharData($filename);
$phar->extractTo($dirName);
// Find the data.json file and extract the source directory from it.
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirName), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $fileinfo) {
if ($fileinfo->getFilename() == "data.json") {
$jsonContents = file_get_contents($fileinfo->getRealPath());
$jsonDecoded = json_decode($jsonContents, true);
if (is_null($jsonDecoded) || !array_key_exists("Source", $jsonDecoded) || !array_key_exists("Binary", $jsonDecoded)) {
$this->DeleteDirectory($dirName);
return false;
}
$this->SourceDirectory = $jsonDecoded['Source'];
$this->BinaryDirectory = $jsonDecoded['Binary'];
break;
}
}
if (empty($this->SourceDirectory) || empty($this->BinaryDirectory)) {
$this->DeleteDirectory($dirName);
return false;
}
// Check if any Labels.json files were included
$iterator->rewind();
foreach ($iterator as $fileinfo) {
if ($fileinfo->getFilename() == "Labels.json") {
$this->ParseLabelsFile($fileinfo);
}
}
// Recursively search for .gcov files and parse them.
$iterator->rewind();
foreach ($iterator as $fileinfo) {
if (pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION) == "gcov") {
$this->ParseGcovFile($fileinfo);
}
}
// Insert coverage summary (removing any old results first)
//$this->CoverageSummary->RemoveAll();
$this->CoverageSummary->Insert();
$this->CoverageSummary->ComputeDifference();
// Delete the directory when we're done.
$this->DeleteDirectory($dirName);
return true;
}
示例2: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
global $CFG;
$tmpdir = $CFG->tempdir;
// Default to last weeks time.
$time = time() - $CFG->tempdatafoldercleanup * 3600;
$dir = new \RecursiveDirectoryIterator($tmpdir);
// Show all child nodes prior to their parent.
$iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);
// An array of the full path (key) and date last modified.
$modifieddateobject = array();
// Get the time modified for each directory node. Nodes will be updated
// once a file is deleted, so we need a list of the original values.
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$node = $iter->getRealPath();
if (!is_readable($node)) {
continue;
}
$modifieddateobject[$node] = $iter->getMTime();
}
// Now loop through again and remove old files and directories.
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$node = $iter->getRealPath();
if (!is_readable($node)) {
continue;
}
// Check if file or directory is older than the given time.
if ($modifieddateobject[$node] < $time) {
if ($iter->isDir() && !$iter->isDot()) {
// Don't attempt to delete the directory if it isn't empty.
if (!glob($node . DIRECTORY_SEPARATOR . '*')) {
if (@rmdir($node) === false) {
mtrace("Failed removing directory '{$node}'.");
}
}
}
if ($iter->isFile()) {
if (@unlink($node) === false) {
mtrace("Failed removing file '{$node}'.");
}
}
} else {
// Return the time modified to the original date only for real files.
if ($iter->isDir() && !$iter->isDot()) {
touch($node, $modifieddateobject[$node]);
}
}
}
}
示例3: array_flatten
function array_flatten(array $array, $key_separator = '/')
{
$result = array();
// a stack of strings
$keys = array();
$prev_depth = -1;
$iter = new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::SELF_FIRST);
// rewind() is necessary
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$curr_depth = $iter->getDepth();
$diff_depth = $prev_depth - $curr_depth + 1;
//##### TODO: It would be nice to do this with a single function.
while ($diff_depth > 0) {
array_pop($keys);
--$diff_depth;
}
/*
Note:
http://bugs.php.net/bug.php?id=52425
array_shift/array_pop: add parameter that tells how many to elements to pop
*/
array_push($keys, $iter->key());
if (is_scalar($iter->current())) {
$result[implode($key_separator, $keys)] = $iter->current();
}
$prev_depth = $curr_depth;
}
return $result;
}
示例4: is_extension_changed
private static function is_extension_changed($name)
{
$name = strtolower($name);
$extension_build_dir = ROOT_PATH . DS . 'build' . DS . $name;
$extension_path = ROOT_PATH . DS . 'extensions' . DS . $name . '.tar.gz';
if (file_exists($extension_build_dir) && file_exists($extension_path)) {
$dir_iterator = new \RecursiveDirectoryIterator($extension_build_dir);
/**
* @var $iterator \RecursiveDirectoryIterator
*/
$iterator = new \RecursiveIteratorIterator($dir_iterator);
$iterator->rewind();
while ($iterator->valid()) {
if (!$iterator->isDot()) {
$file = $extension_build_dir . DS . $iterator->getSubPathName();
$phar_file = "phar://{$extension_path}/" . $iterator->getSubPathName();
if (!file_exists($phar_file)) {
return true;
} else {
$build_file_hash = md5(file_get_contents($file));
$phar_file_hash = md5(file_get_contents($phar_file));
if ($build_file_hash != $phar_file_hash) {
return true;
}
}
}
$iterator->next();
}
return false;
} else {
return false;
}
}
示例5: runTest
/**
* Executes a specific Selenium System Tests in your machine
*
* @param string $seleniumPath Optional path to selenium-standalone-server-x.jar
* @param string $pathToTestFile Optional name of the test to be run
* @param string $suite Optional name of the suite containing the tests, Acceptance by default.
*
* @return mixed
*/
public function runTest($pathToTestFile = null, $suite = 'acceptance')
{
$this->runSelenium();
// Make sure to Run the Build Command to Generate AcceptanceTester
$this->_exec("php vendor/bin/codecept build");
if (!$pathToTestFile) {
$this->say('Available tests in the system:');
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('tests/' . $suite, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);
$tests = array();
$iterator->rewind();
$i = 1;
while ($iterator->valid()) {
if (strripos($iterator->getSubPathName(), 'cept.php') || strripos($iterator->getSubPathName(), 'cest.php')) {
$this->say('[' . $i . '] ' . $iterator->getSubPathName());
$tests[$i] = $iterator->getSubPathName();
$i++;
}
$iterator->next();
}
$this->say('');
$testNumber = $this->ask('Type the number of the test in the list that you want to run...');
$test = $tests[$testNumber];
}
$pathToTestFile = 'tests/' . $suite . '/' . $test;
$this->taskCodecept()->test($pathToTestFile)->arg('--steps')->arg('--debug')->run()->stopOnFail();
// Kill selenium server
// $this->_exec('curl http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer');
}
示例6: getIterator
/**
* @return \RecursiveIteratorIterator
*/
public function getIterator()
{
//$iterator = new FileSearchIterator($this->baseDir, $this->pattern, $this->buildFlag());
if (!is_null($this->iterator)) {
$this->iterator->rewind();
return $this->iterator;
}
$iterator = new \RecursiveDirectoryIterator($this->baseDir, $this->buildFlag());
if ($this->ignoreVcsFiles) {
$this->ignore = array_merge($this->ignore, static::$vcsFiles);
}
if (!empty($this->ignore)) {
$iterator = new DirectoryExcludeFilter($iterator, $this->ignore);
}
if ($this->searchFor === static::SEARCH_FILES) {
$iterator = new FilenameRegexFilter($iterator, $this->pattern);
} else {
$iterator = new DirectoryRegexFilter($iterator, $this->pattern);
}
if (!empty($this->filters)) {
$iterator = $this->addFilters($iterator);
}
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
return $this->iterator = $iterator;
}
示例7: locate
/**
* @param $target
* @return array
*/
public function locate($target)
{
$paths = [];
$target = sprintf("%s/%s", self::RESOURCE_SUFFIX, $target);
foreach ($this->locations as $location) {
if (!is_dir($location)) {
continue;
}
$location = realpath($location);
$dir = new \RecursiveDirectoryIterator($location, \FilesystemIterator::FOLLOW_SYMLINKS);
$filter = new \RecursiveCallbackFilterIterator($dir, function (\SplFileInfo $current) use(&$paths, $target) {
$fileName = strtolower($current->getFilename());
if ($this->isExcluded($fileName) || $current->isFile()) {
return false;
}
if (!is_dir($current->getPathname() . '/Resources')) {
return true;
} else {
$file = $current->getPathname() . sprintf("/Resources/%s", $target);
if (is_file($file)) {
$paths[] = $file;
}
return false;
}
});
$iterator = new \RecursiveIteratorIterator($filter);
$iterator->rewind();
}
return $paths;
}
示例8: unlinkDirectory
private static function unlinkDirectory($path)
{
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
$iterator->rewind();
$files = array();
$directories = array();
foreach ($iterator as $path => $directory) {
if (is_file($path)) {
$files[] = $path;
} elseif (is_dir($path)) {
$directories[] = $path;
}
}
// Remove the files, then the directories
foreach ($files as $filePath) {
self::unlinkFile($filePath);
}
foreach ($directories as $dirPath) {
rmdir($dirPath);
}
// Finally, remove the path itself
if (is_dir($path)) {
rmdir($path);
}
}
示例9: testRecursiveIterator
public function testRecursiveIterator()
{
$document = $this->createDocument();
$iterator = new RecursiveDomIterator($document);
$iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
$iterator->rewind();
$this->assertEquals('html', $iterator->current()->tagName);
$iterator->next();
$this->assertEquals('head', $iterator->current()->tagName);
$iterator->next();
$this->assertEquals('title', $iterator->current()->tagName);
$iterator->next();
$this->assertEquals('Hello World', $iterator->current()->textContent);
$iterator->next();
$this->assertEquals('body', $iterator->current()->tagName);
$iterator->next();
$this->assertEquals('div', $iterator->current()->tagName);
$iterator->next();
$this->assertEquals('p', $iterator->current()->tagName);
$iterator->next();
$this->assertEquals('foo', $iterator->current()->textContent);
$iterator->next();
$this->assertEquals('div', $iterator->current()->tagName);
$iterator->next();
$this->assertEquals('p', $iterator->current()->tagName);
$iterator->next();
$this->assertEquals('bar', $iterator->current()->textContent);
}
示例10: rmdir
public function rmdir($path) {
if (!$this->isDeletable($path)) {
return false;
}
try {
$it = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->getSourcePath($path)),
\RecursiveIteratorIterator::CHILD_FIRST
);
/**
* RecursiveDirectoryIterator on an NFS path isn't iterable with foreach
* This bug is fixed in PHP 5.5.9 or before
* See #8376
*/
$it->rewind();
while ($it->valid()) {
/**
* @var \SplFileInfo $file
*/
$file = $it->current();
if (in_array($file->getBasename(), array('.', '..'))) {
$it->next();
continue;
} elseif ($file->isDir()) {
rmdir($file->getPathname());
} elseif ($file->isFile() || $file->isLink()) {
unlink($file->getPathname());
}
$it->next();
}
return rmdir($this->getSourcePath($path));
} catch (\UnexpectedValueException $e) {
return false;
}
}
示例11: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
global $CFG;
$tmpdir = $CFG->tempdir;
// Default to last weeks time.
$time = strtotime('-1 week');
$dir = new \RecursiveDirectoryIterator($tmpdir);
// Show all child nodes prior to their parent.
$iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$node = $iter->getRealPath();
if (!is_readable($node)) {
continue;
}
// Check if file or directory is older than the given time.
if ($iter->getMTime() < $time) {
if ($iter->isDir() && !$iter->isDot()) {
// Don't attempt to delete the directory if it isn't empty.
if (!glob($node . DIRECTORY_SEPARATOR . '*')) {
if (@rmdir($node) === false) {
mtrace("Failed removing directory '{$node}'.");
}
}
}
if ($iter->isFile()) {
if (@unlink($node) === false) {
mtrace("Failed removing file '{$node}'.");
}
}
}
}
}
示例12: endChildren
function endChildren()
{
global $count;
echo $this->getDepth();
if (--$count > 0) {
// Trigger use-after-free
parent::rewind();
}
}
示例13: countThemePages
protected function countThemePages($path)
{
$result = 0;
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
$it->setMaxDepth(1);
$it->rewind();
while ($it->valid()) {
if (!$it->isDot() && !$it->isDir() && $it->getExtension() == 'htm') {
$result++;
}
$it->next();
}
return $result;
}
示例14: delete
public function delete()
{
if (!$this->loadData()) {
$this->dataError();
sendBack();
}
$moduleobject = $this->_uses[$this->modeltype];
$db = DB::Instance();
$db->StartTrans();
if ($moduleobject->isLoaded()) {
$modulename = $moduleobject->name;
$modulelocation = FILE_ROOT . $moduleobject->location;
if ($moduleobject->enabled && !$moduleobject->disable()) {
$errors[] = 'Failed to disable module';
}
if ($moduleobject->registered && !$moduleobject->unregister()) {
$errors[] = 'Failed to unregister module';
}
if (!$moduleobject->delete()) {
$errors[] = 'Failed to delete module';
} else {
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($modulelocation), RecursiveIteratorIterator::CHILD_FIRST);
for ($dir->rewind(); $dir->valid(); $dir->next()) {
if ($dir->isDir()) {
rmdir($dir->getPathname());
} else {
unlink($dir->getPathname());
}
}
rmdir($modulelocation);
}
} else {
$errors[] = 'Cannot find module';
}
$flash = Flash::Instance();
if (count($errors) > 0) {
$db->FailTrans();
$flash->addErrors($errors);
if (isset($this->_data['id'])) {
$db->CompleteTrans();
sendTo($this->name, 'view', $this->_modules, array('id' => $this->_data['id']));
}
} else {
$flash->addMessage('Module ' . $modulename . ' deleted OK');
}
$db->CompleteTrans();
sendTo($this->name, 'index', $this->_modules);
}
示例15: suite
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('Test Suite');
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/Test'));
for ($it->rewind(); $it->valid(); $it->next()) {
// Something like: Test\Application\Modules\Main\Controllers\Index.php
$path = "Test\\" . $it->getInnerIterator()->getSubPathname();
// Replace all of the \ with _
$className = str_replace('\\', "_", $path);
// Take off the extension
$className = substr($className, 0, -4);
require_once $path;
$suite->addTestSuite($className);
}
return $suite;
}