1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Developer\Console; |
4
|
|
|
|
5
|
|
|
use Magento\Framework\App\ObjectManager; |
6
|
|
|
use Psy\Command\ReflectingCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
abstract class AbstractConsoleCommand extends ReflectingCommand |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param string $variable |
15
|
|
|
* @param mixed $value |
16
|
|
|
* |
17
|
|
|
* @return void |
18
|
|
|
*/ |
19
|
|
|
public function setScopeVariable($variable, $value) |
20
|
|
|
{ |
21
|
|
|
$variables = $this->context->getAll(); |
22
|
|
|
$variables[$variable] = $value; |
23
|
|
|
|
24
|
|
|
$this->context->setAll($variables); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $type |
29
|
|
|
* @return mixed |
30
|
|
|
*/ |
31
|
|
|
public function get($type) |
32
|
|
|
{ |
33
|
|
|
$di = $this->getScopeVariable('di'); |
34
|
|
|
|
35
|
|
|
/** @var $di ObjectManager */ |
36
|
|
|
return $di->get($type); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $type |
41
|
|
|
* @param array $arguments |
42
|
|
|
* @return mixed |
43
|
|
|
*/ |
44
|
|
|
public function create($type, $arguments = []) |
45
|
|
|
{ |
46
|
|
|
$di = $this->getScopeVariable('di'); |
47
|
|
|
|
48
|
|
|
/** @var $di ObjectManager */ |
49
|
|
|
return $di->create($type, $arguments); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Call n98-magerun command |
54
|
|
|
* |
55
|
|
|
* @param string $commandName |
56
|
|
|
* @param InputInterface $input |
57
|
|
|
* @param OutputInterface $output |
58
|
|
|
* @return int |
59
|
|
|
*/ |
60
|
|
|
public function callMagerunCommand($commandName, InputInterface $input, OutputInterface $output) |
61
|
|
|
{ |
62
|
|
|
$command = $this->getScopeVariable('magerun')->find($commandName); |
63
|
|
|
|
64
|
|
|
return $command->run($input, $output); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Call psy console command |
69
|
|
|
* |
70
|
|
|
* @param InputInterface $input |
71
|
|
|
* @param OutputInterface $output |
72
|
|
|
* @return int |
73
|
|
|
*/ |
74
|
|
|
public function callCommand(InputInterface $input, OutputInterface $output) |
75
|
|
|
{ |
76
|
|
|
if ($input->hasArgument('command')) { |
77
|
|
|
$commandName = $input->getArgument('command'); |
78
|
|
|
} else { |
79
|
|
|
$commandName = $input->getFirstArgument(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$command = $this->getApplication()->find($commandName); |
83
|
|
|
|
84
|
|
|
return $command->run($input, $output); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|