/** * 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'])); } } }
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); }
/** * 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); }
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)); } }
public function rmdir($path) { try { $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->buildPath($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(); } if ($result = @rmdir($this->buildPath($path))) { $this->cleanMapper($path); } return $result; } catch (\UnexpectedValueException $e) { return false; } }
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; }
/** * 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]); } } } }
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; }
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; }
/** * 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'); }
/** * 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}'."); } } } } }
/** * @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; } }
/** * @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; }
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; } }
/** * Moves to next item in structure. * Respects filter. */ public function next() { do { $this->iterated->attach($this->current()); parent::next(); } while ($this->valid() && (!$this->passes($this->current()) || $this->iterated->contains($this->current()))); }
/** * 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; }
/** * 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; }
/** * Executes this task. */ public function main() { if ($this->property === null) { throw new BuildException('The property attribute must be specified'); } if ($this->path === null) { throw new BuildException('The path attribute must be specified'); } $check = new AgaviModuleFilesystemCheck(); $check->setConfigDirectory($this->project->getProperty('module.directory.config')); $check->setPath($this->path->getAbsolutePath()); if (!$check->check()) { throw new BuildException('The path attribute must be a valid module base directory'); } $actions = array(); $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path->getAbsolutePath() . DIRECTORY_SEPARATOR . $this->project->getProperty('module.directory.actions'))); for (; $iterator->valid(); $iterator->next()) { $rdi = $iterator->getInnerIterator(); if ($rdi->isDot() || !$rdi->isFile()) { continue; } $file = $rdi->getSubpathname(); if (preg_match('#Action\\.class\\.php$#', $file)) { $actions[] = str_replace(DIRECTORY_SEPARATOR, '.', substr($file, 0, -16)); } } $list = new AgaviArraytostringTransform(); $list->setInput($actions); $list->setDelimiter(' '); $this->project->setUserProperty($this->property, $list->transform()); }
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); } }
/** * Execute the command. * * @return void * * @since 1.0 */ public function execute() { $this->getApplication()->outputTitle('Make Documentation'); $this->usePBar = $this->getApplication()->get('cli-application.progress-bar'); if ($this->getApplication()->input->get('noprogress')) { $this->usePBar = false; } $this->github = $this->getContainer()->get('gitHub'); $this->getApplication()->displayGitHubRateLimit(); /* @type \Joomla\Database\DatabaseDriver $db */ $db = $this->getContainer()->get('db'); $docuBase = JPATH_ROOT . '/Documentation'; /* @type \RecursiveDirectoryIterator $it */ $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($docuBase, \FilesystemIterator::SKIP_DOTS)); $this->out('Compiling documentation in: ' . $docuBase)->out(); $table = new ArticlesTable($db); // @todo compile the md text here. $table->setGitHub($this->github); while ($it->valid()) { if ($it->isDir()) { $it->next(); continue; } $file = new \stdClass(); $file->filename = $it->getFilename(); $path = $it->getSubPath(); $page = substr($it->getFilename(), 0, strrpos($it->getFilename(), '.')); $this->debugOut('Compiling: ' . $page); $table->reset(); $table->{$table->getKeyName()} = null; try { $table->load(array('alias' => $page, 'path' => $path)); } catch (\RuntimeException $e) { // New item } $table->is_file = '1'; $table->path = $it->getSubPath(); $table->alias = $page; $table->text_md = file_get_contents($it->key()); $table->store(); $this->out('.', false); $it->next(); } $this->out()->out('Finished =;)'); }
public function testIterate() { $sitemap = new Sitemap("h-1", "home", null); $n1 = $sitemap->getRoot()->addChild(new Node("h-1-1", "n1", null)); $n2 = $n1->addChild(new Node("h-1-1-1", "n2", null)); $n3 = $n1->addChild(new Node("h-1-1-2", "n3", null)); $it = new \RecursiveIteratorIterator($sitemap->getIterator(), \RecursiveIteratorIterator::SELF_FIRST); $it->rewind(); $this->assertEquals($sitemap->getRoot(), $it->current(), "Se esperaba que el primer elemento del iterador sea la raiz."); $it->next(); $this->assertEquals($n1, $it->current(), "Se esperaba que el segundo elemento del iterador sea el primer hijo de la raiz."); $it->next(); $this->assertEquals($n2, $it->current(), "Se esperaba que el tercer elemento del iterador sea el primer hijo del primer hijo de la raiz."); $it->next(); $this->assertEquals($n3, $it->current(), "Se esperaba que el cuarto elemento del iterador sea el segundo hijo del primer hijo de la raiz."); $it->next(); $this->assertFalse($it->valid(), "Se esperaba que el luego del cuarto elemento el iterador quede inválido."); }
function next() { parent::next(); $x = $this->current(); if (isset($x[0])) { parent::next(); $x = $this->current(); } }
/** * After the call to next() if depth is bigger than limit then * just skip all subIterators for that depth until depth end. * **/ public function next() { parent::next(); if ($this->getDepth() == $this->depth_limit) { while ($this->getSubIterator()->valid()) { $this->getSubIterator()->next(); } parent::next(); } }
function directoryClear($path) { if (!file_exists($path)) { return; } $it = new RecursiveIteratorIterator(new eraserIterator($path), RecursiveIteratorIterator::CHILD_FIRST); while ($it->valid()) { $it->erase(); $it->next(); } }
public static function GetDirectoryContent($Directory) { $Iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($Directory)); $FilesArray = array(); while ($Iterator->valid()) { if (!$Iterator->isDot()) { $FilesArray[] = array('FileLink' => $Iterator->key(), 'FileName' => $Iterator->getSubPathName()); } $Iterator->next(); } return $FilesArray; }
public static function DirectoryContent($Directory, $UserLanguage) { $ReadDirectory = $Directory . str_replace('.language', '', $UserLanguage); $Iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($ReadDirectory)); $FilesArray = array(); while ($Iterator->valid()) { if (!$Iterator->isDot()) { $FilesArray[] = array('FileLink' => $Iterator->key(), 'FileName' => $Iterator->getSubPathName(), 'SmallFileName' => strtolower(str_replace('.language', '', $Iterator->getSubPathName())), 'LinesCount' => File::CountLines($Iterator->key())); } $Iterator->next(); } return $FilesArray; }
protected function countThemePages($path) { $result = 0; $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); $it->setMaxDepth(1); while ($it->valid()) { if (!$it->isDot() && !$it->isDir() && $it->getExtension() == 'htm') { $result++; } $it->next(); } return $result; }
public static function addTestDirectoryRecursive(PHPUnit_Framework_TestSuite $suite, $directory) { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); while ($it->valid()) { if (!$it->isDot()) { $file = $it->key(); if (preg_match('|Test\\.php$|', $file) && $file !== __FILE__) { $suite->addTestFile($file); } } $it->next(); } }
/** * Executes the transformation process. * * @throws Zend_Console_Getopt_Exception * * @return void */ public function execute() { $results = array(); $longest_name = 0; /** @var RecursiveDirectoryIterator $files */ $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/../')); while ($files->valid()) { // skip abstract files if (!$files->isFile() || $files->getBasename() == 'Abstract.php') { $files->next(); continue; } // convert the filename to a class $class_name = 'DocBlox_Task_' . str_replace(DIRECTORY_SEPARATOR, '_', $files->getSubPath()) . '_' . $files->getBasename('.php'); // check if the class exists, if so: add it to the list if (class_exists($class_name)) { $name = $files->getBasename('.php'); $longest_name = max(strlen($name), $longest_name); $results[strtolower($files->getSubPath())][strtolower($name)] = $files->getRealPath(); } $files->next(); } // echo the list of namespaces with their tasks ksort($results, SORT_STRING); foreach ($results as $namespace => $tasks) { echo $namespace . PHP_EOL; asort($tasks, SORT_STRING); foreach ($tasks as $task => $filename) { // get the short description by reflecting the file. $refl = new DocBlox_Reflection_File($filename, false); $refl->setLogLevel(DocBlox_Core_Log::QUIET); $refl->process(); /** @var DocBlox_Reflection_Class $class */ $class = current($refl->getClasses()); echo ' :' . str_pad($task, $longest_name + 2) . $class->getDocBlock()->getShortDescription() . PHP_EOL; } } echo PHP_EOL; }
protected function execute($arguments = array(), $options = array()) { switch (strtolower($arguments['scm'])) { case 'git': $ignoreFileName = '.gitignore'; $forceAddIgnoreFileCommand = "git add -f "; break; case 'cvs': $ignoreFileName = '.cvsignore'; $forceAddIgnoreFileCommand = "cvs add "; break; default: echo "Not a support SCM. Only GIT and CVS are currently supported."; exit(1); } // config folder ignores $currentIgnore = 'config/' . $ignoreFileName; $ignoreFiles = "ProjectConfiguration.class.php\ndatabases.yml\n"; $this->writeIgnore($currentIgnore, $ignoreFiles, $options['add-ignores'], $forceAddIgnoreFileCommand); // Cache folder $currentIgnore = 'cache/' . $ignoreFileName; $ignoreFiles = "*\n"; $this->writeIgnore($currentIgnore, $ignoreFiles, $options['add-ignores'], $forceAddIgnoreFileCommand); // Log folder $currentIgnore = 'log/' . $ignoreFileName; $ignoreFiles = "*\n"; $this->writeIgnore($currentIgnore, $ignoreFiles, $options['add-ignores'], $forceAddIgnoreFileCommand); // Begin the looping through $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(sfConfig::get('sf_root_dir'))); $ignorePathArray = array(); while ($it->valid()) { // Does it match a model/om, model/map, form/base, filter/base $path = str_replace(DIRECTORY_SEPARATOR, '/', $it->getPath()); if (strpos($path, 'model/om') || strpos($path, 'model/map') || strpos($path, 'form/base') || strpos($path, 'filter/base') || strpos($path, 'doctrine/base') || strpos($path, 'Plugin/base')) { // Since we currently go through every file we only want to get the path once so use it as the key. $ignorePathArray[$it->getPath()] = true; } $it->next(); } // Write the actual ignores to all the found paths foreach ($ignorePathArray as $path => $value) { $currentIgnore = $path . '/' . $ignoreFileName; $ignoreFiles = "*\n"; $this->writeIgnore($currentIgnore, $ignoreFiles, $options['add-ignores'], $forceAddIgnoreFileCommand); } if ($options['add-ignores']) { echo "All set, ignores created and added!\n"; } else { echo "All set, ignores created!\n"; } }