|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Meanbee\LibMageConf\ConfigReader; |
|
4
|
|
|
|
|
5
|
|
|
use Meanbee\LibMageConf\ConfigReader; |
|
6
|
|
|
use Meanbee\LibMageConf\Exception\FileNotFound; |
|
7
|
|
|
use Meanbee\LibMageConf\Util\ArrayQuery; |
|
8
|
|
|
use Meanbee\LibMageConf\Util\DsnParser; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class MagentoTwo implements ConfigReader |
|
12
|
|
|
{ |
|
13
|
|
|
protected $configFile; |
|
14
|
|
|
protected $configArray; |
|
15
|
|
|
protected $config; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct($configFile) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->configFile = $configFile; |
|
20
|
|
|
|
|
21
|
|
|
if (!file_exists($this->configFile)) { |
|
22
|
|
|
throw new FileNotFound( |
|
23
|
|
|
sprintf("Unable to find config file at %s", $this->configFile) |
|
24
|
|
|
); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$this->configArray = include $this->configFile; |
|
28
|
|
|
$this->config = new ArrayQuery($this->configArray); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return null|string |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getDatabaseHost() |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->getDsnParser()->getHost(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return null|string |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getDatabasePort() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->getDsnParser()->getPort(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return null|string |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getDatabaseUsername() |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->getConfigValue('db/connection/default/username'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return null|string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getDatabasePassword() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->getConfigValue('db/connection/default/password'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return null|string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getDatabaseName() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->getConfigValue('db/connection/default/dbname'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return null|string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getInstallDate() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->getConfigValue('install/date'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return null|string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getAdminFrontName() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->getConfigValue('backend/frontName'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param $path |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function getConfigValue($path) |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->config->query($path); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return DsnParser |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function getDsnParser() |
|
101
|
|
|
{ |
|
102
|
|
|
$rawHost = $this->getConfigValue('db/connection/default/host'); |
|
103
|
|
|
return new DsnParser($rawHost); |
|
104
|
|
|
} |
|
105
|
|
|
} |