getInstance() public static method

public static getInstance ( ) : Context
return Context
Ejemplo n.º 1
0
 protected function executeActionListIfExist($name, $title = null)
 {
     $actions = Context::getInstance()->getList($name);
     if (count($actions) > 0) {
         $this->getOutput()->writeSmallTitle($title ?: ucfirst($name));
         $this->getOutput()->indent();
         foreach ($actions as $num => $action) {
             $this->getOutput()->write(++$num . ') ' . $action->getTitle() . ' : ');
             $this->getOutput()->indent();
             $action->execute();
             $this->getOutput()->writeEmptyLine();
             $this->getOutput()->unIndent();
         }
         $this->getOutput()->unIndent();
     }
 }
Ejemplo n.º 2
0
 public function loadContext()
 {
     $configHandler = new Handler($this->getApplication()->getConfig(), $this->getApplication()->getProjectRootDir());
     $config = $configHandler->getBaseConfig();
     // Select a branch specific config if a VCS is in use
     if (isset($config['vcs'])) {
         Context::getInstance()->setService('vcs', $config['vcs']['class'], $config['vcs']['options']);
         /** @var VCSInterface $vcs */
         $vcs = Context::get('vcs');
         try {
             $branch = $vcs->getCurrentBranch();
         } catch (\Exception $e) {
             echo "Impossible to read the branch name";
         }
         if (isset($branch)) {
             $config = $configHandler->getConfigForBranch($branch);
         }
     }
     // Store the config for latter usage
     Context::getInstance()->setParameter('config', $config);
     // Populate the context
     foreach (array('version-generator', 'version-persister') as $service) {
         Context::getInstance()->setService($service, $config[$service]['class'], $config[$service]['options']);
     }
     foreach (array('prerequisites', 'pre-release-actions', 'post-release-actions') as $listName) {
         Context::getInstance()->createEmptyList($listName);
         foreach ($config[$listName] as $service) {
             Context::getInstance()->addToList($listName, $service['class'], $service['options']);
         }
     }
     // Provide the root dir as a context parameter
     Context::getInstance()->setParameter('project-root', $this->getApplication()->getProjectRootDir());
 }
Ejemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->loadContext();
     $output->writeln('<info>Current configuration is:</info>');
     $output->writeln(Yaml::dump(Context::getInstance()->getParam('config')));
 }