domainManager = $domainManager; parent::__construct(); } /** * @inheritdoc */ protected function configure() { $description = 'Add domains to the downloadable domains whitelist'; $this->setName('downloadable:domains:add') ->setDescription($description) ->setDefinition( [ new InputArgument( self::INPUT_KEY_DOMAINS, InputArgument::IS_ARRAY, 'Domains name' ) ] ); parent::configure(); } /** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { try { if ($input->getArgument(self::INPUT_KEY_DOMAINS)) { $whitelistBefore = $this->domainManager->getDomains(); $newDomains = $input->getArgument(self::INPUT_KEY_DOMAINS); $newDomains = array_filter(array_map('trim', $newDomains), 'strlen'); $this->domainManager->addDomains($newDomains); foreach (array_diff($this->domainManager->getDomains(), $whitelistBefore) as $newHost) { $output->writeln( $newHost . ' was added to the whitelist.' . PHP_EOL ); } } } catch (Exception $e) { $output->writeln('' . $e->getMessage() . ''); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln($e->getTraceAsString()); } return Cli::RETURN_FAILURE; } return Cli::RETURN_SUCCESS; } }