本文整理汇总了PHP中RecursiveDirectoryIterator::hasChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveDirectoryIterator::hasChildren方法的具体用法?PHP RecursiveDirectoryIterator::hasChildren怎么用?PHP RecursiveDirectoryIterator::hasChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveDirectoryIterator
的用法示例。
在下文中一共展示了RecursiveDirectoryIterator::hasChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCallableModules
/**
* 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;
}
示例2: import
/**
* 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');
}
}
示例3: load_tests
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();
}
}
示例4: getExamples
/**
* 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;
}
示例5: changeNamenamespaceModel
/**
* @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);
}
}
}
}
示例6: _recurseDirectory
/**
* 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();
}
}
示例7: findSnippets
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;
}
示例8: array
$xmlForms = array("form" => array(), "resource" => array());
if ($info->isDir()) {
$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;
示例9: _fetch
/**
*
* 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;
}
}
}
示例10: toArray
/**
* 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;
}
示例11: scanDirectory
/**
* Scans a given directory for class files.
*
* @param string $namespace_prefix
* The namespace prefix to use for discovered classes. Must contain a
* trailing namespace separator (backslash).
* For example: 'Drupal\\node\\Tests\\'
* @param string $path
* The directory path to scan.
* For example: '/path/to/drupal/core/modules/node/tests/src'
*
* @return array
* An associative array whose keys are fully-qualified class names and whose
* values are corresponding filesystem pathnames.
*
* @throws \InvalidArgumentException
* If $namespace_prefix does not end in a namespace separator (backslash).
*
* @todo Limit to '*Test.php' files (~10% less files to reflect/introspect).
* @see https://www.drupal.org/node/2296635
*/
public static function scanDirectory($namespace_prefix, $path)
{
if (substr($namespace_prefix, -1) !== '\\') {
throw new \InvalidArgumentException("Namespace prefix for {$path} must contain a trailing namespace separator.");
}
$flags = \FilesystemIterator::UNIX_PATHS;
$flags |= \FilesystemIterator::SKIP_DOTS;
$flags |= \FilesystemIterator::FOLLOW_SYMLINKS;
$flags |= \FilesystemIterator::CURRENT_AS_SELF;
$iterator = new \RecursiveDirectoryIterator($path, $flags);
$filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $key, $iterator) {
if ($iterator->hasChildren()) {
return TRUE;
}
return $current->isFile() && $current->getExtension() === 'php';
});
$files = new \RecursiveIteratorIterator($filter);
$classes = array();
foreach ($files as $fileinfo) {
$class = $namespace_prefix;
if ('' !== ($subpath = $fileinfo->getSubPath())) {
$class .= strtr($subpath, '/', '\\') . '\\';
}
$class .= $fileinfo->getBasename('.php');
$classes[$class] = $fileinfo->getPathname();
}
return $classes;
}
示例12: parseDirectory
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;
}
示例13: delete
/**
* Force deletion on a cached resource.
*
* @param {string} $key Identifier of target cache.
* @param {?string} $hash Target revision to delete, all revisions will be deleted if omitted.
*/
public static function delete($key, $hash = '*')
{
$res = self::resolve($key, $hash);
// Skip the delete if nothing is found.
if ($res === null) {
return;
}
if ($res->isFile()) {
// Remove target revision(s).
if (!$res->isWritable()) {
Log::warning('Target file is not writable, deletion skipped.');
} else {
$path = $res->getRealPath();
unlink($path);
$path = dirname($path);
// Remove the directory if empty.
$res = new \RecursiveDirectoryIterator($path, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS);
if ($res->isDir() && !$res->hasChildren()) {
rmdir($path);
}
}
} else {
if ($res->isDir()) {
$cacheDirectory = $res->getRealPath();
foreach ($res as $file) {
if ($file->isFile()) {
unlink($file->getRealPath());
} else {
if ($file->isDir()) {
rmdir($file->getRealPath());
}
}
}
rmdir($cacheDirectory);
}
}
}
示例14: deleteDir
/**
* Internal method for directory deletion
*
* @param string $rootPath Path for root directory
* @param boolean $recursive Recursion flag
* @return void
* @throws \DomainException If directory has children and !$recursive
*/
protected function deleteDir($rootPath, $recursive)
{
$directory = new \RecursiveDirectoryIterator($rootPath, \FilesystemIterator::SKIP_DOTS);
if ($directory->hasChildren()) {
if (!$recursive) {
throw new \DomainException('Directory "' . $rootPath . '" Still Has Children', 500);
}
$iterator = new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $child) {
$this->Delete($child);
}
}
rmdir($rootPath);
}
示例15: array
<!--стили сайта-->
<?php
Yii::app()->bootstrap->init();
$assets = Yii::app()->getModule('docs')->assetsUrl();
Yii::app()->clientScript->registerCssFile($assets . '/css/styles.css');
?>
</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 {