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"; } }
public function get_folders($directory) { $rows = array(); $iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), true); foreach ($iter as $file) { if ($iter->hasChildren() && !strstr($iter->getPath() . "/" . $file, "/.")) { $row['name'] = str_repeat(' ', $iter->getDepth()) . ucfirst(basename($file)); $row['path'] = $iter->getPath() . "/" . basename($file); $rows[] = $row; unset($row); } } return $rows; }
public function buildIndex() { $iterator = new RecursiveIteratorIterator(new contentTreeRecursiveIterator($this->toc), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $topic) { $path = ltrim($iterator->getPath() . '/' . $topic['href'], '\\/'); $this->indexPage($path, $topic['title']); } }
function rsearch($folder, $pattern) { $dir = new RecursiveDirectoryIterator($folder); $iterator = new RecursiveIteratorIterator($dir); $files = new RegexIterator($iterator, $pattern, RegexIterator::GET_MATCH); $fileList = array(); foreach ($files as $file) { $fileList[] = array('file' => $file, 'path' => $iterator->getPath()); } // return only the first result return $fileList[0]; }
function testRecursiveTreeItarator() { $structHolder = $this->getTestStructure(); $pathBuilder = new pathBuilder('/index.html'); $sectionData = $structHolder->getPageSection($pathBuilder, 'current'); $section = $sectionData['curSection']; $level = $sectionData['level']; $iterator = new RecursiveIteratorIterator(new contentTreeRecursiveIterator($section), RecursiveIteratorIterator::SELF_FIRST); $tocItems = array(); foreach ($iterator as $topic) { if ($level != -1 && $iterator->getDepth() > $level - 1) { continue; } $topic['href'] = ltrim($iterator->getPath() . '/' . $topic['href'], '\\/'); $topic['level'] = $iterator->getDepth(); $tocItems[] = $topic; } $this->assertEqual($tocItems, array(array('href' => 'introduction.html', 'title' => 'Введение', 'level' => 0), array('href' => 'installation.html', 'title' => 'Установка', 'level' => 0), array('href' => 'quickstart.html', 'title' => 'Простой пример', 'level' => 0), array('href' => 'content/index.html', 'title' => 'Книга', 'level' => 0), array('href' => 'content/bookshelf.html', 'title' => 'Книжная полка', 'level' => 1), array('href' => 'content/toc.html', 'title' => 'Структура', 'level' => 1), array('href' => 'content/text.html', 'title' => 'Текст', 'level' => 1), array('href' => 'layout/index.html', 'title' => 'Оформление', 'level' => 0), array('href' => 'layout/theme.html', 'title' => 'Темы', 'level' => 1), array('href' => 'layout/system_settings.html', 'title' => 'Системные настройки', 'level' => 1), array('href' => 'export.html', 'title' => 'Экспорт', 'level' => 0), array('href' => 'appendix/index.html', 'title' => 'Приложения', 'level' => 0), array('href' => 'appendix/topic_index.html', 'title' => 'Предметный указатель', 'level' => 1), array('href' => 'appendix/authors.html', 'title' => 'Авторы', 'level' => 1), array('href' => 'appendix/license.html', 'title' => 'Лицензия', 'level' => 1), array('href' => 'appendix/similar.html', 'title' => 'Аналоги', 'level' => 1), array('href' => 'appendix/roadmap.html', 'title' => 'Планы по развитию', 'level' => 1)), 'Correct data obtained'); }
public function buildTOC() { $pathBuilder = new pathBuilder('/'); $sectionData = $this->structureHolder->getPageSection($pathBuilder, 'current'); $section = $sectionData['curSection']; $level = 0; $iterator = new RecursiveIteratorIterator(new contentTreeRecursiveIterator($section), RecursiveIteratorIterator::SELF_FIRST); $file_list = ''; $html = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <HTML> <HEAD> <meta name="GENERATOR" content="Microsoft® HTML Help Workshop 4.1"> <!-- Sitemap 1.0 --> </HEAD><BODY><UL><LI><OBJECT type="text/sitemap"> <param name="Name" value="ќбложка"> <param name="Local" value="index.html"> </OBJECT>'; foreach ($iterator as $topic) { $href = ltrim($iterator->getPath() . '/' . $topic['href'], '\\/'); $file_list .= "{$href}\n"; $title = $topic['title']; if ($iterator->getDepth() > $level) { $html .= '<UL>'; $level = $iterator->getDepth(); } if ($iterator->getDepth() < $level) { $html .= '</UL>'; $level = $iterator->getDepth(); } $icon = basename($href) == 'index.html' ? '' : '<param name="ImageNumber" value="11">'; $html .= '<LI> <OBJECT type="text/sitemap"> <param name="Name" value="' . $title . '"> <param name="Local" value="' . $href . '"> ' . $icon . ' </OBJECT>'; } $html = $html . '</UL></BODY></HTML>'; $file_list = "[OPTIONS]\nCompatibility=1.1 or later\nCompiled file={$this->bookKey}.chm\nContents file={$this->bookKey}.hhc\nDefault Font=Verdana,8,204\nDefault topic=index.html\nDisplay compile progress=No\nIndex file={$this->bookKey}.hhk\nLanguage=" . colesoApplication::getMessage('bulldoc', 'chm_encoding') . "\nTitle={$this->bookTitle}\n\n\n[FILES]\n{$file_list}\n\n[INFOTYPES]\n\n"; return array($html, $file_list); }
/** * Retrieves a list of all available extensions on the filesystem * * @return array An array with extension names as keys and paths to the * extension as values */ public function all_available() { $available = array(); if (!is_dir($this->phpbb_root_path . 'ext/')) { return $available; } $iterator = new \RecursiveIteratorIterator(new \phpbb\recursive_dot_prefix_filter_iterator(new \RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/', \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::FOLLOW_SYMLINKS)), \RecursiveIteratorIterator::SELF_FIRST); $iterator->setMaxDepth(2); foreach ($iterator as $file_info) { if ($file_info->isFile() && $file_info->getFilename() == 'composer.json') { $ext_name = $iterator->getInnerIterator()->getSubPath(); $composer_file = $iterator->getPath() . '/composer.json'; // Ignore the extension if there is no composer.json. if (!is_readable($composer_file) || !($ext_info = file_get_contents($composer_file))) { continue; } $ext_info = json_decode($ext_info, true); $ext_name = str_replace(DIRECTORY_SEPARATOR, '/', $ext_name); // Ignore the extension if directory depth is not correct or if the directory structure // does not match the name value specified in composer.json. if (substr_count($ext_name, '/') !== 1 || !isset($ext_info['name']) || $ext_name != $ext_info['name']) { continue; } $available[$ext_name] = $this->phpbb_root_path . 'ext/' . $ext_name . '/'; } } ksort($available); return $available; }
private function buildIndex($pathBuilder) { $basePath = dirname((string) $pathBuilder); if ($basePath == '.') { $basePath = ''; } else { $basePath .= '/'; } $sectionData = $this->structureHolder->getPageSection($pathBuilder, 'current'); $section = $sectionData['curSection']; $level = $sectionData['level']; $iterator = new RecursiveIteratorIterator(new contentTreeRecursiveIterator($section), RecursiveIteratorIterator::SELF_FIRST); $html = ''; foreach ($iterator as $topic) { if ($level != -1 && $iterator->getDepth() > $level - 1) { continue; } $topic['href'] = ltrim($iterator->getPath() . '/' . $topic['href'], '\\/'); $topic['level'] = $iterator->getDepth(); $topic['path'] = $basePath . $topic['href']; $html .= $this->navTemplate->parseItem('toc_topic', $topic); } return $html; }