12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace StatsDBundle\StatsDBundle\Services;
- class Config
- {
-
- const INI_FILE = '../Resources/config/statsd.ini';
- /**
- * @var Config
- */
- private static $_instance;
- /**
- * @var array
- */
- private $_data;
- /**
- * @param string $ini_file
- */
- private function __construct($ini_file = self::INI_FILE)
- {
- if ($ini_file == self::INI_FILE) {
- $ini_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . $ini_file;
- }
- $this->_data = parse_ini_file($ini_file, true);
- }
- /**
- * @return Config
- */
- public static function getInstance()
- {
- if (!self::$_instance) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- /**
- * @param string $section
- *
- * @return boolean
- */
- public function isEnabled($section)
- {
- return isset($this->_data[$section]);
- }
- /**
- * @param string $name
- *
- * @return string
- */
- 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];
- }
- }
|