ProfilerDisableCommand.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Developer\Console\Command;
  7. use Magento\Framework\Filesystem\Io\File;
  8. use Symfony\Component\Console\Command\Command;
  9. use Symfony\Component\Console\Input\InputInterface;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. class ProfilerDisableCommand extends Command
  12. {
  13. /**
  14. * Profiler flag file
  15. */
  16. const PROFILER_FLAG_FILE = 'var/profiler.flag';
  17. /**
  18. * Command name
  19. */
  20. const COMMAND_NAME = 'dev:profiler:disable';
  21. /**
  22. * Success message
  23. */
  24. const SUCCESS_MESSAGE = 'Profiler disabled.';
  25. /**
  26. * @var File
  27. */
  28. private $filesystem;
  29. /**
  30. * Initialize dependencies.
  31. *
  32. * @param File $filesystem
  33. * @internal param ConfigInterface $resourceConfig
  34. */
  35. public function __construct(File $filesystem)
  36. {
  37. parent::__construct();
  38. $this->filesystem = $filesystem;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function configure()
  44. {
  45. $this->setName(self::COMMAND_NAME)
  46. ->setDescription('Disable the profiler.');
  47. parent::configure();
  48. }
  49. /**
  50. * {@inheritdoc}
  51. * @throws \InvalidArgumentException
  52. */
  53. protected function execute(InputInterface $input, OutputInterface $output)
  54. {
  55. $this->filesystem->rm(BP . '/' . self::PROFILER_FLAG_FILE);
  56. if (!$this->filesystem->fileExists(BP . '/' . self::PROFILER_FLAG_FILE)) {
  57. $output->writeln('<info>'. self::SUCCESS_MESSAGE . '</info>');
  58. return;
  59. }
  60. $output->writeln('<error>Something went wrong while disabling the profiler.</error>');
  61. }
  62. }