1 | <?php |
||
16 | class ConsoleCommand extends \Symfony\Component\Console\Command\Command { |
||
17 | |||
18 | /** |
||
19 | * @var null|InputInterface |
||
20 | */ |
||
21 | private $input = null; |
||
22 | |||
23 | /** |
||
24 | * @var null|OutputInterface |
||
25 | */ |
||
26 | private $output = null; |
||
27 | |||
28 | |||
29 | /** |
||
30 | * @inheritdoc |
||
31 | */ |
||
32 | 3 | protected function configure() { |
|
37 | |||
38 | |||
39 | /** |
||
40 | * Return progress panel according to application options |
||
41 | * |
||
42 | * @param int $max |
||
43 | * @return InlineProgressPanel|ProgressPanel |
||
44 | * @throws \Exception |
||
45 | */ |
||
46 | protected function getProgressPanel($max = 0) { |
||
47 | if (empty($this->getOutput())) { |
||
48 | throw new \Exception('Cant initialize progress panel. Output is undefined'); |
||
49 | } |
||
50 | |||
51 | $input = $this->getInput(); |
||
52 | |||
53 | if ($input and $input->hasOption('run-from-cron') and $input->getOption('run-from-cron')) { |
||
54 | return new InlineProgressPanel($this->getOutput(), $max); |
||
55 | } |
||
56 | |||
57 | return new ProgressPanel($this->getOutput(), $max); |
||
58 | } |
||
59 | |||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | protected function initialize(InputInterface $input, OutputInterface $output) { |
||
65 | $this->input = $input; |
||
66 | $this->output = $output; |
||
67 | |||
68 | parent::initialize($input, $output); |
||
69 | |||
70 | |||
71 | if ($input->getOption('run-from-cron')) { |
||
72 | $message = '[run-from-cron] [' . (new \DateTime())->format('Y-m-d H:i:s') . ']'; |
||
73 | |||
74 | if ($input instanceof ArgvInput or $input instanceof ArrayInput) { |
||
75 | $message = $message . ' ' . $input; |
||
76 | } else { |
||
77 | $message = $message . ' ' . $this->getName(); |
||
78 | } |
||
79 | |||
80 | $output->writeln($message); |
||
81 | } |
||
82 | |||
83 | } |
||
84 | |||
85 | |||
86 | /** |
||
87 | * We use execute method for command logic. |
||
88 | * |
||
89 | * @see ConsoleCommand::execute |
||
90 | * @deprecated |
||
91 | * |
||
92 | * @param callable $code |
||
93 | * @return \Symfony\Component\Console\Command\Command|void |
||
94 | * @throws \Exception |
||
95 | */ |
||
96 | 1 | public function setCode(callable $code) { |
|
99 | |||
100 | |||
101 | /** |
||
102 | * @return null|OutputInterface |
||
103 | */ |
||
104 | public function getOutput() { |
||
105 | return $this->output; |
||
106 | } |
||
107 | |||
108 | |||
109 | /** |
||
110 | * @return null|InputInterface |
||
111 | */ |
||
112 | public function getInput() { |
||
113 | return $this->input; |
||
114 | } |
||
115 | |||
116 | |||
117 | /** |
||
118 | * Run command only with single instance |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | 1 | public function isSingleInstance() { |
|
125 | |||
126 | } |