View source
<?php
namespace Drupal\webprofiler\Command;
use Drupal\Console\Annotations\DrupalCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
class ListCommand extends Command {
use ContainerAwareCommandTrait;
protected function configure() {
$this
->setName('webprofiler:list')
->setDescription($this
->trans('commands.webprofiler.list.description'))
->addOption('ip', NULL, InputOption::VALUE_REQUIRED, $this
->trans('commands.webprofiler.list.options.ip'), NULL)
->addOption('url', NULL, InputOption::VALUE_REQUIRED, $this
->trans('commands.webprofiler.list.options.url'), NULL)
->addOption('method', NULL, InputOption::VALUE_REQUIRED, $this
->trans('commands.webprofiler.list.options.method'), NULL)
->addOption('limit', NULL, InputOption::VALUE_REQUIRED, $this
->trans('commands.webprofiler.list.options.limit'), 10);
}
protected function execute(InputInterface $input, OutputInterface $output) {
$ip = $input
->getOption('ip');
$url = $input
->getOption('url');
$method = $input
->getOption('method');
$limit = $input
->getOption('limit');
$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();
}
public function showMessage($output, $message, $type = 'info') {
}
}