/** * Executes the business logic involved with this command. * * @param InputInterface $input * @param OutputInterface $output * * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { // invoke parent to load custom config parent::execute($input, $output); /** @var \phpDocumentor\Console\Helper\ProgressHelper $progress */ $progress = $this->getProgressBar($input); if (!$progress) { $this->connectOutputToLogging($output); } $output->write('Initializing parser and collecting files .. '); $target = $this->getTarget($this->getOption($input, 'target', 'parser/target')); $parser = new \phpDocumentor\Parser\Parser(); $parser->setTitle((string) $this->getOption($input, 'title', 'title')); $parser->setExistingXml($target); $parser->setForced($input->getOption('force')); $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')); $files = $this->getFileCollection($input); $parser->setPath($files->getProjectRoot()); if ($progress) { $progress->start($output, $files->count()); } try { // save the generate file to the path given as the 'target' option $output->writeln('OK'); $output->writeln('Parsing files'); $result = $parser->parseFiles($files, $input->getOption('sourcecode')); } catch (\Exception $e) { if ($e->getCode() === \phpDocumentor\Parser\Exception::NO_FILES_FOUND) { throw new \Exception('No parsable files were found, did you specify any using ' . 'the -f or -d parameter?'); } throw new \Exception($e->getMessage()); } if ($progress) { $progress->finish(); } $output->write('Storing structure.xml in "' . $target . '" .. '); file_put_contents($target, $result); $output->writeln('OK'); return 0; }