/**
  * @see	Action::execute()
  */
 public function execute()
 {
     parent::execute();
     if (!file_exists($this->sourceFile->getPath())) {
         throw new SystemException("Requested file '" . $this->sourceFile->filename . "' for source identified by '" . $this->sourceFile->sourceID . "' is missing.");
     }
     @header('Content-Type: application/x-gzip');
     @header('Content-length: ' . filesize($this->sourceFile->getPath()));
     @header('Content-disposition: attachment; filename="' . $this->sourceFile->filename . '"');
     readfile($this->sourceFile->getPath());
     exit;
 }
Beispiel #2
0
 /**
  * Parse a given file for defintions of classes, traits and interfaces
  *
  * @param SourceFile $source file to process
  *
  * @return ParseResult
  */
 public function parse(SourceFile $source)
 {
     $this->found = array();
     $this->redeclarations = array();
     $this->inNamespace = '';
     $this->aliases = array();
     $this->bracketLevel = 0;
     $this->inUnit = '';
     $this->nsBracket = 0;
     $this->classBracket = 0;
     $this->tokenArray = $source->getTokens();
     $tokenCount = count($this->tokenArray);
     $tokList = array_keys($this->methodMap);
     for ($t = 0; $t < $tokenCount; $t++) {
         $current = (array) $this->tokenArray[$t];
         if ($current[0] == T_STRING && $current[1] == 'trait' && T_TRAIT == -1) {
             // PHP < 5.4 compat fix
             $current[0] = T_TRAIT_53;
             $this->tokenArray[$t] = $current;
         }
         if (!in_array($current[0], $tokList)) {
             continue;
         }
         // PHP 5.5 has classname::class, reusing T_CLASS
         if ($this->tokenArray[$t - 1][0] == T_DOUBLE_COLON) {
             continue;
         }
         $t = call_user_func(array($this, $this->methodMap[$current[0]]), $t);
     }
     return new ParseResult($this->found, $this->dependencies, $this->redeclarations);
 }
Beispiel #3
0
 public function parse_source_file()
 {
     $source = new SourceFile();
     while (!$this->eof()) {
         if ($this->at(array(T_ABSTRACT, T_FINAL, T_CLASS))) {
             $source->push($this->parse_class());
         } elseif ($this->at(T_NAMESPACE)) {
             $this->accept();
             $this->s();
             // TODO: finish
         } else {
             $source->push($this->current_text());
             $this->accept();
         }
     }
     return $source;
 }
 /**
  * Processes specified file or directory.
  *
  * @param   string $path Absolute path to the file or directory.
  */
 protected function processFile($path)
 {
     if (is_dir($path)) {
         $files = scandir($path);
         foreach ($files as $file) {
             if ($file !== '.' && $file !== '..') {
                 $this->processFile(realpath(sprintf('%s%s%s', $path, DIRECTORY_SEPARATOR, $file)));
             }
         }
     } else {
         try {
             $file = new SourceFile($path);
             $this->literals = array_merge($this->literals, $file->getAllLiterals());
             $this->count++;
         } catch (\RuntimeException $e) {
         }
     }
 }
 public function __construct($taskName, SourceFile $sourceFile, array $targetFiles, $taskID = NULL, $userID = 'nobody', $executeMode = 0, $callback = '', $priority = 0)
 {
     $this->taskName = $taskName;
     $this->sourceFile = $sourceFile->toXML();
     $this->targetFiles = '';
     foreach ($targetFiles as $targetFile) {
         if ($targetFile instanceof TargetFileInterface) {
             $this->targetFiles .= $targetFile->toXML();
         }
     }
     if (is_null($taskID)) {
         $this->taskID = \Hoge\gen_uuid();
     } else {
         $this->taskID = $taskID;
     }
     $this->userID = $userID;
     $this->executeMode = $executeMode;
     $this->callbackAddressInfo = $callback;
     $this->priority = $priority;
 }
 /**
  * Delete all changesets for a given repository ID.
  * @param int Repository ID
  */
 static function delete_by_repo($p_repo_id)
 {
     $t_bug_table = plugin_table('bug', 'Source');
     $t_changeset_table = plugin_table('changeset', 'Source');
     # first drop any files for the repository's changesets
     SourceFile::delete_by_repo($p_repo_id);
     $t_query = "DELETE FROM {$t_changeset_table} WHERE repo_id=" . db_param();
     db_query_bound($t_query, array($p_repo_id));
 }
 function renderSummary(Aggregator $agg, array $results, $basePath, $istest = false, $total = 1, $covered = 1, $dead = 1)
 {
     $output = new \XMLWriter();
     if ($istest) {
         if (!$output->openUri($this->savePath . '/index-' . str_replace($istest, '/', '@') . '.html')) {
             throw new Exception('Cannot render test  ' . $istest . ' summary, opening XML failed');
         }
     } else {
         if (!$output->openUri($this->savePath . '/index.html')) {
             throw new Exception('Cannot render test summary, opening XML failed');
         }
     }
     $output->setIndentString(' ');
     $output->setIndent(true);
     $output->startElement('html');
     $output->startElement('head');
     if ($istest) {
         $output->writeElement('title', 'Code Coverage Summary [' . $istest . ']');
     } else {
         $output->writeElement('title', 'Code Coverage Summary');
     }
     $output->startElement('link');
     $output->writeAttribute('href', 'cover.css');
     $output->writeAttribute('rel', 'stylesheet');
     $output->writeAttribute('type', 'text/css');
     $output->endElement();
     $output->endElement();
     $output->startElement('body');
     if ($istest) {
         $output->writeElement('h2', 'Code Coverage Files for test ' . $istest);
     } else {
         $output->writeElement('h2', 'Code Coverage Files for ' . $basePath);
         $output->writeElement('h3', 'Total lines: ' . $total . ', covered lines: ' . $covered . ', dead lines: ' . $dead);
         $percent = 0;
         if ($total > 0) {
             $percent = round($covered / $total * 100);
         }
         $output->startElement('p');
         if ($percent < 50) {
             $output->writeAttribute('class', 'bad');
         } elseif ($percent < 75) {
             $output->writeAttribute('class', 'ok');
         } else {
             $output->writeAttribute('class', 'good');
         }
         $output->text($percent . '% code coverage');
         $output->endElement();
     }
     $output->startElement('p');
     $output->startElement('a');
     $output->writeAttribute('href', 'index-test.html');
     $output->text('Code Coverage per PHPT test');
     $output->endElement();
     $output->endElement();
     $output->startElement('ul');
     echo "[Step 1 of 2] Rendering files\n";
     foreach ($results as $i => $name) {
         echo '(' . ($i + 1) . ' of ' . count($results) . ') ' . $name . "\n";
         $source = new SourceFile($name, $agg, $this->testPath, $this->sourcePath);
         $output->startElement('li');
         $percent = $source->coveragePercentage();
         $output->startElement('div');
         if ($percent < 50) {
             $output->writeAttribute('class', 'bad');
         } elseif ($percent < 75) {
             $output->writeAttribute('class', 'ok');
         } else {
             $output->writeAttribute('class', 'good');
         }
         $output->text(' Coverage: ' . str_pad($percent . '%', 4, ' ', STR_PAD_LEFT));
         $output->endElement();
         $output->startElement('a');
         $output->writeAttribute('href', $this->mangleFile($name, $istest));
         $output->text($source->shortName());
         $output->endElement();
         $output->endElement();
         $source->render($this);
     }
     echo "done\n";
     $output->endElement();
     $output->endElement();
     $output->endDocument();
 }
Beispiel #8
0
 public function addResult(SourceFile $file, ParseResult $result)
 {
     $this->usedEntries[$file->getPathname()] = new CacheEntry($file->getMTime(), $result);
 }
Beispiel #9
0
 public static function register_file(SourceFile $file)
 {
     foreach ($file->get_defined_classes() as $class) {
         self::register_class($class);
     }
 }