|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* @author Tom Klingenberg <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace N98\Magento\Command\System\Check\Settings; |
|
7
|
|
|
|
|
8
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface; |
|
9
|
|
|
use Magento\Store\Api\Data\StoreInterface; |
|
10
|
|
|
use Magento\Store\Model\ScopeInterface; |
|
11
|
|
|
use N98\Magento\Command\System\Check\ResultCollection; |
|
12
|
|
|
use N98\Magento\Command\System\Check\StoreCheck; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class CheckAbstract |
|
16
|
|
|
* |
|
17
|
|
|
* @package N98\Magento\Command\System\Check\Settings |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class CheckAbstract implements StoreCheck |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
private $storeConfigPaths = array(); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ScopeConfigInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $scopeConfig; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param ScopeConfigInterface $scopeConfig |
|
33
|
|
|
*/ |
|
34
|
|
|
final public function __construct(ScopeConfigInterface $scopeConfig) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->scopeConfig = $scopeConfig; |
|
37
|
|
|
|
|
38
|
|
|
$this->initConfigPaths(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
abstract protected function initConfigPaths(); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string $name |
|
45
|
|
|
* @param string $configPath |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function registerStoreConfigPath($name, $configPath) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->storeConfigPaths[$name] = $configPath; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param ResultCollection $results |
|
54
|
|
|
* @param StoreInterface $store |
|
55
|
|
|
* |
|
56
|
|
|
*/ |
|
57
|
|
|
public function check(ResultCollection $results, StoreInterface $store) |
|
58
|
|
|
{ |
|
59
|
|
|
$result = $results->createResult(); |
|
60
|
|
|
|
|
61
|
|
|
$typedParams = array( |
|
62
|
|
|
'result' => $result, |
|
63
|
|
|
'store' => $store, |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
$paramValues = $this->getParamValues($store, $typedParams); |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
$name = 'checkSettings'; |
|
70
|
|
|
$method = new \ReflectionMethod($this, $name); |
|
71
|
|
|
$parameters = $method->getParameters(); |
|
72
|
|
|
|
|
73
|
|
|
$arguments = array(); |
|
74
|
|
|
foreach ($parameters as $parameter) { |
|
75
|
|
|
$paramName = $parameter->getName(); |
|
76
|
|
|
$paramClass = $parameter->getClass(); |
|
77
|
|
|
|
|
78
|
|
|
// create named parameter from type-hint if applicable |
|
79
|
|
|
if ($paramClass) { |
|
80
|
|
|
foreach ($typedParams as $object) { |
|
81
|
|
|
if ($paramClass->isSubclassOf(get_class($object))) { |
|
82
|
|
|
$paramValues[$paramName] = $object; |
|
83
|
|
|
break; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// use named parameter, otherwise null |
|
89
|
|
|
$paramValues += array($paramName => null); |
|
90
|
|
|
$arguments[] = $paramValues[$paramName]; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
call_user_func_array(array($this, $name), $arguments); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param StoreInterface $store |
|
98
|
|
|
* @param array $typedParams |
|
99
|
|
|
* @return array |
|
100
|
|
|
*/ |
|
101
|
|
|
private function getParamValues(StoreInterface $store, array $typedParams) |
|
102
|
|
|
{ |
|
103
|
|
|
$paramValues = $this->storeConfigPaths; |
|
104
|
|
|
|
|
105
|
|
|
foreach ($paramValues as $name => $path) { |
|
106
|
|
|
$value = $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $store->getCode()); |
|
107
|
|
|
$paramValues[$name] = $value; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$paramValues = $typedParams + $paramValues; |
|
111
|
|
|
|
|
112
|
|
|
return $paramValues; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@returndoc comment to communicate to implementors of these methods what they are expected to return.