Example #1
0
function GetPHPFiles(&$result, $path)
{
    global $excludefiles;
    $dir = opendir($path);
    if ($dir) {
        while (($file = readdir($dir)) !== false) {
            if (!isset($excludefiles[$file])) {
                $filename = $path . "/" . $file;
                if (is_dir($filename)) {
                    GetPHPFiles($result, $filename);
                } else {
                    if (substr($filename, -4) === ".php") {
                        $fp = fopen($filename, "rb");
                        while (($line = fgets($fp)) !== false) {
                            $line = trim($line);
                            if (substr($line, 0, 6) === "class ") {
                                $line = trim(substr($line, 6));
                                $pos = strpos($line, " ");
                                if ($pos === false) {
                                    $pos = strlen($line);
                                }
                                $name = substr($line, 0, $pos);
                                if (isset($result[$name]) && filemtime($result[$name]) < filemtime($filename)) {
                                    unset($result[$name]);
                                }
                                if (!isset($result[$name])) {
                                    $result[$name] = $filename;
                                }
                            }
                        }
                        fclose($fp);
                    }
                }
            }
        }
        closedir($dir);
    }
}
Example #2
0
if (!is_dir($srcpath)) {
    mkdir($srcpath);
}
if (!is_dir($destpath)) {
    mkdir($destpath);
}
// Update the registered repo list.  If nothing has changed, exit.
$numchanged = (int) GitRepoChanged($rootpath) + GitPull($srcpath);
if (!$numchanged) {
    exit;
}
// Always do a full rebuild.
DeleteDirectory($destpath);
// Retrieve a list of all PHP files that contain 'class' + a name.
$files = array();
GetPHPFiles($files, $srcpath);
// Generate final file set.
foreach ($files as $name => $filename) {
    $data = file_get_contents($filename);
    // Remove standard inclusion lines so that the autoloader does its thing.
    $lines = explode("\n", $data);
    foreach ($lines as $num => $line) {
        $line = trim($line);
        if (substr($line, 0, 18) === "if (!class_exists(") {
            $lines[$num] = "";
        }
    }
    $data = implode("\n", $lines);
    unset($files[$name]);
    $name = str_replace("\\CubicleSoft\\", "", $name);
    $files[$name] = "/" . $name . ".php";