ShowModeCommand.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Console\Command;
  7. use Magento\Framework\ObjectManagerInterface;
  8. use Magento\Framework\App\State;
  9. use Symfony\Component\Console\Command\Command;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. /**
  13. * Command to show application mode
  14. */
  15. class ShowModeCommand extends Command
  16. {
  17. /**
  18. * Object manager factory
  19. *
  20. * @var ObjectManagerInterface
  21. */
  22. private $objectManager;
  23. /**
  24. * Inject dependencies
  25. *
  26. * @param ObjectManagerInterface $objectManager
  27. */
  28. public function __construct(ObjectManagerInterface $objectManager)
  29. {
  30. $this->objectManager = $objectManager;
  31. parent::__construct();
  32. }
  33. /**
  34. * @inheritdoc
  35. */
  36. protected function configure()
  37. {
  38. $description = 'Displays current application mode.';
  39. $this->setName('deploy:mode:show')->setDescription($description);
  40. parent::configure();
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. protected function execute(InputInterface $input, OutputInterface $output)
  46. {
  47. try {
  48. /** @var \Magento\Deploy\Model\Mode $mode */
  49. $mode = $this->objectManager->create(
  50. \Magento\Deploy\Model\Mode::class,
  51. [
  52. 'input' => $input,
  53. 'output' => $output,
  54. ]
  55. );
  56. $currentMode = $mode->getMode() ?: State::MODE_DEFAULT;
  57. $output->writeln(
  58. "Current application mode: $currentMode. (Note: Environment variables may override this value.)"
  59. );
  60. } catch (\Exception $e) {
  61. $output->writeln('<error>' . $e->getMessage() . '</error>');
  62. if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
  63. $output->writeln($e->getTraceAsString());
  64. }
  65. return;
  66. }
  67. }
  68. }