Example #1
0
 /** @covers \phpDocumentor\Fileset\Collection::getFilenames() */
 public function testGetFilenamesWhenIgnorePatternHidesSomething()
 {
     // load the data test folder... must add non-default extensions first
     $this->fixture->setAllowedExtensions(array('phar', 'txt'));
     $this->fixture->getIgnorePatterns()->append('(phar)');
     $this->fixture->addDirectory($this->getNameOfDataDir());
     $files = $this->fixture->getFilenames();
     // this file should have been seen
     $this->assertContains(realpath($this->getNameOfDataDir() . 'fileWithText.txt'), $files);
     // this file should have been ignored
     $this->assertNotContains(realpath($this->getNameOfDataDir() . 'test.phar'), $files);
 }
 /**
  * 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);
             }
         }
     }
 }
Example #3
0
 /**
  * Extract all filenames from the given collection and output the amount of files.
  *
  * @param Collection $files
  *
  * @throws FilesNotFoundException if no files were found.
  *
  * @return string[]
  */
 protected function getFilenames(Collection $files)
 {
     $paths = $files->getFilenames();
     if (count($paths) < 1) {
         throw new FilesNotFoundException();
     }
     $this->log('Starting to process ' . count($paths) . ' files');
     return $paths;
 }
Example #4
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();
 }