4 const PATH = '/etc/musiikki.conf';
5 const PATH_DLNA = '/etc/minidlna.conf';
6 const SHARE_READ = 'musicread';
7 const SHARE_WRITE = 'musicwrite';
9 private static $main = false;
11 private $values = array();
13 public static function main()
15 if (self::$main === false)
16 self::$main = new Config(Config::PATH);
21 private function __construct($path)
23 $this->loadValues($path);
24 $this->loadMiniDLNA(static::PATH_DLNA);
27 private function loadValues($path)
29 if (!is_readable($path))
30 throw new Exception('Cannot open config file ' . $path);
32 $f = fopen($path, 'r');
34 throw new Exception('Cannot open config file ' . $path);
36 while (($line = fgets($f)) !== false) {
38 if (substr($line,0,1) == '#') continue;
39 if (!strlen($line)) continue;
41 $parts = explode('=', $line, 2);
42 $this->values[$parts[0]] = $parts[1];
48 private function loadMiniDLNA($path)
50 if (!is_readable($path))
51 throw new Exception('Cannot open config file ' . $path);
53 $f = fopen($path, 'r');
55 throw new Exception('Cannot open config file ' . $path);
57 while (($line = fgets($f)) !== false) {
59 if (substr($line,0,1) == '#') continue;
60 if (!strlen($line)) continue;
61 if (substr($line,0,10) != 'media_dir=') continue;
63 $parts = explode('=', $line, 2);
64 $details = explode(',', $parts[1], 2);
65 $this->values[$parts[0].'_'.$details[0]] = $details[1];
71 public function get($name)
73 if (!array_key_exists($name, $this->values))
76 return $this->values[$name];