diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2008-10-28 14:42:44 +0300 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2008-10-28 14:42:44 +0300 |
commit | 255b887a67c9eb6eaac2ff243b3879756d6cb802 (patch) | |
tree | 40acb631d96976a11160e9f4317cbb47a023c725 /core/Tracker/Config.php | |
parent | c1027ca9be90fd572bf6aafc690b7d93e6c75e40 (diff) |
- renaming all instances of LogStats to Tracker for clarity
- improving error message to be prettier
- adding footer in all admin pages for consistency
Diffstat (limited to 'core/Tracker/Config.php')
-rw-r--r-- | core/Tracker/Config.php | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/core/Tracker/Config.php b/core/Tracker/Config.php new file mode 100644 index 0000000000..f6e296d02a --- /dev/null +++ b/core/Tracker/Config.php @@ -0,0 +1,80 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later + * @version $Id: Config.php 450 2008-04-20 22:33:27Z matt $ + * + * @package Piwik_Tracker + */ + +/** + * Simple class to access the configuration file + * + * This is essentially a simple version of Zend_Config that we wrote + * because of performance reasons. + * The Tracker module can't afford a dependency with the Zend_Framework. + * + * It's using the php.net/parse_ini_file function to parse the configuration files. + * It can be used to access both user config.ini.php and piwik global.ini.php config file. + * + * @package Piwik_Tracker + */ +class Piwik_Tracker_Config +{ + static private $instance = null; + + /** + * Returns singleton + * + * @return Piwik_Tracker_Config + */ + static public function getInstance() + { + if (self::$instance == null) + { + $c = __CLASS__; + self::$instance = new $c(); + } + return self::$instance; + } + + /** + * Contains configuration files values + * + * @var array + */ + public $config = array(); + + private function __construct() + { + $pathIniFileUser = 'config/config.ini.php'; + $pathIniFileGlobal = 'config/global.ini.php'; + $this->configUser = parse_ini_file($pathIniFileUser, true); + $this->configGlobal = parse_ini_file($pathIniFileGlobal, true); + } + + /** + * Magic get methods catching calls to $config->var_name + * Returns the value if found in the + * + * @param string $name + * @return mixed The value requested, usually a string + * @throws exception if the value requested not found in both files + */ + public function __get( $name ) + { + if(isset($this->configUser[$name])) + { + return $this->configUser[$name]; + } + if(isset($this->configGlobal[$name])) + { + return $this->configGlobal[$name]; + } + throw new Exception("The config element $name is not available in the configuration (check the configuration file)."); + } +} + + |