Example #1
0
 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;
 }
Example #2
0
 /**
  * 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();
             }
         }
     }
 }
 /**
  *
  * @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;
 }
Example #4
0
 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;
 }
 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;
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
 /**
  * @ignore
  */
 public static function fromFileScan($uPattern)
 {
     $tSep = quotemeta(DIRECTORY_SEPARATOR);
     $tPos = strrpos($uPattern, $tSep);
     if ($tSep !== '/' && $tPos === false) {
         $tSep = '/';
         $tPos = strrpos($uPattern, $tSep);
     }
     if ($tPos !== false) {
         $tPattern = substr($uPattern, $tPos + strlen($tSep));
         $tPath = substr($uPattern, 0, $tPos + strlen($tSep));
     } else {
         $tPath = $uPattern;
         $tPattern = "";
     }
     $tTemp = new static();
     $tHandle = new \DirectoryIterator($tPath);
     $tPatExists = strlen($uPattern) > 0;
     for (; $tHandle->valid(); $tHandle->next()) {
         if (!$tHandle->isFile()) {
             continue;
         }
         $tFile = $tHandle->current();
         if ($tPatExists && !fnmatch($tPattern, $tFile)) {
             continue;
         }
         $tTemp->add(simplexml_load_file($tPath . $tFile));
     }
     return $tTemp;
 }
 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);
         }
     }
 }
Example #9
0
 /**
  * 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;
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $this->checkORMType($options['type']);
     parent::execute($arguments, $options);
     $this->_runInitTask();
     $options['application'] = $arguments['application'];
     // still no class_path given? take the default one!
     if (empty($options['class_path'])) {
         $options['class_path'] = $this->modelTypes[$options['type']]['default_model_path'];
     }
     if (!empty($options['skip_methods'])) {
         $methods = explode(',', $options['skip_methods']);
         foreach ($methods as $method) {
             array_push($this->skipMethods, $method);
         }
     }
     // a custom class given?
     if (!empty($options['class'])) {
         if (strpos($options['class_path'], ':') !== false) {
             throw new sfCommandException(': is not supported in class_path when specifying the class name.');
         }
         $options['libpath'] = $options['class_path'];
         $this->createTestClass($options, $options['target']);
         return;
     }
     $paths = explode(':', $options['class_path']);
     $namespaces = array();
     foreach ($paths as $path) {
         $finder = sfFinder::type('directory');
         $ignoredDirs = $this->modelTypes[$options['type']]['ignored_directory'];
         foreach ($ignoredDirs as $ignDir) {
             $finder = $finder->not_name($ignDir);
         }
         $dirs = $finder->in($path);
         foreach ($dirs as $dir) {
             if (is_dir($dir)) {
                 $namespaces[] = $dir;
             }
         }
     }
     $paths = array_merge($paths, $namespaces);
     foreach ($paths as $path) {
         $options['libpath'] = $path;
         $dir = new DirectoryIterator($path);
         $this->logSection('phpunit', sprintf('Searching %s', $path));
         while ($dir->valid()) {
             if (strpos($dir, '.php') !== false) {
                 $subfolder = basename(dirname($path . DIRECTORY_SEPARATOR . $dir));
                 $suffix = !empty($options['file_suffix']) ? $options['file_suffix'] : $this->modelTypes[$options['type']]['classFileSuffix'];
                 $options['class'] = str_replace($suffix, '', $dir);
                 $this->createTestClass($options, $subfolder);
             }
             $dir->next();
         }
     }
     $this->_runInitTask();
 }
Example #11
0
 public function valid()
 {
     if (!parent::valid()) {
         return false;
     }
     if (!$this->_apb) {
         return true;
     }
     return $this->isAllowed();
 }
Example #12
0
 protected function cleanDir($dir)
 {
     $files = new \DirectoryIterator($dir);
     while ($files->valid()) {
         if (in_array(substr($files->current(), -2), ['.0', '.1'])) {
             unlink($dir . '/' . $files->current());
         }
         $files->next();
     }
 }
 /**
  * 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();
     }
 }
Example #14
0
 public function valid()
 {
     if (parent::valid()) {
         if (!parent::isFile()) {
             parent::next();
             return $this->valid();
         }
         return True;
     }
     return False;
 }
 /**
  * valid 
  * 
  * @access public
  * @return bool
  */
 public function valid()
 {
     if (parent::valid()) {
         if (parent::isDir()) {
             parent::next();
             return $this->valid();
         }
         return true;
     }
     return false;
 }
 function valid()
 {
     if (parent::valid()) {
         if (!parent::isFile()) {
             parent::next();
             return $this->valid();
         }
         return TRUE;
     }
     return FALSE;
 }
 public function valid()
 {
     if (parent::valid()) {
         if ($this->dirsOnly && !parent::isDir() || parent::isDot() || parent::getFileName() == '.svn') {
             parent::next();
             return $this->valid();
         }
         return true;
     }
     return false;
 }
 function __construct($link)
 {
     $d = new DirectoryIterator($link);
     while ($d->valid()) {
         $file = $d->current();
         if (!$file->isDot()) {
             $this->files[] = $file->getFilename();
         }
         $d->next();
     }
     $this->path = $d->getPath();
 }
Example #19
0
function getTestFiles($dir = '')
{
    $file = new DirectoryIterator($dir);
    $res = array();
    while ($file->valid()) {
        if ($file->isFile() && substr($file->getPathName(), -8) == 'Test.php') {
            $res[] = $file->getPathName();
        }
        $file->next();
    }
    return $res;
}
 /**
  * @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;
 }
Example #21
0
 function indexAction()
 {
     setcookie("previewTemplateName", false, 0, "/");
     $templates = array();
     $dir = new DirectoryIterator(Config::get('TEMPLATES_PATH'));
     while ($dir->valid()) {
         if (!$dir->isDot()) {
             $templates[] = (string) $dir->current();
         }
         $dir->next();
     }
     $this->set("alltemplates", $templates);
 }
Example #22
0
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();
    }
}
Example #23
0
function getTestFiles($dir = '')
{
    $file = new DirectoryIterator($dir);
    $res = array();
    while ($file->valid()) {
        if ($file->isFile() && substr($file->getPathName(), -4) == '.php') {
            $class = str_replace(DIRECTORY_SEPARATOR, '_', substr($file->getPathName(), 0, -4));
            $res[] = array($file->getPathName(), $class);
        }
        $file->next();
    }
    return $res;
}
 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;
 }
Example #25
0
 /**
  * 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();
     }
 }
Example #26
0
 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;
 }
 /**
  * Returns the available documentation formats for this documentation
  *
  * @return array Array of \TYPO3\Flow\Package\DocumentationFormat
  * @api
  */
 public function getDocumentationFormats()
 {
     $documentationFormats = array();
     $documentationFormatsDirectoryIterator = new \DirectoryIterator($this->documentationPath);
     $documentationFormatsDirectoryIterator->rewind();
     while ($documentationFormatsDirectoryIterator->valid()) {
         $filename = $documentationFormatsDirectoryIterator->getFilename();
         if ($filename[0] != '.' && $documentationFormatsDirectoryIterator->isDir()) {
             $documentationFormat = new \TYPO3\Flow\Package\Documentation\Format($filename, $this->documentationPath . $filename . '/');
             $documentationFormats[$filename] = $documentationFormat;
         }
         $documentationFormatsDirectoryIterator->next();
     }
     return $documentationFormats;
 }
Example #28
0
 /**
  * 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;
 }
Example #29
0
 /**
  * Clears Up the images folder
  * Old files are unlinked
  */
 public function clearPast()
 {
     // # DirecotryIterator on image folder
     $chartsIterator = new \DirectoryIterator($this->PM->getProperty("basePath") . "/imagedata/");
     $isDirEmpty = !$chartsIterator->valid();
     // # Check if it is already empty
     if (!$isDirEmpty) {
         $this->log->error("Unlinking old files i've found");
         // # Unlink 'em all
         foreach ($chartsIterator as $file) {
             if ($file->isFile()) {
                 @unlink($this->PM->getProperty("basePath") . "/imagedata/" . $file->getFilename());
             }
         }
     }
 }
Example #30
0
 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;
 }