Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProfilerEnableCommand.php
Go to the documentation of this file.
1 <?php
8 
10 use Symfony\Component\Console\Command\Command;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Input\InputArgument;
14 
15 class ProfilerEnableCommand extends Command
16 {
20  const PROFILER_FLAG_FILE = 'var/profiler.flag';
21 
25  const TYPE_DEFAULT = 'html';
26 
30  const BUILT_IN_TYPES = ['html', 'csvfile'];
31 
35  const COMMAND_NAME = 'dev:profiler:enable';
36 
40  const SUCCESS_MESSAGE = 'Profiler enabled with %s output.';
41 
45  private $filesystem;
46 
53  public function __construct(File $filesystem)
54  {
55  parent::__construct();
56  $this->filesystem = $filesystem;
57  }
58 
62  protected function configure()
63  {
64  $this->setName(self::COMMAND_NAME)
65  ->setDescription('Enable the profiler.')
66  ->addArgument('type', InputArgument::OPTIONAL, 'Profiler type');
67 
68  parent::configure();
69  }
70 
75  protected function execute(InputInterface $input, OutputInterface $output)
76  {
77  $type = $input->getArgument('type');
78  if (!$type) {
80  }
81 
82  if (!in_array($type, self::BUILT_IN_TYPES, true)) {
83  $builtInTypes = implode(', ', self::BUILT_IN_TYPES);
84  $output->writeln(
85  '<comment>'
86  . sprintf('Type %s is not one of the built-in output types (%s).', $type, $builtInTypes) .
87  '</comment>'
88  );
89  }
90 
91  $this->filesystem->write(BP . '/' . self::PROFILER_FLAG_FILE, $type);
92  if ($this->filesystem->fileExists(BP . '/' . self::PROFILER_FLAG_FILE)) {
93  $output->write('<info>'. sprintf(self::SUCCESS_MESSAGE, $type) . '</info>');
94  if ($type == 'csvfile') {
95  $output->write(
96  '<info> ' . sprintf(
97  'Output will be saved in %s',
98  \Magento\Framework\Profiler\Driver\Standard\Output\Csvfile::DEFAULT_FILEPATH
99  )
100  . '</info>'
101  );
102  }
103  $output->write(PHP_EOL);
104 
105  return;
106  }
107  $output->writeln('<error>Something went wrong while enabling the profiler.</error>');
108  }
109 }
execute(InputInterface $input, OutputInterface $output)
$type
Definition: item.phtml:13
const BP
Definition: autoload.php:14
$filesystem