userService = $userService; } /** * {@inheritdoc} */ protected function configure() { $this ->setDefinition([ new InputArgument('username', InputArgument::REQUIRED, 'The username'), new InputArgument('role', InputArgument::OPTIONAL, 'The role'), new InputOption('super', null, InputOption::VALUE_NONE, 'Instead specifying role, use this to quickly add the super administrator role'), ]); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); $role = $input->getArgument('role'); $super = (true === $input->getOption('super')); if (null !== $role && $super) { throw new \InvalidArgumentException('You can pass either the role or the --super option (but not both simultaneously).'); } if (null === $role && !$super) { throw new \RuntimeException('Not enough arguments, pass a role or use --super.'); } $user = $this->userService->findUserByUsernameOrThrowException($username); $this->executeRoleCommand($this->userService, new SymfonyStyle($input, $output), $user, $super, $role); return 0; } abstract protected function executeRoleCommand(UserService $manipulator, SymfonyStyle $output, User $user, bool $super, $role); }