undefinedToDefault() public static method

public static undefinedToDefault ( string $value, string | null $default = null ) : null | string
$value string
$default string | null
return null | string
Esempio n. 1
0
 /**
  * Use this for detecting the org and repo.
  *
  * Add the options to decorateDefinition.
  *
  * @param ConsoleEvent $event
  */
 public function initialize(ConsoleEvent $event)
 {
     $command = $event->getCommand();
     if (!$command instanceof InitCommand) {
         return;
     }
     if (!$this->gitHelper->isGitDir()) {
         throw new UserException(sprintf('You can only run the "%s" command when you are in a Git directory.', $command->getName()));
     }
     $input = $event->getInput();
     $input->setOption('repo-adapter', GitHelper::undefinedToDefault($input->getOption('repo-adapter'), $this->detectAdapterName()));
     $input->setOption('issue-adapter', GitHelper::undefinedToDefault($input->getOption('issue-adapter'), $input->getOption('repo-adapter')));
     if (!$this->application->getAdapterFactory()->supports($input->getOption('repo-adapter'), AdapterFactory::SUPPORT_REPOSITORY_MANAGER)) {
         return;
     }
     $org = GitHelper::undefinedToDefault($input->getOption('org'));
     $repo = GitHelper::undefinedToDefault($input->getOption('repo'));
     if (null === $org || null === $repo) {
         list($org, $repo) = $this->getRepositoryReference($this->getAdapter($input->getOption('repo-adapter')), $org, $repo);
         if (!$input->isInteractive()) {
             $this->styleHelper->note(['You did not provide an organization and/or repository name.', 'Gush automatically detected the missing information.', sprintf('Org: "%s" / repo: "%s"', $org, $repo)]);
         }
         $input->setOption('org', $org);
         $input->setOption('repo', $repo);
     }
     $input->setOption('issue-org', GitHelper::undefinedToDefault($input->getOption('issue-org'), $org));
     $input->setOption('issue-project', GitHelper::undefinedToDefault($input->getOption('issue-project'), $repo));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Gush\Application $application */
     $application = $this->getApplication();
     $config = $application->getConfig();
     $valid = true;
     /** @var StyleHelper $styleHelper */
     $styleHelper = $this->getHelper('gush_style');
     $adapters = $this->getAdapters();
     $repositoryManagers = $adapters[0];
     $issueTrackers = $adapters[1];
     $repositoryManager = GitHelper::undefinedToDefault($input->getOption('repo-adapter'));
     $issueTracker = GitHelper::undefinedToDefault($input->getOption('issue-adapter'));
     $org = GitHelper::undefinedToDefault($input->getOption('org'));
     $repo = GitHelper::undefinedToDefault($input->getOption('repo'));
     $issueOrg = GitHelper::undefinedToDefault($input->getOption('issue-org'), $org);
     $issueRepo = GitHelper::undefinedToDefault($input->getOption('issue-project'), $repo);
     $this->validateAdapter($repositoryManager, $repositoryManagers, 'Repository-manager', $valid);
     $this->validateAdapter($issueTracker, $issueTrackers, 'Issue-tracker', $valid);
     if (!$valid) {
         return self::COMMAND_FAILURE;
     }
     $this->checkAdapterConfigured($repositoryManager, $repositoryManagers[$repositoryManager], 'Repository-manager', $valid);
     $this->checkAdapterConfigured($issueTracker, $issueTrackers[$issueTracker], 'Issue-tracker', $valid);
     if (!$valid) {
         if ($input->isInteractive() && $styleHelper->confirm('Would you like to configure the missing adapters now?')) {
             $application->doRun(new ArrayInput(['command' => 'core:configure']), $output);
         } else {
             $styleHelper->note(['You cannot use the selected repository-manager and/or issue-tracker until its configured.', 'Run the "core:configure" command to configure the adapters.']);
         }
     }
     $params = ['repo_adapter' => $repositoryManager, 'issue_tracker' => $issueTracker, 'repo_org' => $org, 'repo_name' => $repo, 'issue_project_org' => $issueOrg, 'issue_project_name' => $issueRepo];
     $config->merge($params, Config::CONFIG_LOCAL);
     ConfigFactory::dumpToFile($config, Config::CONFIG_LOCAL);
     $styleHelper->success('Configuration file saved successfully.');
     return self::COMMAND_SUCCESS;
 }
Esempio n. 3
0
 /**
  * @param ConsoleCommandEvent $event
  * @param string              $org
  * @param string              $repo
  * @param string              $adapterName
  */
 private function initializeIssueTracker(ConsoleCommandEvent $event, $org, $repo, $adapterName)
 {
     $input = $event->getInput();
     $issueOrg = GitHelper::undefinedToDefault($input->getOption('issue-org'), $org);
     $issueRepo = GitHelper::undefinedToDefault($input->getOption('issue-project'), $repo);
     $issueAdapterName = $input->getOption('issue-adapter') ?: $adapterName;
     $input->setOption('issue-org', $issueOrg);
     $input->setOption('issue-project', $issueRepo);
     $input->setOption('issue-adapter', $issueAdapterName);
     $config = $this->application->getConfig()->get(['adapters', $issueAdapterName], Config::CONFIG_SYSTEM);
     /** @var \Gush\Adapter\BaseIssueTracker $issueTracker */
     $issueTracker = $this->application->getAdapterFactory()->createIssueTracker($issueAdapterName, $config, $this->application->getConfig());
     $issueTracker->authenticate();
     $issueTracker->setRepository($issueRepo)->setUsername($issueOrg);
     $this->application->setIssueTracker($issueTracker);
 }