StaticClassesGenerator.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Mtf\Troubleshooting;
  7. use Magento\Mtf\Console\Output;
  8. use Magento\Mtf\ObjectManagerInterface;
  9. use Symfony\Component\Console\Input\InputInterface;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. /**
  12. * Generates static classes (Blocks, Pages, Repositories etc.).
  13. */
  14. class StaticClassesGenerator extends \Symfony\Component\Console\Command\Command
  15. {
  16. /**
  17. * Object manager instance.
  18. *
  19. * @var ObjectManagerInterface
  20. */
  21. private $objectManager;
  22. /**
  23. * @param ObjectManagerInterface $objectManager
  24. */
  25. public function __construct(ObjectManagerInterface $objectManager)
  26. {
  27. parent::__construct();
  28. $this->objectManager = $objectManager;
  29. }
  30. /**
  31. * Configure command.
  32. *
  33. * @return void
  34. */
  35. protected function configure()
  36. {
  37. parent::configure();
  38. $this->setName('troubleshooting:generate-static-classes')
  39. ->setDescription('Generate static classes (Blocks, Pages, Repositories etc.).');
  40. }
  41. /**
  42. * Execute command.
  43. *
  44. * @param InputInterface $input
  45. * @param OutputInterface $output
  46. * @return void
  47. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  48. */
  49. protected function execute(InputInterface $input, OutputInterface $output)
  50. {
  51. $output = $this->objectManager->create(
  52. Output::class,
  53. ['output' => $output]
  54. );
  55. $output->writeln("Generating static classes...");
  56. exec('php ' . MTF_BP . DIRECTORY_SEPARATOR . 'utils' . DIRECTORY_SEPARATOR . 'generate.php', $error, $exitCode);
  57. if ($exitCode) {
  58. $output->outputMessages(['error' => $error]);
  59. }
  60. $output->writeln('Static classes generation is finished.');
  61. }
  62. }