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\DsnParser; |
8
|
|
|
|
9
|
|
|
class MagentoOne implements ConfigReader |
10
|
|
|
{ |
11
|
|
|
protected $configFile; |
12
|
|
|
protected $xmlDoc; |
13
|
|
|
|
14
|
|
|
public function __construct($configFile) |
15
|
|
|
{ |
16
|
|
|
$this->configFile = $configFile; |
17
|
|
|
|
18
|
|
|
if (!file_exists($this->configFile)) { |
19
|
|
|
throw new FileNotFound( |
20
|
|
|
sprintf("Unable to find config file at %s", $this->configFile) |
21
|
|
|
); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return \SimpleXMLElement |
27
|
|
|
*/ |
28
|
|
|
protected function getXmlDoc() |
29
|
|
|
{ |
30
|
|
|
if ($this->xmlDoc === null) { |
31
|
|
|
$this->xmlDoc = new \SimpleXMLElement(file_get_contents($this->configFile)); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $this->xmlDoc; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param $xpath |
39
|
|
|
* @return null|string |
40
|
|
|
*/ |
41
|
|
|
public function xpath($xpath) |
42
|
|
|
{ |
43
|
|
|
$result = $this->getXmlDoc()->xpath($xpath); |
44
|
|
|
|
45
|
|
|
if (count($result) > 0) { |
46
|
|
|
return (string) $result[0]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return null; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return null|string |
54
|
|
|
*/ |
55
|
|
|
public function getDatabaseHost() |
56
|
|
|
{ |
57
|
|
|
return $this->getDsnParser()->getHost(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return null|string |
62
|
|
|
*/ |
63
|
|
|
public function getDatabasePort() |
64
|
|
|
{ |
65
|
|
|
return $this->getDsnParser()->getPort(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return null|string |
70
|
|
|
*/ |
71
|
|
|
public function getDatabaseUsername() |
72
|
|
|
{ |
73
|
|
|
return $this->xpath('//config/global/resources/default_setup/connection/username'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return null|string |
78
|
|
|
*/ |
79
|
|
|
public function getDatabasePassword() |
80
|
|
|
{ |
81
|
|
|
return $this->xpath('//config/global/resources/default_setup/connection/password'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return null|string |
86
|
|
|
*/ |
87
|
|
|
public function getDatabaseName() |
88
|
|
|
{ |
89
|
|
|
return $this->xpath('//config/global/resources/default_setup/connection/dbname'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return null|string |
94
|
|
|
*/ |
95
|
|
|
public function getInstallDate() |
96
|
|
|
{ |
97
|
|
|
return $this->xpath('//config/global/install/date'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return null|string |
102
|
|
|
*/ |
103
|
|
|
public function getAdminFrontName() |
104
|
|
|
{ |
105
|
|
|
return $this->xpath('//config/admin/routers/adminhtml/args/frontName'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return DsnParser |
110
|
|
|
*/ |
111
|
|
|
protected function getDsnParser() |
112
|
|
|
{ |
113
|
|
|
$rawHost = $this->xpath('//config/global/resources/default_setup/connection/host'); |
114
|
|
|
return new DsnParser($rawHost); |
115
|
|
|
} |
116
|
|
|
} |