当前位置: 首页>>代码示例>>PHP>>正文


PHP RecursiveIteratorIterator::valid方法代码示例

本文整理汇总了PHP中RecursiveIteratorIterator::valid方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveIteratorIterator::valid方法的具体用法?PHP RecursiveIteratorIterator::valid怎么用?PHP RecursiveIteratorIterator::valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RecursiveIteratorIterator的用法示例。


在下文中一共展示了RecursiveIteratorIterator::valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: main

 /**
  * Executes this task.
  */
 public function main()
 {
     if ($this->path === null) {
         throw new BuildException('The path attribute must be specified');
     }
     $check = new AgaviModuleFilesystemCheck();
     $check->setConfigDirectory($this->project->getProperty('module.config.directory'));
     $check->setPath($this->path->getAbsolutePath());
     if (!$check->check()) {
         throw new BuildException('The path attribute must be a valid module base directory');
     }
     /* We don't know whether the module is configured or not here, so load the
      * values we want properly. */
     $this->tryLoadAgavi();
     $this->tryBootstrapAgavi();
     require_once AgaviConfigCache::checkConfig(sprintf('%s/%s/module.xml', $this->path->getAbsolutePath(), (string) $this->project->getProperty('module.config.directory')));
     $actionPath = AgaviToolkit::expandVariables(AgaviToolkit::expandDirectives(AgaviConfig::get(sprintf('modules.%s.agavi.action.path', strtolower($this->path->getName())), '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php')), array('moduleName' => $this->path->getName()));
     $pattern = '#^' . AgaviToolkit::expandVariables(str_replace('\\$\\{actionName\\}', '${actionName}', preg_quote($actionPath, '#')), array('actionName' => '(?P<action_name>.*?)')) . '$#';
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path->getAbsolutePath()));
     for (; $iterator->valid(); $iterator->next()) {
         $rdi = $iterator->getInnerIterator();
         if ($rdi->isDot() || !$rdi->isFile()) {
             continue;
         }
         $file = $rdi->getPathname();
         if (preg_match($pattern, $file, $matches)) {
             $this->log(str_replace(DIRECTORY_SEPARATOR, '.', $matches['action_name']));
         }
     }
 }
开发者ID:horros,项目名称:agavi,代码行数:33,代码来源:AgaviDisplayactionsTask.php

示例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]);
             }
         }
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:53,代码来源:file_temp_cleanup_task.php

示例3: findDirectories

 public static function findDirectories($rootDir, $multiMap = true)
 {
     if (!is_dir($rootDir)) {
         throw new \LogicException($rootDir . ' is not a directory');
     }
     $elements = array();
     $d = @dir($rootDir);
     if (!$d) {
         throw new \LogicException('Directory is not readable');
     }
     $dirs = array();
     $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootDir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
     while ($it->valid()) {
         if (!$it->isDir()) {
             $it->next();
         } else {
             $cur = $it->current();
             if ($cur->isDir()) {
                 if ($multiMap) {
                     $dirs[$cur->getPath()][] = $cur->getFilename();
                 } else {
                     $dirs[] = $cur->getPath();
                 }
             }
             $it->next();
         }
     }
     return $dirs;
 }
开发者ID:shenlu2011,项目名称:Hub-master,代码行数:29,代码来源:Util.php

示例4: getFile

 /**
  * @param $path
  * @return mixed|string
  */
 private function getFile($path)
 {
     $returnView = $this->viewFolder . $path . '.php';
     if (!file_exists($returnView)) {
         $dir = $path;
         $dir = explode('/', $dir);
         unset($dir[count($dir) - 1]);
         $dir = implode('/', $dir);
         $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->viewFolder . $dir));
         while ($it->valid()) {
             if (!$it->isDot()) {
                 $cache['SelectView'] = strrev($path);
                 $cache['SelectView'] = explode("/", $cache['SelectView'])[0];
                 $cache['SelectView'] = strrev($cache['SelectView']);
                 $cache['ReturnView'] = explode(".", $it->key());
                 unset($cache['ReturnView'][count($cache['ReturnView']) - 1]);
                 $cache['ReturnView'] = implode('.', $cache['ReturnView']);
                 $cache['ReturnView'] = explode("\\", $cache['ReturnView']);
                 $cache['ReturnView'] = $cache['ReturnView'][count($cache['ReturnView']) - 1];
                 if ($cache['ReturnView'] == $cache['SelectView']) {
                     $returnView = $it->key();
                 }
             }
             $it->next();
         }
         if (!isset($returnView)) {
             die('Can not find a file matching these arguments: getView("' . $this->getPath($path, TRUE) . '")');
         }
         return $returnView;
     }
 }
开发者ID:dashomeradio,项目名称:framework,代码行数:35,代码来源:View.php

示例5: recursive_rmdir

 private function recursive_rmdir($dirname, $followLinks = false)
 {
     if (is_dir($dirname) && !is_link($dirname)) {
         if (!is_writable($dirname)) {
             throw new Exception('You do not have renaming permissions!');
         }
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname), RecursiveIteratorIterator::CHILD_FIRST);
         while ($iterator->valid()) {
             if (!$iterator->isDot()) {
                 if (!$iterator->isWritable()) {
                     throw new Exception(sprintf('Permission Denied: %s.', $iterator->getPathName()));
                 }
                 if ($iterator->isLink() && false === (bool) $followLinks) {
                     $iterator->next();
                 }
                 if ($iterator->isFile()) {
                     unlink($iterator->getPathName());
                 } else {
                     if ($iterator->isDir()) {
                         rmdir($iterator->getPathName());
                     }
                 }
             }
             $iterator->next();
         }
         unset($iterator);
         // Fix for Windows.
         return rmdir($dirname);
     } else {
         throw new Exception(sprintf('Directory %s does not exist!', $dirname));
     }
 }
开发者ID:jadnx,项目名称:VulnerabilityAssessmentWebTool,代码行数:32,代码来源:FileManagerModel.php

示例6: getTestFiles

 /**
  * Get Test Files
  *
  * @param null $directory
  * @param null $excludes
  * @return array
  */
 public static function getTestFiles($directory = null, $excludes = null)
 {
     if (is_array($directory)) {
         $files = array();
         foreach ($directory as $d) {
             $files = array_merge($files, self::getTestFiles($d, $excludes));
         }
         return array_unique($files);
     }
     if ($excludes !== null) {
         $excludes = self::getTestFiles((array) $excludes);
     }
     if ($directory === null || $directory !== realpath($directory)) {
         $basePath = App::pluginPath('DebugKit') . 'Test' . DS . 'Case' . DS;
         $directory = str_replace(DS . DS, DS, $basePath . $directory);
     }
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
     $files = array();
     while ($it->valid()) {
         if (!$it->isDot()) {
             $file = $it->key();
             if (preg_match('|Test\\.php$|', $file) && $file !== __FILE__ && !preg_match('|^All.+?\\.php$|', basename($file)) && ($excludes === null || !in_array($file, $excludes))) {
                 $files[] = $file;
             }
         }
         $it->next();
     }
     return $files;
 }
开发者ID:SebFav,项目名称:ApplicationInternet2,代码行数:36,代码来源:DebugkitGroupTestCase.php

示例7: copyDir

 /**
  * @throws  \Seitenbau\FileSystem\FileSystemException
  */
 public static function copyDir($source, $destination)
 {
     if (!is_dir($source)) {
         throw new FileSystemException('Sourcedir "' . $source . '" does not exists');
     }
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
     if (!self::createDirIfNotExists($destination)) {
         return false;
     }
     // Verzeichnis rekursiv durchlaufen
     while ($iterator->valid()) {
         if (!$iterator->isDot()) {
             if ($iterator->current()->isDir()) {
                 // relativen Teil des Pfad auslesen
                 $relDir = str_replace($source, '', $iterator->key());
                 // Ziel-Verzeichnis erstellen
                 if (!self::createDirIfNotExists($destination . $relDir)) {
                     return false;
                 }
             } elseif ($iterator->current()->isFile()) {
                 $destinationFile = $destination . str_replace($source, '', $iterator->key());
                 if (!copy($iterator->key(), $destinationFile)) {
                     return false;
                 }
             }
         }
         $iterator->next();
     }
     return true;
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:33,代码来源:FileSystem.php

示例8: 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;
		}
	}
开发者ID:ninjasilicon,项目名称:core,代码行数:35,代码来源:local.php

示例9: get_directory_list

function get_directory_list($settings = false)
{
    $directory = !empty($settings['dir']) ? $settings['dir'] : CLIENT_DIR . "/";
    $array = array();
    $array['dirs'] = array();
    $array['host'] = array();
    $array['root'] = array();
    if (!is_dir($directory)) {
        return false;
    }
    $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST);
    // Loop through directories
    while ($dir->valid()) {
        try {
            $file = $dir->current();
            ob_start();
            echo $file;
            $data = ob_get_contents();
            ob_end_clean();
            $data = trim($data);
            if (basename($data) != '.' && basename($data) != '..') {
                $array['host'][] = $data;
                $array['root'][] = str_replace(ROOT_DIR, "", $data);
                if (is_dir($data) && !in_array($data . "/", $array['dirs'])) {
                    $array['dirs'][] = $data . "/";
                }
            }
            unset($data);
            $dir->next();
        } catch (UnexpectedValueException $e) {
            continue;
        }
    }
    return isset($array) ? $array : false;
}
开发者ID:rasclatt,项目名称:ZipEngine,代码行数:35,代码来源:function.get_directory_list.php

示例10: scanDir

 /**
  * Function to start a scan in a directory.
  * @return Array
  * @throws DirectoryNotFoundException
  */
 public static function scanDir($parentDirectory)
 {
     $occurences = array(array());
     //if the directory/file does not exists, then throw and error.
     if (!file_exists($parentDirectory)) {
         throw new DirectoryORFileNotFoundException("ERROR: Directory not found!");
     }
     //get the list of all the files inside this directory.
     $allFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($parentDirectory));
     $fileList = array();
     //remove (.), (..) and directories from the list of all files so that only files are left.
     while ($allFiles->valid()) {
         if (!$allFiles->isDot()) {
             if (!is_dir($allFiles->key())) {
                 array_push($fileList, $allFiles->key());
             }
         }
         $allFiles->next();
     }
     $i = 0;
     foreach ($fileList as $file) {
         if (pathinfo($file, PATHINFO_EXTENSION) != "php") {
             continue;
         }
         $occurences[$i]['file'] = realpath($file);
         $occurences[$i]['result'] = Scanner::scanFile($file);
         $i++;
     }
     return $occurences;
 }
开发者ID:sachintaware,项目名称:phpsec,代码行数:35,代码来源:scanner.php

示例11: rmdir

 /**
  * Remove recursively the directory named by dirname.
  *
  * @param string $dirname       Path to the directory
  * @param boolean $followLinks  Removes symbolic links if set to true
  * @return boolean              True if success otherwise false
  * @throws Exception            When the directory does not exist or permission denied
  */
 public static function rmdir($dirname, $followLinks = false)
 {
     if (!is_dir($dirname) && !is_link($dirname)) {
         throw new Exception(sprintf('Directory %s does not exist', $dirname));
     }
     if (!is_writable($dirname)) {
         throw new Exception('You do not have renaming permissions');
     }
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname), RecursiveIteratorIterator::CHILD_FIRST);
     while ($iterator->valid()) {
         if (!$iterator->isDot()) {
             if (!$iterator->isWritable()) {
                 throw new Exception(sprintf('Permission denied for %s', $iterator->getPathName()));
             }
             if ($iterator->isLink() && false === (bool) $followLinks) {
                 $iterator->next();
                 continue;
             }
             if ($iterator->isFile()) {
                 unlink($iterator->getPathName());
             } else {
                 if ($iterator->isDir()) {
                     rmdir($iterator->getPathName());
                 }
             }
         }
         $iterator->next();
     }
     unset($iterator);
     return rmdir($dirname);
 }
开发者ID:rom1git,项目名称:Centurion,代码行数:39,代码来源:System.php

示例12: assertDirContentsEquals

 protected function assertDirContentsEquals($expDir, $actDir)
 {
     if (!file_exists($expDir)) {
         throw new RuntimeException("Expected dir not found: " . $expDir);
     }
     if (!file_exists($actDir)) {
         throw new RuntimeException("Actual dir not found: " . $actDir);
     }
     $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($expDir));
     $expFiles = array();
     while ($dir->valid()) {
         if (!$dir->isDot()) {
             array_push($expFiles, $dir->getSubPathName());
         }
         $dir->next();
     }
     $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($actDir));
     $actFiles = array();
     while ($dir->valid()) {
         if (!$dir->isDot()) {
             array_push($actFiles, $dir->getSubPathName());
         }
         $dir->next();
     }
     $this->assertEquals($expFiles, $actFiles);
     foreach ($expFiles as $key => $value) {
         $expFile = file_get_contents($expDir . DIRECTORY_SEPARATOR . $value);
         $actFile = file_get_contents($expDir . DIRECTORY_SEPARATOR . $actFiles[$key]);
         $this->assertEquals($expFile, $actFile);
     }
 }
开发者ID:irfan-blackhawk,项目名称:XSD-to-PHP,代码行数:31,代码来源:LegkoXMLTestCase.php

示例13: 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');
 }
开发者ID:remotehelp,项目名称:weblinks,代码行数:37,代码来源:RoboFile.php

示例14: 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;
}
开发者ID:grevutiu-gabriel,项目名称:iqatest,代码行数:29,代码来源:array_flatten.php

示例15: 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;
     }
 }
开发者ID:one-more,项目名称:peach_framework,代码行数:33,代码来源:autoloader.php


注:本文中的RecursiveIteratorIterator::valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。