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());
 }
Beispiel #2
0
 /** @covers \phpDocumentor\Fileset\Collection::getFollowSymlinks() */
 public function testGetFollowSymlinksGivenTrue()
 {
     /*
      * NOTE:
      *     this does not verify that symlinks were followed...
      *     it simply exercises the getFollowSymlinks() method.
      */
     $this->fixture->setFollowSymlinks(true);
     $this->assertTrue($this->fixture->getFollowSymlinks());
 }
Beispiel #3
0
 /**
  * Returns the collection of files based on the input and configuration.
  *
  * @param InputInterface $input
  *
  * @return Collection
  */
 protected function getFileCollection($input)
 {
     /** @var ConfigurationHelper $configurationHelper */
     $configurationHelper = $this->getHelper('phpdocumentor_configuration');
     $this->files->setAllowedExtensions($configurationHelper->getOption($input, 'extensions', 'parser/extensions', array('php', 'php3', 'phtml'), true));
     $this->files->setIgnorePatterns($configurationHelper->getOption($input, 'ignore', 'files/ignore', array(), true));
     $ignoreHidden = $configurationHelper->getOption($input, 'hidden', 'files/ignore-hidden', 'off');
     $this->files->setIgnoreHidden($ignoreHidden !== 'off' && $ignoreHidden === false);
     $this->files->setFollowSymlinks($configurationHelper->getOption($input, 'ignore-symlinks', 'files/ignore-symlinks', 'off') == 'on');
     $file_options = (array) $configurationHelper->getOption($input, 'filename', 'files/files', array(), true);
     $added_files = array();
     foreach ($file_options as $glob) {
         if (!is_string($glob)) {
             continue;
         }
         $matches = glob($glob);
         if (is_array($matches)) {
             foreach ($matches as $file) {
                 if (!empty($file)) {
                     $file = realpath($file);
                     if (!empty($file)) {
                         $added_files[] = $file;
                     }
                 }
             }
         }
     }
     $this->files->addFiles($added_files);
     $directory_options = $configurationHelper->getOption($input, 'directory', 'files/directories', array(), true);
     $added_directories = array();
     foreach ($directory_options as $glob) {
         if (!is_string($glob)) {
             continue;
         }
         $matches = glob($glob, GLOB_ONLYDIR);
         if (is_array($matches)) {
             foreach ($matches as $dir) {
                 if (!empty($dir)) {
                     $dir = realpath($dir);
                     if (!empty($dir)) {
                         $added_directories[] = $dir;
                     }
                 }
             }
         }
     }
     $this->files->addDirectories($added_directories);
     return $this->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);
             }
         }
     }
 }
 /**
  * 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()));
 }
Beispiel #6
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;
 }
 /**
  * Constructs a Fileset collection and returns that.
  *
  * @param array $sources    List of source paths.
  * @param array $extensions List of extensions to scan for in directories.
  *
  * @return Collection
  */
 protected function buildCollection(array $sources, array $extensions)
 {
     $collection = new Collection();
     $collection->setAllowedExtensions($extensions);
     foreach ($sources as $path) {
         if (is_dir($path)) {
             $collection->addDirectory($path);
             continue;
         }
         $collection->addFile($path);
     }
     return $collection;
 }
Beispiel #8
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();
 }