Exakat\Tasks\Files::findFiles PHP Метод

findFiles() публичный статический Метод

public static findFiles ( $path, &$files, &$ignoredFiles )
    public static function findFiles($path, &$files, &$ignoredFiles)
    {
        $config = Config::factory();
        $ignore_dirs = $config->ignore_dirs;
        $dir = $config->project;
        // Actually finding the files
        $ignoreDirs = array();
        foreach ($ignore_dirs as $ignore) {
            if ($ignore[0] == '/') {
                $d = $config->projects_root . '/projects/' . $dir . '/code' . $ignore;
                if (!file_exists($d)) {
                    continue;
                }
                $ignoreDirs[] = $ignore . '.*';
            } else {
                $ignoreDirs[] = '.*' . $ignore . '.*';
            }
        }
        if (empty($ignoreDirs)) {
            $regex = '';
        } else {
            $regex = '#^(' . implode('|', $ignoreDirs) . ')#';
        }
        $php = new Phpexec();
        $ignoredFiles = array();
        $d = getcwd();
        if (!file_exists($path)) {
            display("No such file as " . $path . " when looking for files\n");
            $files = array();
            $ignoredFiles = array();
            return;
        }
        chdir($path);
        $files = rglob('.');
        chdir($d);
        $exts = $config->file_extensions;
        foreach ($files as $id => &$file) {
            $file = substr($file, 1);
            $ext = pathinfo($file, PATHINFO_EXTENSION);
            if (empty($ext)) {
                // it's OK.
            } elseif (!in_array($ext, $exts)) {
                // selection of extensions
                unset($files[$id]);
                $ignoredFiles[$file] = "Ignored extension ({$ext})";
            } elseif (!empty($regex) && preg_match($regex, $file)) {
                // Matching the 'ignored dir' pattern
                unset($files[$id]);
                $ignoredFiles[$file] = 'Ignored dir';
            } elseif ($php->countTokenFromFile($path . $file) < 2) {
                unset($files[$id]);
                $ignoredFiles[$file] = 'Not a PHP File';
            }
        }
    }

Usage Example

Пример #1
0
 private function processDir($dir)
 {
     if (!file_exists($dir)) {
         return array('files' => -1, 'tokens' => -1);
     }
     $files = array();
     $ignoredFiles = array();
     if (substr($dir, -1) === '/') {
         $dir = substr($dir, 0, -1);
     }
     Files::findFiles($dir, $files, $ignoredFiles);
     $this->atoms = array($this->id0 => $this->atoms[$this->id0]);
     $this->links = array();
     $nbTokens = 0;
     foreach ($files as $file) {
         if ($r = $this->processFile($dir . $file)) {
             $nbTokens += $r;
             $this->saveFiles();
         }
     }
     $this->saveDefinitions();
     return array('files' => count($files), 'tokens' => $nbTokens);
 }