|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Developer\Console; |
|
4
|
|
|
|
|
5
|
|
|
use N98\Magento\Command\Developer\Console\Exception\NoModuleDefinedException; |
|
6
|
|
|
use N98\Util\BinaryString; |
|
7
|
|
|
use Psy\Configuration; |
|
8
|
|
|
use Psy\Exception\ErrorException; |
|
9
|
|
|
use Psy\Exception\FatalErrorException; |
|
10
|
|
|
use Psy\Exception\ParseErrorException; |
|
11
|
|
|
use Psy\Shell as PsyShell; |
|
12
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatter; |
|
13
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
|
14
|
|
|
use Symfony\Component\Console\Helper\HelperInterface; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
16
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
|
|
19
|
|
|
class Shell extends PsyShell |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $prompt = ''; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ConsoleOutput |
|
28
|
|
|
*/ |
|
29
|
|
|
private $consoleOutput; |
|
30
|
|
|
|
|
31
|
|
|
public function run(InputInterface $input = null, OutputInterface $output = null) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->registerHelpersFromMainApplication(); |
|
34
|
|
|
|
|
35
|
|
|
return parent::run($input, $output); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
private function registerHelpersFromMainApplication() |
|
39
|
|
|
{ |
|
40
|
|
|
$helperSetMagerun = $this->getScopeVariable('magerun')->getHelperSet(); |
|
41
|
|
|
$helperSetPsy = $this->getHelperSet(); |
|
42
|
|
|
|
|
43
|
|
|
foreach ($helperSetMagerun as $helper) { |
|
44
|
|
|
/** @var $helper HelperInterface */ |
|
45
|
|
|
if (!$helperSetPsy->has($helper->getName())) { |
|
46
|
|
|
$helperSetPsy->set($helper); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Renders a caught Exception. |
|
54
|
|
|
* |
|
55
|
|
|
* Exceptions are formatted according to severity. ErrorExceptions which were |
|
56
|
|
|
* warnings or Strict errors aren't rendered as harshly as real errors. |
|
57
|
|
|
* |
|
58
|
|
|
* Stores $e as the last Exception in the Shell Context. |
|
59
|
|
|
* |
|
60
|
|
|
* @param \Exception $e An exception instance |
|
61
|
|
|
* @param OutputInterface $output An OutputInterface instance |
|
|
|
|
|
|
62
|
|
|
*/ |
|
63
|
|
|
public function writeException(\Exception $e) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->resetCodeBuffer(); |
|
66
|
|
|
|
|
67
|
|
|
if ($e instanceof NoModuleDefinedException) { |
|
|
|
|
|
|
68
|
|
|
$this->getConsoleOutput()->writeln('<warning>' . $e->getMessage() . '</warning>'); |
|
69
|
|
|
return; |
|
70
|
|
|
} elseif ($e instanceof ErrorException) { |
|
71
|
|
|
if (BinaryString::startsWith($e->getMessage(), 'PHP error: Use of undefined constant')) { |
|
72
|
|
|
$this->getConsoleOutput()->writeln('<warning>Unknown command</warning>'); |
|
73
|
|
|
return; |
|
74
|
|
|
} |
|
75
|
|
|
} elseif ($e instanceof FatalErrorException) { |
|
76
|
|
|
if (BinaryString::startsWith($e->getMessage(), 'PHP Fatal error: Call to undefined function')) { |
|
77
|
|
|
$this->getConsoleOutput()->writeln('<warning>Unknown function</warning>'); |
|
78
|
|
|
return; |
|
79
|
|
|
} |
|
80
|
|
|
} elseif ($e instanceof ParseErrorException) { |
|
81
|
|
|
$message = substr($e->getMessage(), 0, strpos($e->getMessage(), ' on line')); |
|
82
|
|
|
$this->getConsoleOutput()->writeln('<error>' . $message . '</error>'); |
|
83
|
|
|
return; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
throw $e; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getPrompt() |
|
94
|
|
|
{ |
|
95
|
|
|
if (!empty($this->prompt)) { |
|
96
|
|
|
return $this->prompt; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return parent::getPrompt(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param string $prompt |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setPrompt($prompt) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->prompt = $prompt; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Resets prompt to default |
|
112
|
|
|
*/ |
|
113
|
|
|
public function resetPrompt() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->prompt = ''; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return ConsoleOutput |
|
120
|
|
|
*/ |
|
121
|
|
|
private function getConsoleOutput() |
|
122
|
|
|
{ |
|
123
|
|
|
if (empty($this->consoleOutput)) { |
|
124
|
|
|
$formatter = new OutputFormatter(); |
|
125
|
|
|
$formatter->setStyle('warning', new OutputFormatterStyle('black', 'yellow')); |
|
126
|
|
|
$this->consoleOutput = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, null, $formatter); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
return $this->consoleOutput; |
|
130
|
|
|
} |
|
131
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.