Exemplo n.º 1
0
 /**
  * Executes the business logic involved with this command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws \Exception if the target location is not a folder.
  *
  * @return integer
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var ConfigurationHelper $configurationHelper */
     $configurationHelper = $this->getHelper('phpdocumentor_configuration');
     $target = $configurationHelper->getOption($input, 'target', 'parser/target');
     if (strpos($target, '/tmp/') === 0) {
         $target = str_replace('/tmp/', sys_get_temp_dir() . DIRECTORY_SEPARATOR, $target);
     }
     $fileSystem = new Filesystem();
     if (!$fileSystem->isAbsolutePath($target)) {
         $target = getcwd() . DIRECTORY_SEPARATOR . $target;
     }
     if (!file_exists($target)) {
         mkdir($target, 0777, true);
     }
     if (!is_dir($target)) {
         throw new \Exception($this->__('PPCPP:EXC-BADTARGET'));
     }
     $this->getCache()->getOptions()->setCacheDir($target);
     $builder = $this->getBuilder();
     $builder->createProjectDescriptor();
     $projectDescriptor = $builder->getProjectDescriptor();
     $output->write($this->__('PPCPP:LOG-COLLECTING'));
     $files = $this->getFileCollection($input);
     /** @var Finder $exampleFinder */
     $exampleFinder = $this->getContainer()->offsetGet('parser.example.finder');
     $exampleFinder->setSourceDirectory($files->getProjectRoot());
     $exampleFinder->setExampleDirectories($configurationHelper->getConfigValueFromPath('files/examples'));
     $output->writeln($this->__('PPCPP:LOG-OK'));
     /** @var ProgressHelper $progress  */
     $progress = $this->getProgressBar($input);
     if (!$progress) {
         $this->getHelper('phpdocumentor_logger')->connectOutputToLogging($output, $this);
     }
     $output->write($this->__('PPCPP:LOG-INITIALIZING'));
     $this->populateParser($input, $files);
     if ($progress) {
         $progress->start($output, $files->count());
     }
     try {
         $output->writeln($this->__('PPCPP:LOG-OK'));
         $output->writeln($this->__('PPCPP:LOG-PARSING'));
         $mapper = new ProjectDescriptorMapper($this->getCache());
         $mapper->garbageCollect($files);
         $mapper->populate($projectDescriptor);
         $visibility = (array) $configurationHelper->getOption($input, 'visibility', 'parser/visibility');
         $visibilities = array();
         foreach ($visibility as $item) {
             $visibilities = $visibilities + explode(',', $item);
         }
         $visibility = null;
         foreach ($visibilities as $item) {
             switch ($item) {
                 case 'public':
                     $visibility |= ProjectDescriptor\Settings::VISIBILITY_PUBLIC;
                     break;
                 case 'protected':
                     $visibility |= ProjectDescriptor\Settings::VISIBILITY_PROTECTED;
                     break;
                 case 'private':
                     $visibility |= ProjectDescriptor\Settings::VISIBILITY_PRIVATE;
                     break;
             }
         }
         if ($visibility === null) {
             $visibility = ProjectDescriptor\Settings::VISIBILITY_DEFAULT;
         }
         if ($input->getOption('parseprivate')) {
             $visibility = $visibility | ProjectDescriptor\Settings::VISIBILITY_INTERNAL;
         }
         $projectDescriptor->getSettings()->setVisibility($visibility);
         $this->getParser()->parse($builder, $files);
     } catch (FilesNotFoundException $e) {
         throw new \Exception($this->__('PPCPP:EXC-NOFILES'));
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage(), 0, $e);
     }
     if ($progress) {
         $progress->finish();
     }
     $projectDescriptor->setPartials($this->getService('partials'));
     $output->write($this->__('PPCPP:LOG-STORECACHE', (array) $this->getCache()->getOptions()->getCacheDir()));
     $projectDescriptor->getSettings()->clearModifiedFlag();
     $mapper->save($projectDescriptor);
     $output->writeln($this->__('PPCPP:LOG-OK'));
     return 0;
 }
Exemplo n.º 2
0
 /**
  * Executes the business logic involved with this command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return integer
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // invoke parent to load custom config
     parent::execute($input, $output);
     $target = $this->getOption($input, 'target', 'parser/target');
     if (!$this->isAbsolute($target)) {
         $target = getcwd() . DIRECTORY_SEPARATOR . $target;
     }
     if (!file_exists($target)) {
         mkdir($target, 0777, true);
     }
     if (!is_dir($target)) {
         throw new \Exception($this->__('PPCPP:EXC-BADTARGET'));
     }
     $this->getCache()->getOptions()->setCacheDir($target);
     $builder = $this->getBuilder();
     $builder->createProjectDescriptor();
     $projectDescriptor = $builder->getProjectDescriptor();
     $visibility = ProjectDescriptor\Settings::VISIBILITY_DEFAULT;
     if ($input->getOption('parseprivate')) {
         $visibility = $visibility | ProjectDescriptor\Settings::VISIBILITY_INTERNAL;
     }
     $projectDescriptor->getSettings()->setVisibility($visibility);
     $output->write($this->__('PPCPP:LOG-COLLECTING'));
     $files = $this->getFileCollection($input);
     $output->writeln($this->__('PPCPP:LOG-OK'));
     /** @var ProgressHelper $progress  */
     $progress = $this->getProgressBar($input);
     if (!$progress) {
         $this->connectOutputToLogging($output);
     }
     $output->write($this->__('PPCPP:LOG-INITIALIZING'));
     $this->populateParser($input, $files);
     if ($progress) {
         $progress->start($output, $files->count());
     }
     try {
         $output->writeln($this->__('PPCPP:LOG-OK'));
         $output->writeln($this->__('PPCPP:LOG-PARSING'));
         $mapper = new ProjectDescriptorMapper($this->getCache());
         $mapper->garbageCollect($files);
         $mapper->populate($projectDescriptor);
         $this->getParser()->parse($builder, $files);
     } catch (FilesNotFoundException $e) {
         throw new \Exception($this->__('PPCPP:EXC-NOFILES'));
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage(), 0, $e);
     }
     if ($progress) {
         $progress->finish();
     }
     $output->write($this->__('PPCPP:LOG-STORECACHE', (array) $this->getCache()->getOptions()->getCacheDir()));
     $mapper->save($projectDescriptor);
     $output->writeln($this->__('PPCPP:LOG-OK'));
     return 0;
 }