/** * * @param Criterio $filtro * @param string $order * @param integer $limitOffset * @param integer $limitCount * @param string $group * @return mixed Proyecto */ function findBy($filtro = null, $order = null, $limitOffset = null, $limitCount = null, $group = null) { $dir = new DirectoryIterator(DIR_PROYECTOS); while ($dir->valid()) { if ($dir->isFile() && stripos($dir->getFilename(), '.json')) { $proyFilename = DIR_PROYECTOS . $dir->getFilename(); $p = new Proyecto(); $fp = fopen($proyFilename, 'r'); $strJsonProy = fread($fp, filesize($proyFilename)); fclose($fp); $jsonProy = json_decode($strJsonProy); $p->setNombre($jsonProy->nombre); $p->setRuta($jsonProy->ruta); $p->setTieneProyectoEcplipse(file_exists("{$jsonProy->ruta}/.project")); if ($p->getTieneProyectoEclipse()) { $eclipseProy = simplexml_load_file("{$jsonProy->ruta}/.project"); $p->setNombre((string) $eclipseProy->name); } $p->setId($jsonProy->id); $p->setDbConfig($jsonProy->dbConfig); $lista[] = $p; } $dir->next(); } return $lista; }
public function loadMigrations() { $result = array('mgrs' => array(), 'headers' => array(array('id' => 'id', 'content' => Loc::getMessage('MIGRATION_ID'), 'sort' => 'id', 'align' => 'left', 'default' => true), array('id' => 'status', 'content' => Loc::getMessage('MIGRATION_STATUS'), 'align' => 'right', 'default' => true), array('id' => 'date_c', 'content' => Loc::getMessage('MIGRATION_DATE_CHANGED'), 'align' => 'right', 'default' => true), array('id' => 'date_a', 'content' => Loc::getMessage('MIGRATION_DATE_ADDED'), 'align' => 'right', 'default' => true))); $db_mgrs = $this->loadDBMigrations(); $mgr_path = Option::get(UM_BM_MODULE_NAME, 'migration_folder', UM_BM_MGR_PATH); $di = new \DirectoryIterator($_SERVER['DOCUMENT_ROOT'] . $mgr_path); while ($di->valid()) { if (!$di->isDot() && $this->hasProperFilename($di->getFilename())) { $filename = $di->getFilename(); if (!array_key_exists($filename, $db_mgrs)) { $mgr = new BixMigBase(); $mgr->setCode($filename)->setStatus('UNKNOWN')->setAddDate(date('d.m.Y H:i:s'))->setChangeDate()->add(); $result['mgrs'][] = $mgr; } else { $result['mgrs'][] = $db_mgrs[$filename]; unset($db_mgrs[$filename]); } } $di->next(); } if (!empty($db_mgrs)) { $this->deleteOrphans($db_mgrs); } return $result; }
/** * Carrega todos os arquivos do pacote especificado o carregamento considera o classpath atual da execusão * * @param string $package nome do pacote */ public static function load($package) { self::getCurrentPath(); if (substr($package, -1, 1) != "/") { $package .= "/"; } foreach (self::$classPath as $path) { $dir = $path . $package; if (is_dir($dir)) { $d = new DirectoryIterator($dir); while ($d->valid()) { if ($d->isFile()) { $requireThis = false; //testa a extensão foreach (self::$filesExtensions as $ext) { if (substr($d->getFilename(), strlen($ext) * -1, strlen($ext)) == $ext) { $requireThis = true; break; } } if ($requireThis) { require_once $package . $d->getFilename(); } } $d->next(); } } } }
/** * Método recursivo que busca o arquivo em todas as pastadas dentro do * diretorio específicado * * @param string $dir * @param string $file * @return boolean */ public static function searchInDir($dir, $file) { if (is_file($dir . "/" . $file)) { require_once $dir . "/" . $file; self::$find = true; if (self::$sugests) { $fileName = $dir . "/" . $file; $fileName = str_replace(self::$currentPath, "", $fileName); echo "require_once '" . $fileName . "';<br>\n"; } return true; } if (is_dir($dir)) { $d = new DirectoryIterator($dir); while (!self::$find && $d->valid()) { if (is_dir($d->getPath() . '/' . $d->getFilename())) { //testa se o arquivo pode ser incluido $inc = true; foreach (self::$blockedDirs as $bDir) { if ($d->getFilename() == $bDir) { $inc = false; break; } } if (!$d->isDot() && $inc) { self::searchInDir($d->getPath() . '/' . $d->getFilename(), $file); } } $d->next(); } } return self::$find; }
/** * Compacta todos os arquivos .php de um diretório removendo comentários, * espaços e quebras de linhas desnecessárias. * motivos de desempenho e segurança esse método so interage em um diretório * de cada vez. * * @param string $directoryPath * @param string $newFilesDirectory * @param string $newFilesPrefix * @param string $newFilesSufix */ public static function cleanDir($directoryPath, $newFilesDirectory = "packed", $newFilesPrefix = "", $newFilesSufix = "") { $dir = new DirectoryIterator($directoryPath); mkdir($directoryPath . "/{$newFilesDirectory}/"); while ($dir->valid()) { if (!$dir->isDir() and !$dir->isDot() and substr($dir->getFilename(), -3, 3) == 'php') { $str = self::cleanFile($dir->getPathname()); $fp = fopen($dir->getPath() . "/packed/" . $newFilesPrefix . $dir->getFilename() . $newFilesSufix, "w"); fwrite($fp, $str); fclose($fp); echo $dir->getPathname() . ' - Renomeado com sucesso <br />'; } $dir->next(); } }
/** * Obtem um array de ImgObject com todos os arquivos de imagens dos * diretórios especificados * * @param int|null $limit * @return array */ public function getImgArray($limit = null) { $imgArray = array(); foreach ($this->getDir() as $diretorio) { $imgArray = array(); $d = new DirectoryIterator($diretorio); while ($d->valid()) { if (!$d->isDot()) { $fileName = $d->getFilename(); if ($this->validateFormat($fileName)) { $imgObj = new ImgObject($fileName, $diretorio); $imgArray[] = $imgObj; ++$this->imgCount; if ($limit != null) { if ($this->imgCount >= $limit) { break; } } } } $d->next(); } } return $imgArray; }
public function logAction() { $pageSize = 4096; $overlapSize = 128; $dir = APPLICATION_PATH . '/../data/logs/'; $file = $this->_getParam('file', null); $this->view->page = $this->_getParam('page', 0); if ($file === null) { $file = sprintf('%s_application.log', Zend_Date::now()->toString('yyyy.MM.dd')); } $fp = fopen($dir . $file, 'r'); fseek($fp, -$pageSize * ($this->view->page + 1) + $overlapSize, SEEK_END); $this->view->errorLog = fread($fp, $pageSize + $overlapSize * 2); fclose($fp); $iterator = new DirectoryIterator($dir); while ($iterator->valid()) { if (!$iterator->isDot()) { if ($iterator->isFile()) { $files[$iterator->getFilename()] = $iterator->getPathName(); } } $iterator->next(); } $this->view->itemCountPerPage = $pageSize; $this->view->totalItemCount = filesize($dir . $file); $this->view->files = $files; }
function executeDir($directory) { $iterator = new DirectoryIterator($directory); while ($iterator->valid()) { $entry = $iterator->getFilename(); $path = $directory . '/' . $entry; $iterator->next(); if ($entry[0] == '.') { continue; } if (is_file($path)) { if (substr($entry, -4) != '.php') { continue; } if (ctype_upper($entry[0])) { $test = new DocTest($path); if ($test->failed()) { echo $test->toString(); $this->fail('Doc test failed.'); } else { if ($test->numOfPassed()) { echo ','; } else { echo ' '; } } } } elseif (is_dir($path)) { $this->executeDir($path); } } }
protected function scanFolder($folder, &$position, $forFolders = true, $threshold_key = 'dir', $threshold_default = 50) { $registry = AEFactory::getConfiguration(); // Initialize variables $arr = array(); $false = false; if (!is_dir($folder) && !is_dir($folder . '/')) { return $false; } try { $di = new DirectoryIterator($folder); } catch (Exception $e) { $this->setWarning('Unreadable directory ' . $folder); return $false; } if (!$di->valid()) { $this->setWarning('Unreadable directory ' . $folder); return $false; } if (!empty($position)) { $di->seek($position); if ($di->key() != $position) { $position = null; return $arr; } } $counter = 0; $maxCounter = $registry->get("engine.scan.large.{$threshold_key}_threshold", $threshold_default); while ($di->valid()) { if ($di->isDot()) { $di->next(); continue; } if ($di->isDir() != $forFolders) { $di->next(); continue; } $ds = $folder == '' || $folder == '/' || @substr($folder, -1) == '/' || @substr($folder, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR; $dir = $folder . $ds . $di->getFilename(); $data = _AKEEBA_IS_WINDOWS ? AEUtilFilesystem::TranslateWinPath($dir) : $dir; if ($data) { $counter++; $arr[] = $data; } if ($counter == $maxCounter) { break; } else { $di->next(); } } // Determine the new value for the position $di->next(); if ($di->valid()) { $position = $di->key() - 1; } else { $position = null; } return $arr; }
/** * Overwrite in children to parse files according to our style. * @param array $listing * @param DirectoryIterator $item */ public function pushItem(&$listing, DirectoryIterator $entry) { if (substr($filename = $entry->getFilename(), -4) == '.css') { // a reset stylesheet, always used if (strpos($stylename = $entry->getBasename('.css'), 'tripoli') !== FALSE) { } else { array_push($listing, $stylename); } } }
/** * Rewinds the cache entry iterator to the first element * * @return void * @api */ public function rewind() { if ($this->cacheFilesIterator === null) { $this->cacheFilesIterator = new \DirectoryIterator($this->cacheDirectory); } $this->cacheFilesIterator->rewind(); while (substr($this->cacheFilesIterator->getFilename(), 0, 1) === '.' && $this->cacheFilesIterator->valid()) { $this->cacheFilesIterator->next(); } }
/** * @param DirectoryIterator $file */ private function addFromFile(DirectoryIterator $file) { $match = preg_match('/([^.]+)-custom.definition.json/', $file->getFilename(), $matches); if (!$match) { return; } $dictionaryName = $matches[1]; $translations = $this->loadTranslations($file->getPathname()); foreach ($translations as $translationName => $translations) { $this->includeTranslation($dictionaryName, $translationName, $translations); } }
public function pushItem(&$listing, DirectoryIterator $item) { // dot would be for morse code locale? if (!$item->isDot() && $item->isFile()) { // explode and extract name & type list($name, $type) = explode('.', $item->getFilename()); assert('!empty($name) && !empty($type); // invalid locale files'); // push name to stack if ($type == 'yml') { array_push($listing, $name); } } }
/** * @desc Iterates the components directory and returns list of it subdirectories * * @return array */ public static function loadComponentsFromFileSystem() { $componentsNames = []; $directory = new DirectoryIterator(\Wikia\UI\Factory::getComponentsDir()); while ($directory->valid()) { if (!$directory->isDot() && $directory->isDir()) { $componentName = $directory->getFilename(); $componentsNames[] = $componentName; } $directory->next(); } return $componentsNames; }
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">'; getDirInfo($iterator->getPathname()); echo '</ul></li>'; } $iterator->next(); } #再输出文件 $iterator->Rewind(); while ($iterator->valid()) { if ($iterator->isFile()) { echo '<li class="flist file"><i class="fa fa-file-text"></i> ' . $iterator->getFilename() . '</li>'; } $iterator->next(); } }
public function getPlugins() { $output = array(); $it = new DirectoryIterator(BASE . 'plugins/'); while ($it->valid()) { $xml_path = $it->getPath() . $it->getFilename() . '/'; $xml_file = $xml_path . "plugin.xml"; if ($it->isReadable() && $it->isDir() && file_exists($xml_file)) { $output[] = new PapyrinePlugin($xml_path); } $it->next(); } return $output; }
/** * Returns the available languages for this documentation format * * @return array Array of string language codes * @api */ public function getAvailableLanguages() { $languages = array(); $languagesDirectoryIterator = new \DirectoryIterator($this->formatPath); $languagesDirectoryIterator->rewind(); while ($languagesDirectoryIterator->valid()) { $filename = $languagesDirectoryIterator->getFilename(); if ($filename[0] != '.' && $languagesDirectoryIterator->isDir()) { $language = $filename; $languages[] = $language; } $languagesDirectoryIterator->next(); } return $languages; }
protected function FileFilter(DirectoryIterator $pParent, DirectoryIterator $pNode) { $returnvalue = false; $filename = $pNode->getFilename(); $patternDDS = '/\\.dds$/'; $patternPNG = '/\\.png$/'; if (preg_match($patternDDS, $filename)) { $returnvalue = true; } else { if (preg_match($patternPNG, $filename)) { $returnvalue = true; } } return $returnvalue; }
/** * @param DirectoryIterator $fileInfo */ private function patchXml(\DirectoryIterator $fileInfo) { if ($fileInfo->isFile()) { $filePath = $fileInfo->getPathname(); if (!preg_match('/\\.orm\\.xml$/', $fileInfo->getFilename())) { return; } else { preg_match('/(.*)\\.orm\\.xml/', $fileInfo->getFilename(), $m); $className = $m[1]; } //replase $contentMap = ['column="order"' => 'column="`order`"', 'column="from"' => 'column="`from`"', 'column="to"' => 'column="`to`"', 'column="user"' => 'column="`user`"']; $content = file_get_contents($filePath); $content = str_replace(array_keys($contentMap), array_values($contentMap), $content); //rename $filenameMap = []; if (isset($filenameMap[$fileInfo->getFilename()])) { unlink($filePath); $filePath = $fileInfo->getPath() . '/' . $filenameMap[$fileInfo->getFilename()]; } $content = $this->addGedmoLoggable($content, $className); file_put_contents($filePath, $content); } }
function getList($max = null) { $dir = new DirectoryIterator($this->file_path); $fileList = array(); while ($dir->valid()) { if ($dir->isDot()) { $dir->next(); continue; } $file_name = $dir->getFilename(); $fileList[] = $file_name; $dir->next(); } return $fileList; }
/** * This should provide the feature that the lang package can be used from * everywhere without to import it. Currently this is not working. */ private function initLang() { if ($this->initialized) { return; } $dir = new \DirectoryIterator(__DIR__); while ($dir->valid()) { $file = $dir->getFilename(); if ($dir->isFile() && ($len = strpos($file, '.php')) === strlen($file) - 4) { $name = substr($file, 0, $len); $fullName = 'blaze\\lang\\' . $name; $this->loadClass($fullName); @class_alias($fullName, $name); } $dir->next(); } }
/** * Scan the files in the configured path for controllers * * To dynamically scan controllers from the source files * use PHP Reflection to find the controllers. * * The returning result is an array of Admin_Model_DbRow_Controller elements * * @return array */ public function getControllers() { $resources = array(); $directory = new DirectoryIterator($this->path); $CcFilter = new Zend_Filter_Word_CamelCaseToDash(); while ($directory->valid()) { if ($directory->isFile() && !in_array($directory->getFilename(), $this->skip, TRUE)) { // load the file require_once $directory->getPathname(); $reflect = new Zend_Reflection_File($directory->getPathName()); $name = substr($reflect->getClass()->getName(), strrpos($reflect->getClass()->getName(), "_") + 1); $controller = new Admin_Model_DbRow_Controller(array('moduleName' => 'webdesktop', 'controllerName' => strtolower($name), 'virtual' => 1)); $resources[] = $controller; } $directory->next(); } return $resources; }
/** * Get all Controllers of all Modules in this application * * @return array * @access public * @todo refactoring needed, multiple nested iterations */ public function getControllers() { $frontController = Zend_Controller_Front::getInstance(); $resources = array(); foreach ($frontController->getControllerDirectory() as $cDirectory) { $directory = new DirectoryIterator($cDirectory); $module = basename(dirname($cDirectory)); if ($module === 'default' || $module === 'application') { $module = 'default'; } while ($directory->valid()) { if (preg_match('/^([A-Za-z0-9]+)Controller.php$/', $directory->getFilename(), $match)) { $controller = new Admin_Model_DbRow_Controller(array('moduleName' => $module, 'controllerName' => strtolower($match[1]), 'virtual' => 0)); $resources[] = $controller; } $directory->next(); } } // get the controllers from the hooks // //FIXME this can be very expensive on performance, multiple nesting of iterations foreach ($this->hooks as $hook) { /** * We need to setup a tmp array to store the hook controllers, because * we iterate each hookcontroller over reflectcontroller and this would end * in duplicates entries. * Store the hookcontroller if matches the expressions with a key in the tmp * array and later merge the tmp array with the ressources array. * so we do not have duplicate entries */ $hookResources = array(); foreach ($hook->getControllers() as $hookController) { foreach ($resources as $reflectController) { $key = $hookController->get('moduleName') . '/' . $hookController->get('controllerName'); $notSameModule = $hookController->get('moduleName') !== $reflectController->get('moduleName'); $notSameController = $hookController->get('controllerName') !== $reflectController->get('controllerName'); if ($notSameModule && $notSameController && !array_keys($hookResources, $key, TRUE)) { $hookResources[$key] = $hookController; } } } $resources = array_merge_recursive($resources, array_values($hookResources)); } return $resources; }
/** * scan folders recursive and returns all folders * @param string $directory * @param string exclude * @return array|string */ public function scanRecursiveDir($directory, $exclude = '') { try { $file = ''; $it = new DirectoryIterator($directory); for ($it->rewind(); $it->valid(); $it->next()) { if ($it->isDir() && !$it->isDot()) { if ($it->getFilename() == $exclude) { continue; } $file[] = $it->getFilename(); } } return $file; } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('error', 'php', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_VOID); } }
/** * Iteratively remove/delete a directory and its contents * * @param DirectoryIterator $path base directory (inclusive) to recursively delete. */ function recursivelyDeleteDirectory(DirectoryIterator $path) { // echo $path . " being deleted?"; if ($path->isDir()) { $directory = new DirectoryIterator($path->getPath() . DIRECTORY_SEPARATOR . $path->getFilename()); // For each element within this directory, delete it or recurse into next directory foreach ($directory as $object) { if (!$object->isDot()) { if ($object->isDir()) { recursivelyDeleteDirectory($object); } else { unlink($object->getPathname()); } } } rmdir($path->getPathname()); } else { // Not a directory... // Do nothing } }
public function readDir($dirPath) { $di = new DirectoryIterator($dirPath); $array = array(); while ($di->valid()) { if (!$di->isDot() && $this->validateDir($di->getFilename())) { if ($di->isDir()) { $dir = $di->getPath() . '/' . $di->getFilename(); $array[$di->getFilename()] = $this->readDir($di->getPath() . '/' . $di->getFilename()); } else { $array[$di->getFilename()] = $di->getPath() . "/" . $di->getFilename(); } } $di->next(); } return $array; }
private function nextUpdate() { $prefixLength = strlen(self::PREFIX); $suffixLength = strlen(self::SUFFIX); $updateNameLength = $prefixLength + 10 + $suffixLength; $iterator = new DirectoryIterator('update'); while ($iterator->valid()) { $entry = $iterator->getFilename(); $iterator->next(); if (strlen($entry) != $updateNameLength) { continue; } if (substr($entry, 0, $prefixLength) != self::PREFIX) { continue; } if (substr($entry, -$suffixLength) != self::SUFFIX) { continue; } $version = substr($entry, $prefixLength, 10); if ($version > $this->version) { return $version; } } }
/** * Delete empty directories (directories which contains only directories) starting from $dir * @static * @param string $dir * @param Closure|string|null $log * @return void */ static function deleteEmptyDirectories($dir, $log = null) { $iterator = new DirectoryIterator($dir); $files_in_dir = 0; foreach ($iterator as $node) { if ($iterator->isDot()) { continue; } $pathname = $iterator->getPathName(); $filename = $iterator->getFilename(); if ($iterator->isDir()) { $files_in_dir += self::deleteEmptyDirectories($iterator->getPathName(), $log); } else { $files_in_dir++; } } if ($files_in_dir == 0) { if (null !== $log) { $log("Remove empty dir '{$dir}'"); } rmdir($dir); } return $files_in_dir; }
/** * ULTIMATE Seo Urls 5 PRO by FWR Media * Reset the various cache systems * @param string $action */ function tep_reset_cache_data_usu5($action = false) { if ($action == 'reset') { $usu5_path = realpath(dirname(__FILE__) . '/../../../') . '/' . DIR_WS_MODULES . 'ultimate_seo_urls5/'; switch (USU5_CACHE_SYSTEM) { case 'file': $path_to_cache = $usu5_path . 'cache_system/cache/'; $it = new DirectoryIterator($path_to_cache); while ($it->valid()) { if (!$it->isDot() && is_readable($path_to_cache . $it->getFilename()) && substr($it->getFilename(), -6) == '.cache') { @unlink($path_to_cache . $it->getFilename()); } $it->next(); } break; case 'mysql': tep_db_query('TRUNCATE TABLE `usu_cache`'); break; case 'memcache': if (class_exists('Memcache')) { include $usu5_path . 'interfaces/cache_interface.php'; include $usu5_path . 'cache_system/memcache.php'; Memcache_Cache_Module::iAdmin()->initiate()->flushOut(); } break; case 'sqlite': include $usu5_path . 'interfaces/cache_interface.php'; include $usu5_path . 'cache_system/sqlite.php'; Sqlite_Cache_Module::admini()->gc(); break; } tep_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value='false' WHERE configuration_key='USU5_RESET_CACHE'"); } }
/** * getTranslationFilesArray * * @param string $lang Language code * @return array Array */ private function getTranslationFilesArray($lang) { $dir = new DirectoryIterator($this->_langDir . $lang); while ($dir->valid()) { if (!$dir->isDot() && $dir->isFile() && !preg_match('/^\\./', $dir->getFilename())) { $files[] = $dir->getFilename(); } $dir->next(); } return $files; }