Skip to content

Commit

Permalink
Merge pull request statsd#27 from zerkms/master
Browse files Browse the repository at this point in the history
Config class for php-example
  • Loading branch information
kastner committed Feb 11, 2012
2 parents 9dd152b + dbc5b61 commit 91e0ff4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions php-example.php
Expand Up @@ -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.