9 * Currently selected host.
15 protected function getConfigFilePath()
17 if (!isset($_SERVER['HOME'])) {
21 return $_SERVER['HOME'] . '/.config/shpub.ini';
24 public function load()
26 $cfgFile = $this->getConfigFilePath();
27 if ($cfgFile == false) {
31 if (!file_exists($cfgFile) || !is_readable($cfgFile)) {
35 $data = parse_ini_file($cfgFile, true);
36 foreach ($data as $key => $val) {
37 if (!is_array($val)) {
40 $host = new Config_Host();
41 foreach ($val as $hostProp => $hostVal) {
42 if (!property_exists($host, $hostProp)) {
43 Log::err('Invalid config key "' . $hostProp . '"');
46 $host->$hostProp = $hostVal;
48 $this->hosts[$key] = $host;
52 public function save()
55 foreach ($this->hosts as $hostName => $host) {
59 $str .= '[' . $hostName . "]\n";
60 foreach ($host as $hostProp => $hostVal) {
61 if ($hostProp == 'cache') {
67 $str .= $hostProp . '=' . $hostVal . "\n";
70 file_put_contents($this->getConfigFilePath(), $str);
73 public function getDefaultHost()
75 if (!count($this->hosts)) {
78 foreach ($this->hosts as $key => $host) {
85 return key($this->hosts);
88 public function getHostByName($keyOrServer)
90 if (!count($this->hosts)) {
93 foreach ($this->hosts as $key => $host) {
94 if ($key == $keyOrServer || $host->server == $keyOrServer) {