private function configureAdapter(InputInterface $input, OutputInterface $output, $adapterName, array $adapter)
{
/** @var \Gush\Application $application */
$application = $this->getApplication();
$isAuthenticated = false;
$authenticationAttempts = 0;
$config = [];
$styleHelper = $this->getHelper('gush_style');
$configurator = $application->getAdapterFactory()->createConfigurator($adapterName, $application->getHelperSet(), $application->getConfig());
while (!$isAuthenticated) {
// Prevent endless loop with a broken test
if ($authenticationAttempts > 50) {
throw new \RuntimeException('Too many attempts, aborting.');
}
if ($authenticationAttempts > 0) {
$styleHelper->error('Authentication failed please try again.');
}
try {
$config = $configurator->interact($input, $output);
$isAuthenticated = $this->isCredentialsValid($adapterName, $adapter, $config);
} catch (\Exception $e) {
$styleHelper->error($e->getMessage());
}
++$authenticationAttempts;
}
if ($isAuthenticated) {
$rawConfig = $this->getConfig()->toArray(Config::CONFIG_SYSTEM);
$rawConfig['adapters'][$adapterName] = $config;
$styleHelper->success(sprintf('The "%s" adapter was successfully authenticated.', $adapter['label']));
$this->getConfig()->merge($rawConfig, Config::CONFIG_SYSTEM);
}
}