function ListCommand::execute

File

webprofiler/src/Command/ListCommand.php, line 41

Class

ListCommand
Class ListCommand * @DrupalCommand ( extension="webprofiler", extensionType="module" )

Namespace

Drupal\webprofiler\Command

Code

protected function execute(InputInterface $input, OutputInterface $output) {
    $ip = $input->getOption('ip');
    $url = $input->getOption('url');
    $method = $input->getOption('method');
    $limit = $input->getOption('limit');
    
    /** @var \Drupal\webprofiler\Profiler\Profiler $profiler */
    $profiler = $this->container
        ->get('profiler');
    $profiles = $profiler->find($ip, $url, $limit, $method, '', '');
    $rows = [];
    foreach ($profiles as $profile) {
        $row = [];
        $row[] = $profile['token'];
        $row[] = $profile['ip'];
        $row[] = $profile['method'];
        $row[] = $profile['url'];
        $row[] = date($this->trans('commands.webprofiler.list.rows.time'), $profile['time']);
        $rows[] = $row;
    }
    $table = new Table($output);
    $table->setHeaders([
        $this->trans('commands.webprofiler.list.header.token'),
        $this->trans('commands.webprofiler.list.header.ip'),
        $this->trans('commands.webprofiler.list.header.method'),
        $this->trans('commands.webprofiler.list.header.url'),
        $this->trans('commands.webprofiler.list.header.time'),
    ])
        ->setRows($rows);
    $table->render();
}