1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Plugins\AbstractConsolePlugin |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 7 |
13
|
|
|
* |
14
|
|
|
* @author Marcus Döllerer <[email protected]> |
15
|
|
|
* @copyright 2020 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Plugins; |
22
|
|
|
|
23
|
|
|
use Symfony\Component\Console\Exception\LogicException; |
24
|
|
|
use Symfony\Component\Console\Helper\HelperInterface; |
25
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
26
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
27
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
28
|
|
|
use TechDivision\Import\ApplicationInterface; |
29
|
|
|
use TechDivision\Import\Cli\Application; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Abstract console plugin implementation containing access to console commands and helpers. |
33
|
|
|
* |
34
|
|
|
* @author Marcus Döllerer <[email protected]> |
35
|
|
|
* @copyright 2020 TechDivision GmbH <[email protected]> |
36
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
37
|
|
|
* @link https://github.com/techdivision/import |
38
|
|
|
* @link http://www.techdivision.com |
39
|
|
|
*/ |
40
|
|
|
abstract class AbstractConsolePlugin extends AbstractPlugin |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The M2IF console application instance. |
45
|
|
|
* |
46
|
|
|
* @var Application |
47
|
|
|
*/ |
48
|
|
|
protected $cliApplication; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* The console input instance. |
52
|
|
|
* |
53
|
|
|
* @var InputInterface |
54
|
|
|
*/ |
55
|
|
|
protected $input; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* The console output instance. |
59
|
|
|
* |
60
|
|
|
* @var OutputInterface |
61
|
|
|
*/ |
62
|
|
|
protected $output; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* The helper set. |
66
|
|
|
* |
67
|
|
|
* @var HelperSet |
68
|
|
|
*/ |
69
|
|
|
protected $helperSet; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* AbstractConsolePlugin constructor |
73
|
|
|
* |
74
|
|
|
* @param ApplicationInterface $application |
75
|
|
|
* |
76
|
|
|
* @throws \Exception |
77
|
|
|
*/ |
78
|
|
|
public function __construct(ApplicationInterface $application) |
79
|
|
|
{ |
80
|
|
|
|
81
|
|
|
// inject the cli application |
82
|
|
|
$cliApplication = $application->getContainer()->get('application'); |
83
|
|
|
if (!$cliApplication instanceof Application) { |
|
|
|
|
84
|
|
|
throw new \Exception('No console application configured, please check your configuration.'); |
85
|
|
|
} |
86
|
|
|
$this->setCliApplication($cliApplication); |
87
|
|
|
|
88
|
|
|
// set the console input |
89
|
|
|
$input = $application->getContainer()->get('input'); |
90
|
|
|
if (!$input instanceof InputInterface) { |
91
|
|
|
throw new \Exception('No console input configured, please check your configuration.'); |
92
|
|
|
} |
93
|
|
|
$this->setInput($input); |
94
|
|
|
|
95
|
|
|
// set the console output |
96
|
|
|
$output = $application->getContainer()->get('output'); |
97
|
|
|
if (!$output instanceof OutputInterface) { |
98
|
|
|
throw new \Exception('No console output configured, please check your configuration.'); |
99
|
|
|
} |
100
|
|
|
$this->setOutput($output); |
101
|
|
|
|
102
|
|
|
// inject the helper set |
103
|
|
|
$helperSet = $this->getCliApplication()->getHelperSet(); |
104
|
|
|
if (!$helperSet instanceof HelperSet) { |
105
|
|
|
throw new LogicException('No HelperSet is defined.'); |
106
|
|
|
} |
107
|
|
|
$this->setHelperSet($helperSet); |
108
|
|
|
|
109
|
|
|
parent::__construct($application); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Returns the import cli application instance. |
114
|
|
|
* |
115
|
|
|
* @return \TechDivision\Import\Cli\Application |
116
|
|
|
*/ |
117
|
|
|
public function getCliApplication() |
118
|
|
|
{ |
119
|
|
|
return $this->cliApplication; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param \TechDivision\Import\Cli\Application $cliApplication |
124
|
|
|
* |
125
|
|
|
* @return void |
126
|
|
|
*/ |
127
|
|
|
public function setCliApplication(Application $cliApplication) |
128
|
|
|
{ |
129
|
|
|
$this->cliApplication = $cliApplication; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Returns the console input instance. |
134
|
|
|
* |
135
|
|
|
* @return \Symfony\Component\Console\Input\InputInterface |
136
|
|
|
*/ |
137
|
|
|
public function getInput() |
138
|
|
|
{ |
139
|
|
|
return $this->input; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
144
|
|
|
* |
145
|
|
|
* @return void |
146
|
|
|
*/ |
147
|
|
|
public function setInput(InputInterface $input) |
148
|
|
|
{ |
149
|
|
|
$this->input = $input; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Returns the console output instance. |
154
|
|
|
* |
155
|
|
|
* @return \Symfony\Component\Console\Output\OutputInterface |
156
|
|
|
*/ |
157
|
|
|
public function getOutput() |
158
|
|
|
{ |
159
|
|
|
return $this->output; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
164
|
|
|
* |
165
|
|
|
* @return void |
166
|
|
|
*/ |
167
|
|
|
public function setOutput(OutputInterface $output) |
168
|
|
|
{ |
169
|
|
|
$this->output = $output; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Returns the helper set. |
174
|
|
|
* |
175
|
|
|
* @return \Symfony\Component\Console\Helper\HelperSet |
176
|
|
|
*/ |
177
|
|
|
public function getHelperSet() |
178
|
|
|
{ |
179
|
|
|
return $this->helperSet; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param HelperSet $helperSet |
184
|
|
|
* |
185
|
|
|
* @return void |
186
|
|
|
*/ |
187
|
|
|
public function setHelperSet(HelperSet $helperSet) |
188
|
|
|
{ |
189
|
|
|
$this->helperSet = $helperSet; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Retrieve a helper by name. |
194
|
|
|
* |
195
|
|
|
* @param string $name The name of the helper to retrieve |
196
|
|
|
* |
197
|
|
|
* @return HelperInterface |
198
|
|
|
*/ |
199
|
|
|
public function getHelper($name) |
200
|
|
|
{ |
201
|
|
|
return $this->getHelperSet()->get($name); |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.