Permalink
Browse files

Merge pull request #27 from zerkms/master

Config class for php-example
  • Loading branch information...
2 parents 9dd152b + dbc5b61 commit 91e0ff40dd0f8e60a3e3d45b1cfb94c89ffea085 @kastner kastner committed Feb 11, 2012
Showing with 44 additions and 0 deletions.
  1. +44 −0 php-example.php
View
@@ -94,3 +94,47 @@ public static function send($data, $sampleRate=1) {
}
}
}
+
+class Config
+{
+ private static $_instance;
+ private $_data;
+
+ private function __construct()
+ {
+ $this->_data = parse_ini_file('statsd.ini', true);
+ }
+
+ public static function getInstance()
+ {
+ if (!self::$_instance) self::$_instance = new self();
+
+ return self::$_instance;
+ }
+
+ public function isEnabled($section)
+ {
+ return isset($this->_data[$section]);
+ }
+
+ public function getConfig($name)
+ {
+ $name_array = explode('.', $name, 2);
+
+ if (count($name_array) < 2) return;
+
+ list($section, $param) = $name_array;
+
+ if (!isset($this->_data[$section][$param])) return;
+
+ return $this->_data[$section][$param];
+ }
+}
+
+/* Config file example (put it into "statsd.ini"):
+
+[statsd]
+host = yourhost
+port = 8125
+
+*/

0 comments on commit 91e0ff4

Please sign in to comment.