コード例 #1
0
 /**
  * Demonstrates the basic usage the the ProjectDescriptorBuilder.
  *
  * This test scenario demonstrates how a ProjectDescriptorBuilder can be used to create a new ProjectDescriptor
  * and populate it with a single FileDescriptor using a FileReflector as source.
  *
  * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::createProjectDescriptor
  * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::buildFileUsingSourceData
  * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::getProjectDescriptor
  *
  * @see self::setUp on how to create an instance of the builder.
  *
  * @return void
  */
 public function testCreateNewProjectDescriptorAndBuildFile()
 {
     $this->markTestIncomplete('Finish later, in a hurry now.');
     // we use a FileReflector as example input
     $data = $this->createFileReflectorMock();
     $this->createFileDescriptorCreationMock();
     // usage example, see the setup how to instantiate the builder.
     $this->fixture->createProjectDescriptor();
     $this->fixture->buildFileUsingSourceData($data);
     $projectDescriptor = $this->fixture->getProjectDescriptor();
     // assert functioning
     $this->assertInstanceOf('phpDocumentor\\Descriptor\\ProjectDescriptor', $projectDescriptor);
     $this->assertCount(1, $projectDescriptor->getFiles());
 }
コード例 #2
0
ファイル: Parser.php プロジェクト: michaelyin1/Modern-Toolkit
 /**
  * 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();
 }