Example #1
0
 /** @covers \phpDocumentor\Fileset\Collection::getProjectRoot() */
 public function testGetProjectRootWhenTwoFilesAreVeryFarApart()
 {
     $this->fixture->addFile(__FILE__);
     $this->fixture->addFile($this->getNameOfDataDir() . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'phpDocumentor' . DIRECTORY_SEPARATOR . 'Fileset' . DIRECTORY_SEPARATOR . 'Collection.php');
     // realpath() steals our trailing directory separator
     $expected = realpath($this->getNameOfDataDir() . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     $this->assertEquals($expected, $this->fixture->getProjectRoot());
 }
 public function populate(Parser $parser, InputInterface $input, ConfigurationHelper $configurationHelper, Collection $files)
 {
     $parser->setForced($input->getOption('force'));
     $parser->setEncoding($configurationHelper->getOption($input, 'encoding', 'parser/encoding'));
     $parser->setMarkers($configurationHelper->getOption($input, 'markers', 'parser/markers', array('TODO', 'FIXME'), true));
     $parser->setIgnoredTags($input->getOption('ignore-tags'));
     $parser->setValidate($input->getOption('validate'));
     $parser->setDefaultPackageName($configurationHelper->getOption($input, 'defaultpackagename', 'parser/default-package-name'));
     $parser->setPath($files->getProjectRoot());
 }
 /**
  * Removes all files in cache that do not occur in the given FileSet Collection.
  *
  * @param Collection $collection
  *
  * @return void
  */
 public function garbageCollect(Collection $collection)
 {
     $projectRoot = $collection->getProjectRoot();
     $filenames = $collection->getFilenames();
     foreach ($filenames as &$name) {
         // the cache key contains a path relative to the project root; here we expect absolute paths.
         $name = self::FILE_PREFIX . md5(substr($name, strlen($projectRoot)));
     }
     /** @var IteratorInterface $iteratorInterface  */
     $iteratorInterface = $this->getCache()->getIterator();
     // FIXME: Workaround for: https://github.com/zendframework/zf2/pull/4154
     if ($iteratorInterface->valid()) {
         foreach ($this->getCache() as $item) {
             if (!in_array($item, $filenames)) {
                 $this->getCache()->removeItem($item);
             }
         }
     }
 }
 /**
  * Returns the filename relative to the Project Root of the fileset.
  *
  * @param File $file
  *
  * @return string
  */
 public function getDestinationFilenameRelativeToProjectRoot(File $file)
 {
     return substr($this->getDestinationFilename($file), strlen($this->fileset->getProjectRoot()));
 }
 /**
  * @param InputInterface $input
  * @param Collection     $files
  */
 protected function populateParser(InputInterface $input, Collection $files)
 {
     $parser = $this->getParser();
     $title = (string) $this->getOption($input, 'title', 'title');
     $this->getBuilder()->getProjectDescriptor()->setName($title ?: 'API Documentation');
     $parser->setForced($input->getOption('force'));
     $parser->setEncoding($this->getOption($input, 'encoding', 'parser/encoding'));
     $parser->setMarkers($this->getOption($input, 'markers', 'parser/markers/item', null, true));
     $parser->setIgnoredTags($input->getOption('ignore-tags'));
     $parser->setValidate($input->getOption('validate'));
     $parser->setVisibility((string) $this->getOption($input, 'visibility', 'parser/visibility'));
     $parser->setDefaultPackageName($this->getOption($input, 'defaultpackagename', 'parser/default-package-name'));
     $parser->setPath($files->getProjectRoot());
 }
Example #6
0
 /**
  * Iterates through the given files and builds the structure.xml file.
  *
  * @param \phpDocumentor\Fileset\Collection $files          A files container
  *     to parse.
  * @param bool                           $include_source whether to include
  *     the source in the generated output..
  *
  * @api
  *
  * @return bool|string
  */
 public function parseFiles(\phpDocumentor\Fileset\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) {
         $this->dispatch('parser.file.pre', array('file' => $file, 'progress' => array($key + 1, $file_count)));
         $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();
 }
 /**
  * @param InputInterface $input
  * @param Collection     $files
  */
 protected function populateParser(InputInterface $input, Collection $files)
 {
     /** @var ConfigurationHelper $configurationHelper */
     $configurationHelper = $this->getHelper('phpdocumentor_configuration');
     $parser = $this->getParser();
     $title = (string) $configurationHelper->getOption($input, 'title', 'title');
     $this->getBuilder()->getProjectDescriptor()->setName($title ?: 'API Documentation');
     $parser->setForced($input->getOption('force'));
     $parser->setEncoding($configurationHelper->getOption($input, 'encoding', 'parser/encoding'));
     $parser->setMarkers($configurationHelper->getOption($input, 'markers', 'parser/markers', array(), true));
     $parser->setIgnoredTags($input->getOption('ignore-tags'));
     $parser->setValidate($input->getOption('validate'));
     $parser->setDefaultPackageName($configurationHelper->getOption($input, 'defaultpackagename', 'parser/default-package-name'));
     $parser->setPath($files->getProjectRoot());
 }