apiKeyService = $apiKeyService; $this->translator = $translator; parent::__construct(null); } public function configure() { $this->setName('api-key:generate') ->setDescription($this->translator->translate('Generates a new valid API key.')) ->addOption( 'expirationDate', 'e', InputOption::VALUE_OPTIONAL, $this->translator->translate('The date in which the API key should expire. Use any valid PHP format.') ); } public function execute(InputInterface $input, OutputInterface $output) { $expirationDate = $input->getOption('expirationDate'); $apiKey = $this->apiKeyService->create(isset($expirationDate) ? new \DateTime($expirationDate) : null); $output->writeln($this->translator->translate('Generated API key') . sprintf(': %s', $apiKey)); } }