Gush\Command\Core\CoreConfigureCommand::configureAdapter PHP Method

configureAdapter() private method

private configureAdapter ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output, $adapterName, array $adapter )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
$adapter array
    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);
        }
    }