Example #1
0
 public function init()
 {
     $cwd = getcwd();
     // create data dir
     if (!file_exists(".xref")) {
         echo "Creating dir .xref\n";
         if (!mkdir(".xref")) {
             throw new Exception("Can't create dir .xref");
         }
     }
     $config_filename = ".xref/xref.ini";
     if (file_exists($config_filename)) {
         echo "Config file {$config_filename} exists; won't overwrite\n";
     } else {
         echo "Creating config file {$config_filename}\n";
         // create config file
         $fh = fopen($config_filename, "w");
         if (!$fh) {
             throw new Exception("Can't create file {$config_filename}");
         }
         $config = array();
         $config[] = "[project]";
         $config[] = array("name", basename($cwd));
         $config[] = array("source-code-dir[]", realpath($cwd));
         $config[] = array(";source-url", 'https://github.com/<author>/<project>/blob/{%revision}/{%fileName}#L{%lineNumber}');
         $config[] = null;
         $config[] = "[xref]";
         $config[] = array("data-dir", realpath("{$cwd}/.xref"));
         $config[] = array("project-check", "true");
         $config[] = array(";smarty-class", "/path/to/Smarty.class.php");
         $config[] = array(";script-url", "http://xref.your.domain.com/bin");
         $config[] = null;
         $config[] = "[lint]";
         $config[] = array("ignore-missing-class[]", 'PHPUnit_Framework_TestCase');
         $config[] = array(";ignore-error[]", 'xr052');
         $config[] = null;
         $config[] = "[doc]";
         $config[] = array(";output-dir", "/path/for/generated/doc");
         $config[] = null;
         if (file_exists(".git")) {
             // TODO: need a better way to check that this is a git project
             // http://stackoverflow.com/questions/957928
             // git rev-parse --show-toplevel
             $config[] = "[git]";
             $config[] = array("repository-dir", realpath($cwd));
             $config[] = null;
             $config[] = "[ci]";
             $config[] = array("incremental", "true");
             $config[] = array("update-repository", "true");
             $config[] = null;
             $config[] = "[mail]";
             $config[] = array("from", "XRef Continuous Integration");
             $config[] = array(";reply-to", "*****@*****.**");
             $config[] = array(";to[]", "{%ae}");
             $config[] = array(";to[]", "*****@*****.**");
             $config[] = null;
         }
         foreach ($config as $line) {
             $l = null;
             if (!$line) {
                 $l = "\n";
             } elseif (!is_array($line)) {
                 $l = "{$line}\n";
             } else {
                 list($k, $v) = $line;
                 if (preg_match('#^\\w+$#', $v)) {
                     $l = sprintf("%-24s= %s\n", $k, $v);
                 } else {
                     $v = preg_replace('#\\\\#', '\\\\', $v);
                     $l = sprintf("%-24s= \"%s\"\n", $k, $v);
                 }
             }
             fwrite($fh, $l);
         }
         fclose($fh);
         // re-read config values from the file
         self::getConfig(true);
     }
     // index files for the first time
     $this->loadPluginGroup('lint');
     $file_provider = new XRef_FileProvider_FileSystem($cwd);
     $lint_engine = new XRef_LintEngine_ProjectCheck($this);
     $lint_engine->setShowProgressBar(true);
     $lint_engine->setRewriteCache(true);
     // re-index files and refill cache
     echo "Indexing files\n";
     $lint_engine->getReport($file_provider);
     echo "\nDone.\n";
     // done
 }