示例#1
0
 /**
  * Parses the file identified by the given filename and passes the resulting FileDescriptor to the ProjectBuilder.
  *
  * @param string                   $filename
  * @param ProjectDescriptorBuilder $builder
  *
  * @return void
  */
 public function parse($filename, ProjectDescriptorBuilder $builder)
 {
     if (class_exists('phpDocumentor\\Event\\Dispatcher')) {
         Dispatcher::getInstance()->dispatch('parser.file.pre', PreFileEvent::createInstance($this)->setFile($filename));
     }
     $this->log('Starting to parse file: ' . $filename);
     try {
         $file = $this->createFileReflector($builder, $filename);
         if (!$file) {
             $this->log('>> Skipped file ' . $filename . ' as no modifications were detected');
             return;
         }
         $file->process();
         $builder->buildFileUsingSourceData($file);
         $this->logErrorsForDescriptor($builder->getProjectDescriptor()->getFiles()->get($file->getFilename()));
     } catch (Exception $e) {
         $this->log('  Unable to parse file "' . $filename . '", an error was detected: ' . $e->getMessage(), LogLevel::ALERT);
     }
 }
示例#2
0
 /**
  * Iterates through the given files feeds them to the builder.
  *
  * @param ProjectDescriptorBuilder $builder
  * @param Collection               $files          A files container to parse.
  *
  * @api
  *
  * @throws Exception if no files were found.
  *
  * @return bool|string
  */
 public function parse(ProjectDescriptorBuilder $builder, Collection $files)
 {
     $timer = microtime(true);
     $paths = $this->getFilenames($files);
     $this->log('  Project root is:  ' . $files->getProjectRoot());
     $this->log('  Ignore paths are: ' . implode(', ', $files->getIgnorePatterns()->getArrayCopy()));
     if ($builder->getProjectDescriptor()->getSettings()->isModified()) {
         $this->setForced(true);
         $this->log('One of the project\'s settings have changed, forcing a complete rebuild');
     }
     foreach ($paths as $filename) {
         if (class_exists('phpDocumentor\\Event\\Dispatcher')) {
             Dispatcher::getInstance()->dispatch('parser.file.pre', PreFileEvent::createInstance($this)->setFile($filename));
         }
         $this->log('Starting to parse file: ' . $filename);
         $memory = memory_get_usage();
         try {
             $file = new FileReflector($filename, $this->doValidation(), $this->getEncoding());
             $file->setDefaultPackageName($this->getDefaultPackageName());
             $file->setMarkers($this->getMarkers());
             $file->setFilename($this->getRelativeFilename($filename));
             // if the hash is unchanged; continue to the next file
             $cachedFiles = $builder->getProjectDescriptor()->getFiles();
             $hash = $cachedFiles->get($file->getFilename()) ? $cachedFiles->get($file->getFilename())->getHash() : null;
             if ($hash === $file->getHash() && !$this->isForced()) {
                 $this->log('>> Skipped file ' . $file->getFilename() . ' as no modifications were detected');
                 continue;
             }
             $file->process();
             $builder->buildFileUsingSourceData($file);
             $fileDescriptor = $builder->getProjectDescriptor()->getFiles()->get($file->getFilename());
             $errors = $fileDescriptor->getAllErrors();
             foreach ($errors as $error) {
                 $this->log($error->getCode(), $error->getSeverity(), $error->getContext());
             }
         } catch (Exception $e) {
             $this->log('  Unable to parse file "' . $filename . '", an error was detected: ' . $e->getMessage(), LogLevel::ALERT);
         }
         $memoryDelta = memory_get_usage() - $memory;
         $this->log('>> Memory after processing of file: ' . number_format(memory_get_usage() / 1024 / 1024, 2) . ' megabytes (' . ($memoryDelta > -0 ? '+' : '') . number_format($memoryDelta / 1024) . ' kilobytes)', LogLevel::DEBUG);
     }
     $this->log('Elapsed time to parse all files: ' . round(microtime(true) - $timer, 2) . 's');
     $this->log('Peak memory usage: ' . round(memory_get_peak_usage() / 1024 / 1024, 2) . 'M');
     return $builder->getProjectDescriptor();
 }
示例#3
0
 /**
  * Iterates through the given files and builds the structure.xml file.
  *
  * @param Collection $files          A files container
  *     to parse.
  * @param bool       $include_source whether to include the source in the
  *     generated output..
  *
  * @api
  *
  * @throws Exception if no files were found.
  *
  * @return bool|string
  */
 public function parseFiles(Collection $files, $include_source = false)
 {
     $timer = microtime(true);
     $this->exporter = new \phpDocumentor\Parser\Exporter\Xml\Xml($this);
     $this->exporter->initialize();
     $paths = $files->getFilenames();
     $this->log('Starting to process ' . count($paths) . ' files');
     $this->log('  Project root is:  ' . $files->getProjectRoot());
     $this->log('  Ignore paths are: ' . implode(', ', $files->getIgnorePatterns()->getArrayCopy()));
     if (count($paths) < 1) {
         throw new Exception('No files were found', Exception::NO_FILES_FOUND);
     }
     $file_count = count($paths);
     foreach ($paths as $key => $file) {
         Dispatcher::getInstance()->dispatch('parser.file.pre', PreFileEvent::createInstance($this)->setFile($file));
         $this->parseFile($file, $include_source);
     }
     $this->exporter->finalize();
     $this->log('--');
     $this->log('Elapsed time to parse all files: ' . round(microtime(true) - $timer, 2) . 's');
     $this->log('Peak memory usage: ' . round(memory_get_peak_usage() / 1024 / 1024, 2) . 'M');
     return $this->exporter->getContents();
 }