* @param null */ spl_autoload_register(function ($class) { $Dir = str_replace('\\', '/', $class) . '.class.php'; $FileName = __DIR__ . '/' . $Dir; #realpath('./'.$Dir)亦可 但调用了函数肯定会适度加重负担; include $FileName; }); #Function文件夹中的文件自动加载 $FunctionDir = __DIR__ . '/Function/'; if (is_dir($FunctionDir)) { $iterator = new DirectoryIterator($FunctionDir); while ($iterator->valid()) { if ($iterator->isFile()) { $FileDir = $FunctionDir . $iterator->getFilename(); if ($iterator->getExtension() == 'php') { include $FileDir; } } $iterator->next(); } } #文件结构迭代器 function getDirInfo($dir) { $iterator = new DirectoryIterator($dir); #先输出文件夹 while ($iterator->valid()) { if ($iterator->isDir() && $iterator->getFilename() != '.' && $iterator->getFilename() != '..' && $iterator->getFilename() != '.git') { echo '<li class="flist filedir"><i class="fa fa-folder-open"></i> ' . $iterator->getFilename(); echo '<ul class="dirlist">';
public function getExtension() { if (method_exists(get_parent_class($this), 'getExtension')) { $ext = parent::getExtension(); } else { $ext = pathinfo($this->getPathName(), PATHINFO_EXTENSION); } return strtolower($ext); }
private function _filestackProcessDir($dir) { $Iterator = new \DirectoryIterator($dir); if ($this->_filestackKey > 0) { $Iterator->seek($this->_filestackKey); } while ($Iterator->valid()) { // timeout check: if ($this->intervalLimitIsReached() === true) { $this->_Dirstack->save(); $this->_Filestack->save(); $this->setMessage('Filestack creation: ' . $this->_filesInStack . ' files processed.'); return false; } $this->_filestackKey = $Iterator->key(); $this->Storage->set('filestackKey', $this->_filestackKey, 'filecheck'); // skip dots: if ($Iterator->isDot()) { $Iterator->next(); continue; } // if is directory save to database for later processing: $currentPath = $Iterator->getPathname(); if ($Iterator->isDir()) { $this->_Dirstack->addPath($currentPath); $Iterator->next(); continue; } // filesize check: $filesize = $Iterator->getSize(); if (empty($filesize) || $filesize > $this->sizeFilter) { $Iterator->next(); continue; } // filetype check: if ($this->_extensionCheck === true) { $fileExtension = $Iterator->getExtension(); if (empty($fileExtension) || !isset($this->_allowedExtensions[$fileExtension])) { $Iterator->next(); continue; } } // add file to stack: $this->_Filestack->addPath($currentPath); // create hash (if not yet done): if ($this->_createFilehashDb === true) { $pathhash = sha1($currentPath); $filehash = sha1_file($currentPath); $this->Database->setQuery("INSERT IGNORE INTO #__wm_filehashes (pathhash, filehash, mode) VALUES(" . $this->Database->q($pathhash) . "," . $this->Database->q($filehash) . ", " . $this->Database->q($this->runMode) . ")")->execute(); } $this->_filesInStack++; $this->Storage->set('filesInStack', $this->_filesInStack, 'filecheck'); $Iterator->next(); } unset($Iterator); // current dir completed -> delete from stack: $this->_Dirstack->save(); $this->_Dirstack->clear(); $this->_Filestack->save(); $this->_Filestack->clear(); $this->Database->setQuery("DELETE FROM #__wm_dirstack WHERE path = " . $this->Database->q($dir) . "AND mode = " . $this->Database->q($this->runMode))->execute(); $this->_filestackKey = 0; // select next dir from stack: $this->Database->setQuery("SELECT path FROM #__wm_dirstack WHERE mode = " . $this->Database->q($this->runMode) . " LIMIT 1")->execute(); $row = $this->Database->getRow(); if (empty($row)) { return true; } $this->_filestackPath = $row->path; $this->Storage->set('filestackPath', $this->_filestackPath, 'filecheck'); return $this->_filestackProcessDir($row->path); }
/** * Retrieve all XLIFF for a given language. * * @param string $language The language to search the xliff files in. * * @return string[] */ protected function getAllTxFiles($language) { $iterator = new \DirectoryIterator($this->txlang . DIRECTORY_SEPARATOR . $language); $files = array(); while ($iterator->valid()) { if (!$iterator->isDot() && $iterator->isFile() && $iterator->getExtension() == 'xlf' && $this->isNotFileToSkip($iterator->getPathname())) { $files[$iterator->getPathname()] = $iterator->getFilename(); } $iterator->next(); } return $files; }
/** * Get system I18n files * * @return void */ public function getDefaultLocale() { $localeFiles = new \DirectoryIterator(PATH_SYS . DIRECTORY_SEPARATOR . 'I18n'); // Traverse the I18n directory and load each locale files while ($localeFiles->valid()) { if ($localeFiles->getExtension() == 'yml') { list($locale, $extension) = explode('.', $localeFiles->getFilename()); if ($locale = self::validateLocale($locale)) { $localeArray = Yaml::parse($localeFiles->getPathname()); $this->lang->set($locale, $localeArray); } } $localeFiles->next(); } }
/** * @param \DirectoryIterator $currentItem * * @return string */ protected function getLocale(\DirectoryIterator $currentItem) { return substr($currentItem->getFilename(), 0, (strlen($currentItem->getExtension()) + 1) * -1); }