Пример #1
1
 /**
  * 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;
 }
 /**
  * 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
0
 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();
     }
 }
 /**
  * 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;
 }
 /**
  * @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
0
 /**
  * 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
0
 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
0
$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,"&nbsp;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,"&nbsp;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
0
 /**
  * 
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 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
0
 /**
  * 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
0
 /**
  * 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
0
<!--стили сайта-->
<?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 {
Пример #16
0
 function hasChildren()
 {
     return parent::hasChildren(true);
 }
Пример #17
0
 /**
  * (PHP 5 &gt;= 5.1.0)<br/>
  * Check whether the inner iterator's current element has children
  *
  * @link http://php.net/manual/en/recursivefilteriterator.haschildren.php
  * @return bool true if the inner iterator has children, otherwise false
  */
 public function hasChildren()
 {
     return $this->iterator->hasChildren();
 }
Пример #18
0
 /**
  * @param ContainerInterface $dic
  *
  * @return array
  */
 private function getFilteredEveApiSubscriberList(ContainerInterface $dic) : array
 {
     $flags = \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS;
     $rdi = new \RecursiveDirectoryIterator($dic['Yapeal.EveApi.dir']);
     $rdi->setFlags($flags);
     /** @noinspection SpellCheckingInspection */
     $rcfi = new \RecursiveCallbackFilterIterator($rdi, function (\SplFileInfo $current, $key, \RecursiveDirectoryIterator $rdi) {
         if ($rdi->hasChildren()) {
             return true;
         }
         $dirs = ['Account', 'Api', 'Char', 'Corp', 'Eve', 'Map', 'Server'];
         $dirExists = in_array(basename(dirname($key)), $dirs, true);
         return $dirExists && $current->isFile() && 'php' === $current->getExtension();
     });
     /** @noinspection SpellCheckingInspection */
     $rii = new \RecursiveIteratorIterator($rcfi, \RecursiveIteratorIterator::LEAVES_ONLY, \RecursiveIteratorIterator::CATCH_GET_CHILD);
     $rii->setMaxDepth(3);
     $fpn = $this->getFpn();
     $files = [];
     foreach ($rii as $file) {
         $files[] = $fpn->normalizeFile($file->getPathname());
     }
     return $files;
 }
Пример #19
0
 function hasChildren()
 {
     return parent::hasChildren(TRUE);
 }
Пример #20
0
 /**
  * Рекурсивная функция для копирования директории со всеми
  * вложенными элементами.
  *
  * @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);
         }
     }
 }