Exemplo n.º 1
0
 /**
  * Search, inside a dir, for a file pattern, using regular expresion
  * Example:
  *
  * <code>PHP_Beautifier_Common::getFilesByPattern('.','*.php',true);</code>
  * Search recursively for all the files with php extensions
  * in the current dir
  * @param    string  path to a dir
  * @param    string  file pattern
  * @param    bool    recursive?
  * @return   array   path to files
  */
 public static function getFilesByPattern($sDir, $sFilePattern, $bRecursive = false)
 {
     if (substr($sDir, -1) == '/') {
         $sDir = substr($sDir, 0, -1);
     }
     $dh = @opendir($sDir);
     if (!$dh) {
         throw new Exception("Cannot open directory '{$sDir}'");
     }
     $matches = array();
     while ($entry = @readdir($dh)) {
         if ($entry == '.' or $entry == '..') {
             continue;
         } elseif (is_dir($sDir . '/' . $entry) and $bRecursive) {
             $matches = array_merge($matches, PHP_Beautifier_Common::getFilesByPattern($sDir . '/' . $entry, $sFilePattern, $bRecursive));
         } elseif (preg_match("/" . $sFilePattern . "\$/", $entry)) {
             $matches[] = $sDir . "/" . $entry;
         }
     }
     if (!$matches) {
         PHP_Beautifier_Common::getLog()->log("{$sDir}/{$sFilePattern} pattern don't match any file", PEAR_LOG_DEBUG);
     }
     return $matches;
 }
Exemplo n.º 2
0
 /**
  * Get the list of all available Filters in all the include Dirs
  * @return array list of Filters
  */
 public function getFilterListTotal()
 {
     $aFilterFiles = array();
     foreach ($this->aFilterDirs as $sDir) {
         $aFiles = PHP_Beautifier_Common::getFilesByPattern($sDir, ".*?\\.filter\\.php");
         array_walk($aFiles, array($this, 'getFilterList_FilterName'));
         $aFilterFiles = array_merge($aFilterFiles, $aFiles);
     }
     sort($aFilterFiles);
     return $aFilterFiles;
 }
 function testgetFilesByPattern()
 {
     $sDir = PHP_Beautifier_Common::normalizeDir(dirname(__FILE__));
     $aExpected = array($sDir . 'BeautifierTest.php');
     $this->assertEquals($aExpected, PHP_Beautifier_Common::getFilesByPattern($sDir, 'BeautifierTest\\....', false));
 }