/** * get callable module list * * @return array */ public function getCallableModules() { $dirIterator = new \RecursiveDirectoryIterator($this->path, \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::SKIP_DOTS); $modules = array(); foreach ($dirIterator as $k => $v) { $doVotedModule = false; if ($dirIterator->hasChildren()) { foreach ($dirIterator->getChildren() as $key => $value) { $entension = $value->getExtension(); if (!$entension || 'php' !== $entension) { continue; } $fileBasename = $value->getBasename('.php'); $module_to_be = $v->getBasename(); $expectedClassName = $this->baseNamespace . NAMESPACE_SEPARATOR . $module_to_be . NAMESPACE_SEPARATOR . $fileBasename; Loader::getInstance()->import($value->__toString()); if (!class_exists($expectedClassName, false)) { // not a standard class file! continue; } if (!$doVotedModule) { $modules[] = $module_to_be; $doVotedModule = true; } } } } return $modules; }
/** * @return mixed object * * @throws AccessDeniedException */ public function getChildren() { try { return parent::getChildren(); } catch (\UnexpectedValueException $e) { throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e); } }
/** Override of getChildren in \RecursiveDirectoryIterator, to skip directories with insufficient rights to access * @internal */ function getChildren() { try { return parent::getChildren(); } catch (\UnexpectedValueException $e) { return new \RecursiveArrayIterator(array()); } }
public function getChildren() { $children = parent::getChildren(); if (is_object($children)) { echo get_class($children) . " {$children}\n"; } else { echo gettype($children) . " {$children}\n"; } return $children; }
/** * @return \RecursiveIterator * * @throws AccessDeniedException */ public function getChildren() { try { return parent::getChildren(); } catch (\UnexpectedValueException $e) { if ($this->ignoreUnreadableDirs) { // If directory is unreadable and finder is set to ignore it, a fake empty content is returned. return new \RecursiveArrayIterator(array()); } else { throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e); } } }
public function getChildren() { try { $children = parent::getChildren(); if ($children instanceof self) { $children->skipUnreadable = $this->skipUnreadable; } return $children; } catch (\UnexpectedValueException $e) { if ($this->skipUnreadable) { return new \RecursiveArrayIterator(array()); } else { throw new \Reea\FileSearcher\Bundle\Exceptions\AccessDeniedException(); } } }
public function getChildren() { try { $children = parent::getChildren(); if ($children instanceof self) { $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs; } return $children; } catch (\UnexpectedValueException $e) { if ($this->ignoreUnreadableDirs) { return new \RecursiveArrayIterator(array()); } else { throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e); } } }
/** * import * * @param string $tsvDirPath * @access public * @return void */ public function import($tsvDirPath = null) { if (is_null($tsvDirPath)) { $tsvDirPath = realpath(__DIR__ . '/../../../../../../masterData'); } $iterator = new \RecursiveDirectoryIterator($tsvDirPath); foreach ($iterator as $file) { if (!$iterator->hasChildren()) { continue; } $databaseName = $file->getFileName(); $con = $this->getConnection($databaseName); $con->exec('set foreign_key_checks = 0'); $this->importFromTsvInDir($iterator->getChildren(), $con); $con->exec('set foreign_key_checks = 1'); } }
/** * @return \RecursiveIterator * * @throws AccessDeniedException */ public function getChildren() { try { $children = parent::getChildren(); if ($children instanceof self) { // parent method will call the constructor with default arguments, so unreadable dirs won't be ignored anymore $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs; } return $children; } catch (\UnexpectedValueException $e) { if ($this->ignoreUnreadableDirs) { // If directory is unreadable and finder is set to ignore it, a fake empty content is returned. return new \RecursiveArrayIterator(array()); } else { throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e); } } }
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(); } }
/** * @return RecursiveIterator * * @throws (ehough_finder_exception_AccessDeniedException */ public function getChildren() { try { $children = parent::getChildren(); if ($children instanceof self) { // parent method will call the constructor with default arguments, so unreadable dirs won't be ignored anymore $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs; // performance optimization to avoid redoing the same work in all children $children->rewindable =& $this->rewindable; $children->rootPath = $this->rootPath; } return $children; } catch (UnexpectedValueException $e) { if ($this->ignoreUnreadableDirs) { // If directory is unreadable and finder is set to ignore it, a fake empty content is returned. return new RecursiveArrayIterator(array()); } else { if (version_compare(PHP_VERSION, '5.3') >= 0) { throw new ehough_finder_exception_AccessDeniedException($e->getMessage(), $e->getCode(), $e); } throw new ehough_finder_exception_AccessDeniedException($e->getMessage(), $e->getCode()); } } }
/** * Data provider for testExamples method. * * Assumes that an `examples` directory exists inside parent directory. * This examples directory should contain any number of subdirectories, each of which contains * three files: one Mustache class (.php), one Mustache template (.mustache), and one output file * (.txt). * * This whole mess will be refined later to be more intuitive and less prescriptive, but it'll * do for now. Especially since it means we can have unit tests :) * * @access public * @return array */ public function getExamples() { $basedir = dirname(__FILE__) . '/../examples/'; $ret = array(); $files = new RecursiveDirectoryIterator($basedir); while ($files->valid()) { if ($files->hasChildren() && ($children = $files->getChildren())) { $example = $files->getSubPathname(); $class = null; $template = null; $output = null; foreach ($children as $file) { if (!$file->isFile()) { continue; } $filename = $file->getPathInfo(); $info = pathinfo($filename); switch ($info['extension']) { case 'php': $class = $info['filename']; include_once $filename; break; case 'mustache': $template = file_get_contents($filename); break; case 'txt': $output = file_get_contents($filename); break; } } $ret[$example] = array($class, $template, $output); } $files->next(); } return $ret; }
/** * Load all Command files from $path directory. * * Traverse all files inside specified directory, but loads only those files with suffix 'Command.php'. * * @param string $path Directory with Command files * @param string|null $prefix Commands namespace * * @return void */ public function loadCommands($path, $prefix = null) { // load commands try { $iterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO); /** @var \RecursiveDirectoryIterator $child */ foreach ($iterator->getChildren() as $child) { if ($child->isFile() && \preg_match('/Command.php$/', $child->getBasename())) { $namespace = $class = ""; $gettingNamespace = $gettingClass = false; foreach (\token_get_all(\file_get_contents($child->getRealPath())) as $token) { if (\is_array($token) && ($token[0] === T_ABSTRACT || $token[0] === T_INTERFACE)) { $namespace = $class = ''; break; } if (\is_array($token) && $token[0] === T_NAMESPACE) { $gettingNamespace = true; } if (\is_array($token) && $token[0] === T_CLASS) { $gettingClass = true; } if ($gettingNamespace === true) { if (\is_array($token) && \in_array($token[0], [T_STRING, T_NS_SEPARATOR])) { $namespace .= $token[1]; } else { if ($token === ';') { $gettingNamespace = false; } } } if ($gettingClass === true) { if (\is_array($token) && $token[0] === T_STRING) { $class = $token[1]; break; } } } $className = $namespace ? $namespace . '\\' . $class : $class; if (\preg_match('/Command$/', $className) > 0) { // make sure file with class is loaded require_once $child->getRealPath(); /** @var Command $command */ $command = new $className(); if ($prefix !== null) { $command->setName($prefix . ':' . $command->getName()); } $this['console']->add($command); } } } } catch (\UnexpectedValueException $ex) { // do nothing - no commands to load } }
/** * (PHP 5 >= 5.1.0)<br/> * Return the inner iterator's children contained in a RecursiveFilterIterator * * @link http://php.net/manual/en/recursivefilteriterator.getchildren.php * @return \RecursiveFilterIterator containing the inner iterator's children. */ public function getChildren() { return new self($this->iterator->getChildren(), $this->excluded); }
/** * Recursively convert RecursiveDirectoryIterator to array * * @param \RecursiveDirectoryIterator $tree * @param string $path * @return array */ protected function toArray(\RecursiveDirectoryIterator $tree, $path) { $array = array(); $types = array(); $names = array(); foreach ($tree as $file) { if (strpos($file->getFileName(), '.') === 0) { continue; } $types[] = (int) $file->isDir(); $names[] = $file->getFileName(); $array[] = $entry = array('type' => $file->isDir() ? 'folder' : 'file', 'name' => $file->getFileName(), 'path' => $localPath = str_replace($this->source, '', $file->getPath() . '/' . $file->getFileName()), 'children' => $tree->hasChildren() ? $this->toArray($tree->getChildren(), $path) : array(), 'state' => strpos($path, $localPath) === 0 ? 'open' : 'close'); } array_multisort($types, SORT_NUMERIC, SORT_DESC, $names, SORT_STRING, SORT_ASC, $array); return $array; }
?> </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); } else { $items[] = array('label' => $folder_name, 'items' => $tmp, 'itemOptions' => array('class' => 'nav-header')); } } //foreach (Documentation::model()->orderByLft()->findAll() as $doc) //{ // if ($doc->depth == 1)
/** * @param \RecursiveDirectoryIterator $dir * @param $namenamespaceFrom * @param $namenamespaceTo */ private function changeNamenamespaceModel(\RecursiveDirectoryIterator $dir, $namenamespaceFrom, $namenamespaceTo) { $namenamespaceFromRgx = preg_quote($namenamespaceFrom, "%"); foreach ($dir as $fileinfo) { if (!in_array($fileinfo->getFilename(), ['.', '..'])) { if (!$dir->hasChildren()) { $content = file_get_contents($fileinfo->getPathname()); $content = preg_replace("%{$namenamespaceFromRgx}%", $namenamespaceTo, $content); file_put_contents($fileinfo->getPathname(), $content); } else { $dirInner = $dir->getChildren(); $this->changeNamenamespaceModel($dirInner, $namenamespaceFrom, $namenamespaceTo); } } } }
/** * Recursive directory function. * * @param RecursiveDirectoryIterator $iterator */ protected function _recurseDirectory($iterator) { while ($iterator->valid()) { if ($iterator->isDir() && !$iterator->isDot()) { if ($iterator->hasChildren()) { $this->_recurseDirectory($iterator->getChildren()); } } elseif ($iterator->isFile()) { $path = $iterator->getPath() . '/' . $iterator->getFilename(); $pathinfo = pathinfo($path); if ($this->_isPhpFile($path)) { $this->addFile($path); } } $iterator->next(); } }
$iterator = new RecursiveDirectoryIterator($formImportDir); while ($iterator->valid()) { if ($iterator->isFile()) { $ext = pathinfo($iterator->getPathname(), PATHINFO_EXTENSION); if ($ext == "xml") { // echo $prefix,$j," import ",$dirIterator->getPathname(), "<br>\n"; $xmlForms["form"][$iterator->getFilename()] = $iterator->getPathname(); } else { $filepath = preg_replace("/" . preg_replace("/\\//", "\\\\/", HEURIST_UPLOAD_DIR) . "/", "/", $iterator->getPathname()); // echo $prefix,$j," resource ".$dirIterator->getFilename()." has path ".$filepath, "<br>\n"; $xmlForms["resource"][$iterator->getFilename()] = $filepath; } } else { if ($iterator->isDir() && $iterator->hasChildren(false)) { // echo $i,pathinfo($iterator->getPathname(),PATHINFO_FILENAME), "<br>\n"; processChildDir($iterator->getChildren(), $i . "-"); } } $iterator->next(); $i++; } } else { echo "something is wrong"; } foreach ($xmlForms["form"] as $filename => $path) { list($rtyName, $headers, $row) = parseImportForm($filename, $xmlForms["resource"]); $rtyName = "" . $rtyName; if (!$rtyName) { continue; } if (!array_key_exists($rtyName, $importData)) {
/** * * 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; } } }
/** * Get children. * Please, see \RecursiveDirectoryIterator::getChildren() method. * * @return mixed */ public function getChildren() { self::$_handlePath = $this->getRelativePath(); $out = parent::getChildren(); if ($out instanceof \RecursiveDirectoryIterator) { $out->setSplFileInfoClass($this->_splFileInfoClass); } return $out; }
protected function parseDirectory(\RecursiveDirectoryIterator $iterator) { $page_tree = array(); foreach ($iterator as $file) { $item = NULL; if ($file->isFile() && strpos($file->getFilename(), '.') !== 0) { $uriProvider = new \stdClass(); // TEMP $item = new Page($file->getPathname(), $this->pages_path, $this->app['uri']->string(), (array) $this->app['config']); $this->route_map[$item->url] = $item; if ($item->id) { $this->id_map[$item->id] = $item; } } elseif ($iterator->hasChildren()) { $uriProvider = new \stdClass(); // TEMP $item = new Directory($file->getPathname(), $this->pages_path, $this->app['uri']->segments(), (array) $this->app['config']); $children = $this->parseDirectory($iterator->getChildren()); $item->add_children($children); $this->dir_map[$item->url] = $item; } if ($item) { $page_tree[] = $item; } } uasort($page_tree, function ($a, $b) { return strnatcasecmp($a->fs_path, $b->fs_path); }); return $page_tree; }
/** * Рекурсивная функция для копирования директории со всеми * вложенными элементами. * * @param RecursiveDirectoryIterator $iterator * @param string $pathDestDir * @param integer $dirmode * @param integer $filemode * @throws System_FSException */ private function coping(\RecursiveDirectoryIterator $iterator, $pathDestDir, $copyMode = CopyMode::SKIP_EXISTING, $dirmode = 0755, $filemode = 0644) { foreach ($iterator as $fileinfo) { $destDir = new FileInfo($pathDestDir . '/' . $fileinfo->getBasename()); if ($iterator->hasChildren()) { if ($destDir->isLink() || $destDir->isFile()) { throw new Exception\UnexpectedValueException(); } elseif (!$destDir->isDir()) { $destDir->controlDirectory()->create($dirmode); } $this->coping($iterator->getChildren(), $destDir->getRealPath(), $dirmode, $filemode); } elseif ($fileinfo->isLink()) { $fileinfo->openLink()->copyTo($destDir->getRealPath(), $copyMode); } elseif ($fileinfo->isFile()) { $fileinfo->openFile()->copyTo($destDir->getRealPath(), $copyMode); } } }
private function findSnippets(\RecursiveDirectoryIterator $dir = null, $prefix = '') { if (!isset($dir)) { if (!is_dir($this->p('app/Snippets'))) { return array(); } $dir = new \RecursiveDirectoryIterator($this->p('app/Snippets')); } $snippets = array(); foreach ($dir as $file) { if ($dir->hasChildren()) { $snippets = array_merge($snippets, $this->findSnippets($dir->getChildren(), $file->getFilename() . '\\')); } else { if ($file->isFile()) { if (preg_match('/^(.+)\\.php$/', $file->getFilename(), $matches) === 1) { $snippets[] = $prefix . $matches[1]; } } } } return $snippets; }