netz98 /
n98-magerun2
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace N98\Magento\Command\Developer; |
||
| 4 | |||
| 5 | use Exception; |
||
| 6 | use Magento\Framework\App\ProductMetadataInterface; |
||
| 7 | use N98\Magento\Command\AbstractMagentoCommand; |
||
| 8 | use N98\Util\Unicode\Charset; |
||
| 9 | use PhpParser\Lexer; |
||
| 10 | use PhpParser\Parser; |
||
| 11 | use Psy\CodeCleaner; |
||
| 12 | use Psy\Command\ListCommand; |
||
| 13 | use Psy\Configuration; |
||
| 14 | use Psy\Output\ShellOutput; |
||
| 15 | use Psy\Shell; |
||
| 16 | use Symfony\Component\Console\Input\InputInterface; |
||
| 17 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 18 | use Psy\ParserFactory; |
||
| 19 | |||
| 20 | class ConsoleCommand extends AbstractMagentoCommand |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var ProductMetadataInterface |
||
| 24 | */ |
||
| 25 | private $productMeta; |
||
| 26 | |||
| 27 | protected function configure() |
||
| 28 | { |
||
| 29 | $this |
||
| 30 | ->setName('dev:console') |
||
| 31 | ->setDescription('Opens PHP interactive shell with initialized Mage::app() <comment>(Experimental)</comment>') |
||
|
0 ignored issues
–
show
|
|||
| 32 | ; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param ProductMetadataInterface $productMetadata |
||
| 37 | */ |
||
| 38 | public function inject(ProductMetadataInterface $productMetadata) |
||
| 39 | { |
||
| 40 | $this->productMeta = $productMetadata; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param InputInterface $input |
||
| 45 | * @param OutputInterface $output |
||
| 46 | * |
||
| 47 | * @return int|void |
||
| 48 | */ |
||
| 49 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 50 | { |
||
| 51 | $initialized = false; |
||
| 52 | try { |
||
| 53 | $this->detectMagento($output); |
||
| 54 | $initialized = $this->initMagento(); |
||
| 55 | } catch (Exception $e) { |
||
| 56 | // do nothing |
||
| 57 | } |
||
| 58 | |||
| 59 | $parser = new Parser(new Lexer()); |
||
| 60 | $cleaner = new CodeCleaner($parser); |
||
| 61 | $consoleOutput = new ShellOutput(); |
||
| 62 | $config = new Configuration(); |
||
| 63 | $config->setCodeCleaner($cleaner); |
||
| 64 | $shell = new Shell($config); |
||
| 65 | $shell->setScopeVariables([ |
||
| 66 | 'di' => $this->getObjectManager(), |
||
| 67 | ]); |
||
| 68 | |||
| 69 | if ($initialized) { |
||
| 70 | $ok = Charset::convertInteger(Charset::UNICODE_CHECKMARK_CHAR); |
||
| 71 | |||
| 72 | $edition = $this->productMeta->getEdition(); |
||
| 73 | $magentoVersion = $this->productMeta->getVersion(); |
||
| 74 | |||
| 75 | $consoleOutput->writeln('<fg=black;bg=green>Magento ' . $magentoVersion . ' ' . $edition . ' initialized.</fg=black;bg=green> ' . $ok); |
||
|
0 ignored issues
–
show
|
|||
| 76 | } else { |
||
| 77 | $consoleOutput->writeln('<fg=black;bg=yellow>Magento is not initialized.</fg=black;bg=yellow>'); |
||
| 78 | } |
||
| 79 | |||
| 80 | $help = <<<'help' |
||
| 81 | At the prompt, type <comment>help</comment> for some help. |
||
| 82 | |||
| 83 | To exit the shell, type <comment>^D</comment>. |
||
| 84 | help; |
||
| 85 | |||
| 86 | $consoleOutput->writeln($help); |
||
| 87 | |||
| 88 | $shell->run($input, $consoleOutput); |
||
| 89 | } |
||
| 90 | } |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.