Skip to content

Commit d582277

Browse files
author
Oleksii Korshenko
committed
MAGETWO-81841: Added CLI command to enable and disable the Profiler #11407
- fixed code style issues
1 parent 220bc1d commit d582277

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

app/bootstrap.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@
5454
&& isset($_SERVER['HTTP_ACCEPT'])
5555
&& strpos($_SERVER['HTTP_ACCEPT'], 'text/html') !== false
5656
) {
57+
$profilerFlag = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
58+
? $_SERVER['MAGE_PROFILER']
59+
: trim(file_get_contents(BP . '/var/profiler.flag'));
60+
5761
\Magento\Framework\Profiler::applyConfig(
58-
(isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])) ? $_SERVER['MAGE_PROFILER'] : trim(file_get_contents(BP . '/var/profiler.flag')),
62+
$profilerFlag,
5963
BP,
6064
!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
6165
);

app/code/Magento/Developer/Console/Command/ProfilerDisableCommand.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313

14+
/**
15+
* CLI Command to disable Magento profiler.
16+
*/
1417
class ProfilerDisableCommand extends Command
1518
{
1619
/**
@@ -37,11 +40,12 @@ class ProfilerDisableCommand extends Command
3740
* Initialize dependencies.
3841
*
3942
* @param File $filesystem
43+
* @param string|null $name The name of the command; passing null means it must be set in configure()
4044
* @internal param ConfigInterface $resourceConfig
4145
*/
42-
public function __construct(File $filesystem)
46+
public function __construct(File $filesystem, $name = null)
4347
{
44-
parent::__construct();
48+
parent::__construct($name ?: self::COMMAND_NAME);
4549
$this->filesystem = $filesystem;
4650
}
4751

@@ -50,9 +54,7 @@ public function __construct(File $filesystem)
5054
*/
5155
protected function configure()
5256
{
53-
$this->setName(self::COMMAND_NAME)
54-
->setDescription('Disable the profiler.');
55-
57+
$this->setDescription('Disable the profiler.');
5658
parent::configure();
5759
}
5860

app/code/Magento/Developer/Console/Command/ProfilerEnableCommand.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Symfony\Component\Console\Input\InputArgument;
1414

15+
/**
16+
* CLI Command to enable Magento profiler.
17+
*/
1518
class ProfilerEnableCommand extends Command
1619
{
1720
/**
@@ -48,11 +51,12 @@ class ProfilerEnableCommand extends Command
4851
* Initialize dependencies.
4952
*
5053
* @param File $filesystem
54+
* @param string|null $name The name of the command; passing null means it must be set in configure()
5155
* @internal param ConfigInterface $resourceConfig
5256
*/
53-
public function __construct(File $filesystem)
57+
public function __construct(File $filesystem, $name = null)
5458
{
55-
parent::__construct();
59+
parent::__construct($name ?: self::COMMAND_NAME);
5660
$this->filesystem = $filesystem;
5761
}
5862

@@ -61,9 +65,8 @@ public function __construct(File $filesystem)
6165
*/
6266
protected function configure()
6367
{
64-
$this->setName(self::COMMAND_NAME)
65-
->setDescription('Enable the profiler.')
66-
->addArgument('type', InputArgument::OPTIONAL, 'Profiler type');
68+
$this->setDescription('Enable the profiler.')
69+
->addArgument('type', InputArgument::OPTIONAL, 'Profiler type', self::TYPE_DEFAULT);
6770

6871
parent::configure();
6972
}
@@ -75,10 +78,6 @@ protected function configure()
7578
protected function execute(InputInterface $input, OutputInterface $output)
7679
{
7780
$type = $input->getArgument('type');
78-
if (!$type) {
79-
$type = self::TYPE_DEFAULT;
80-
}
81-
8281
if (!in_array($type, self::BUILT_IN_TYPES)) {
8382
$builtInTypes = implode(', ', self::BUILT_IN_TYPES);
8483
$output->writeln(

0 commit comments

Comments
 (0)