/**
 * Lists all files of a directory recursively.
 * 
 * Note that default pattern in *.* thus only listing files with a dot in the name.
 * If you change that to '*' everything will be returned.
 * We use *.* a common filter for all files (yes, we know that this is wrong).
 * @param string $directory Directory name
 * @param string $pattern Filename pattern
 * @return array Listing of all files
 */
function system_glob_rec($directory = '', $pattern = '*.*')
{
    system_ensure_path_ending($directory);
    $paths = system_glob($directory . '*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
    $files = system_glob($directory . $pattern);
    foreach ($paths as $path) {
        $files = array_merge($files, system_glob_rec($path, $pattern));
    }
    return $files;
}
示例#2
0
/**
 * @internal Collects files for minifying
 */
function minify_collect_files($paths, $kind)
{
    global $dependency_info, $res_file_storage, $ext_resources;
    $dependency_info = array();
    $res_file_storage = array();
    $ext_resources = array();
    foreach ($paths as $path) {
        if (!ends_with($path, "/")) {
            $path .= "/";
        }
        foreach (system_glob_rec($path, '*.class.php') as $f) {
            minify_collect_from_file($kind, $f);
        }
        $done_templates = array();
        foreach (array_reverse(cfg_get('system', 'tpl_ext')) as $tpl_ext) {
            $files = system_glob_rec($path, "*.{$tpl_ext}");
            foreach ($files as $f) {
                $skip = false;
                foreach ($done_templates as $d) {
                    if (isset($res_file_storage[basename($f, ".{$d}")])) {
                        $skip = true;
                        break;
                    }
                }
                if ($skip) {
                    continue;
                }
                minify_collect_from_file($kind, $f);
            }
            $done_templates[] = $tpl_ext;
        }
    }
    $res = array();
    $classes = array_keys($res_file_storage);
    foreach ($classes as $class) {
        $res = array_merge($res, minify_resolve_dependencies($class, $dependency_info, $res_file_storage));
    }
    unset($dependency_info);
    unset($res_file_storage);
    return array_unique($res);
}
示例#3
0
 function Run()
 {
     $summary = $this->content(new Control('div'));
     $run = new Anchor(buildQuery('DocMain', 'Run'), 'Run again');
     $down = new Anchor(buildQuery('DocMain', 'Download'), 'Download');
     $preview = new Anchor(buildQuery('Preview'), 'Preview');
     $this->content('<div style="text-align: center; font-size: 18px; font-weight: bold">');
     $this->content($run->WdfRender() . "&nbsp;&nbsp;" . $down->WdfRender() . "&nbsp;&nbsp;" . $preview->WdfRender());
     $this->content('</div>');
     if (!file_exists(__DIR__ . '/out')) {
         mkdir(__DIR__ . '/out');
     }
     foreach (system_glob_rec(__DIR__ . '/out', '*') as $file) {
         unlink($file);
     }
     cache_clear();
     $path = realpath(__DIR__ . '/../../system/');
     $i = 1;
     global $home, $processed_files;
     $home = array('funcs' => array(), 'classes' => array(), 'methods' => array(), 'tree' => array(), 'interfaces' => array(), 'namespaces' => array());
     $processed_files = array();
     $all_files = system_glob_rec($path, '*.php');
     $cnt_all_files = count($all_files);
     foreach ($all_files as $file) {
         if ($this->skip($file)) {
             $cnt_all_files--;
             continue;
         }
         $title = str_replace($path . '/', '', $file);
         $fn_cls = __DIR__ . '/out/classes_' . str_replace('.php.md', '.md', str_replace('/', '_', $title) . '.md');
         $fn_fnc = __DIR__ . '/out/functions_' . str_replace('.php.md', '.md', str_replace('/', '_', $title) . '.md');
         $this->_startSection("FILE: {$file}");
         $data = $this->process($file);
         if ($i++ > self::MAX_FILES) {
             $this->content("<h1>Stopping, still " . ($cnt_all_files - self::MAX_FILES) . " missing</h1>");
             break;
         }
         // functions
         $lines = array();
         foreach ($data['functions'] as $func) {
             $l = $this->funcToMd($func);
             if ($l) {
                 $home['funcs'][$func['name']] = basename($fn_fnc, '.md') . "#wiki-" . md5($func['name']);
                 $lines[] = $l;
                 //					$processed_files[$title][] = $func['name']; // we do not want functions in the folder tree
             }
         }
         if (count($lines) > 0) {
             file_put_contents($fn_fnc, $this->escapeMd("# Functions in file {$title}\n" . implode("\n", $lines)));
         }
         // classes
         $lines = array();
         foreach ($data['classes'] as $class) {
             //				log_if($class['name']=="uiControl",$class['name'],$class);
             $lines[] = $this->classToMd($class, basename($fn_cls, '.md'));
             if ($class['type'] == 'interface' && !isset($home['interfaces'][$class['type']])) {
                 $home['interfaces'][$class['name']] = array();
             }
             if (isset($class['implements'])) {
                 foreach ($class['implements'] as $int) {
                     if (!isset($home['interfaces'][$int])) {
                         $home['interfaces'][$int] = array($class['name']);
                     } else {
                         $home['interfaces'][$int][] = $class['name'];
                     }
                 }
             }
             $processed_files[$title][] = $class['name'];
         }
         if (count($lines) > 0) {
             file_put_contents($fn_cls, $this->escapeMd("# Classes in file {$title}\n" . implode("\n", $lines)));
         }
     }
     $this->_endSection();
     $this->writeIndexes();
     $this->createLinks();
     $this->writeZip();
     if (array_sum($this->sums) > 0 || count($this->errors) > 0) {
         $summary->addClass('summary');
         $summary->content("<b>Summary:</b><br/>");
         if ($this->sums['comment'] > 0) {
             $summary->content("Missing comments: {$this->sums['comment']}<br/>");
         }
         if ($this->sums['short'] > 0) {
             $summary->content("Missing short descriptions: {$this->sums['short']}<br/>");
         }
         if ($this->sums['long'] > 0) {
             $summary->content("Missing long descriptions: {$this->sums['long']}<br/>");
         }
         if ($this->sums['param'] > 0) {
             $summary->content("Missing param descriptions: {$this->sums['param']}<br/>");
         }
         if ($this->sums['return'] > 0) {
             $summary->content("Missing return value descriptions: {$this->sums['return']}<br/>");
         }
         foreach ($this->errors as $err) {
             $summary->content("{$err}<br/>");
         }
     }
 }