*/ class UserCreateCommand extends Command { /** * {@inheritdoc} */ protected function configure() { $this ->setName('user:create') ->setDescription('Create a user') ->setHelp(''); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $helper = $this->getHelper('question'); $userProvider = $this->getSilexApplication()['user.provider']; $username = ''; $password = ''; while (trim($username) === '') { $question = new Question('Username: ', ''); $username = $helper->ask($input, $output, $question); if ($userProvider->userExists($username)) { $output->writeln('This username is already used.'); $username = ''; } } while (trim($password) === '') { $question = new Question('Password: ', ''); $password = $helper->ask($input, $output, $question); } $user = $userProvider->createUser(); $user->setUsername($username); $userProvider->registerUser($user, $password); } }