|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\System\Setup; |
|
4
|
|
|
|
|
5
|
|
|
use N98\Magento\Command\AbstractMagentoCommand; |
|
6
|
|
|
use Magento\Framework\Module\ModuleListInterface; |
|
7
|
|
|
use Magento\Framework\Module\ResourceInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class AbstractSetupCommand |
|
11
|
|
|
* @package N98\Magento\Command\System\Setup |
|
12
|
|
|
*/ |
|
13
|
|
|
abstract class AbstractSetupCommand extends AbstractMagentoCommand |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var ModuleListInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $moduleList; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var ResourceInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $resource; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Gather dependencies |
|
27
|
|
|
* @param ModuleListInterface $moduleList |
|
28
|
|
|
* @param ResourceInterface $resource |
|
29
|
|
|
*/ |
|
30
|
|
|
public function inject( |
|
31
|
|
|
ModuleListInterface $moduleList, |
|
32
|
|
|
ResourceInterface $resource |
|
33
|
|
|
) { |
|
34
|
|
|
$this->moduleList = $moduleList; |
|
35
|
|
|
$this->resource = $resource; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Determine if a module exists. If it does, return the actual module name (not lowercased). |
|
40
|
|
|
* @param string $requestedModuleName |
|
41
|
|
|
* @return string |
|
|
|
|
|
|
42
|
|
|
* @throws \InvalidArgumentException When the module doesn't exist |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getMagentoModuleName($requestedModuleName) |
|
45
|
|
|
{ |
|
46
|
|
|
$lowercaseModuleName = strtolower($requestedModuleName); |
|
47
|
|
|
foreach ($this->getMagentoModuleList() as $moduleName => $moduleInfo) { |
|
48
|
|
|
if ($lowercaseModuleName === strtolower($moduleName)) { |
|
49
|
|
|
return $moduleName; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
throw new \InvalidArgumentException(sprintf('Module does not exist: "%s"', $requestedModuleName)); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function getMagentoModuleList() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->moduleList->getAll(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return ResourceInterface |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function getMagentoModuleResource() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->resource; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.