searchService = $searchService; $this->configService = $configService; } protected function configure() { parent::configure(); $this->setName('circles:members:search') ->setDescription('Change the level of a member from a Team') ->addArgument('term', InputArgument::REQUIRED, 'term to search') ->addOption('initiator', '', InputOption::VALUE_REQUIRED, 'set an initiator to the request', '') ->addOption('status-code', '', InputOption::VALUE_NONE, 'display status code on exception'); } /** * @param InputInterface $input * @param OutputInterface $output * * @return int */ protected function execute(InputInterface $input, OutputInterface $output): int { $result = $this->searchService->search($input->getArgument('needle')); if (strtolower($input->getOption('output')) === 'json') { $output->writeln(json_encode($result, JSON_PRETTY_PRINT)); } $this->displaySearchResult($result); return 0; } /** * @param list $result */ private function displaySearchResult(array $result) { $output = new ConsoleOutput(); $output = $output->section(); $table = new Table($output); $table->setHeaders(['SingleId', 'UserId', 'UserType', 'Instance']); $rows = []; foreach ($result as $entry) { if (!$result instanceof IFederatedUser) { continue; } $rows[] = [ $entry->getSingleId(), $entry->getUserId(), Member::$TYPE[$entry->getUserType()], $this->configService->displayInstance($entry->getInstance()) ]; } $table->setRows($rows); $table->render(); } }