29f4d8fe7b33751272b6dd1d16ca52925a399ae6
[yaffs-website] / web / modules / contrib / devel / webprofiler / src / Command / ListCommand.php
1 <?php
2
3 namespace Drupal\webprofiler\Command;
4
5 use Symfony\Component\Console\Command\Command;
6 use Symfony\Component\Console\Helper\Table;
7 use Symfony\Component\Console\Input\InputInterface;
8 use Symfony\Component\Console\Input\InputOption;
9 use Symfony\Component\Console\Output\OutputInterface;
10 use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
11 use Drupal\Console\Annotations\DrupalCommand;
12
13 /**
14  * Class ListCommand
15  **
16  * @DrupalCommand (
17  *     extension="webprofiler",
18  *     extensionType="module"
19  * )
20  */
21 class ListCommand extends Command {
22
23   use ContainerAwareCommandTrait;
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function configure() {
29     $this
30       ->setName('webprofiler:list')
31       ->setDescription($this->trans('commands.webprofiler.list.description'))
32       ->addOption('ip', NULL, InputOption::VALUE_REQUIRED, $this->trans('commands.webprofiler.list.options.ip'), NULL)
33       ->addOption('url', NULL, InputOption::VALUE_REQUIRED, $this->trans('commands.webprofiler.list.options.url'), NULL)
34       ->addOption('method', NULL, InputOption::VALUE_REQUIRED, $this->trans('commands.webprofiler.list.options.method'), NULL)
35       ->addOption('limit', NULL, InputOption::VALUE_REQUIRED, $this->trans('commands.webprofiler.list.options.limit'), 10);
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   protected function execute(InputInterface $input, OutputInterface $output) {
42     $ip = $input->getOption('ip');
43     $url = $input->getOption('url');
44     $method = $input->getOption('method');
45     $limit = $input->getOption('limit');
46
47     /** @var \Drupal\webprofiler\Profiler\Profiler $profiler */
48     $profiler = $this->container->get('profiler');
49     $profiles = $profiler->find($ip, $url, $limit, $method, '', '');
50
51     $rows = [];
52     foreach ($profiles as $profile) {
53       $row = [];
54
55       $row[] = $profile['token'];
56       $row[] = $profile['ip'];
57       $row[] = $profile['method'];
58       $row[] = $profile['url'];
59       $row[] = date($this->trans('commands.webprofiler.list.rows.time'), $profile['time']);
60
61       $rows[] = $row;
62     }
63
64     $table = new Table($output);
65     $table
66       ->setHeaders([
67         $this->trans('commands.webprofiler.list.header.token'),
68         $this->trans('commands.webprofiler.list.header.ip'),
69         $this->trans('commands.webprofiler.list.header.method'),
70         $this->trans('commands.webprofiler.list.header.url'),
71         $this->trans('commands.webprofiler.list.header.time'),
72       ])
73       ->setRows($rows);
74     $table->render();
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function showMessage($output, $message, $type = 'info') {
81   }
82 }