Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Config.php « Tracker « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8d9e6f7499f8581d3d1d22c9d070e879fc2943a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?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$
 * 
 * @category Piwik
 * @package Piwik
 */

/**
 * 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
 * @subpackage 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();
	protected $initialized = false;
	
	public function init($pathIniFileUser = null, $pathIniFileGlobal = null)
	{
		if(is_null($pathIniFileGlobal))
		{
			$pathIniFileGlobal = PIWIK_USER_PATH . '/config/global.ini.php'; 
		}
		$this->configGlobal = _parse_ini_file($pathIniFileGlobal, true);

		if(is_null($pathIniFileUser))
		{
			$pathIniFileUser = PIWIK_USER_PATH . '/config/config.ini.php'; 
		}
		$this->configUser = _parse_ini_file($pathIniFileUser, true);
		if($this->configUser)
		{
			foreach($this->configUser as $section => &$sectionValues)
			{ 
				foreach($sectionValues as $name => &$value)
				{
					if(is_array($value)) 
					{
						$value = array_map("html_entity_decode", $value);
					} 
					else 
					{
						$value = html_entity_decode($value);
					}
				}
			}
		}
		$this->initialized = 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(!$this->initialized)
		{
			$this->init();
		}
		
		$section = array();
		if(isset($this->configGlobal[$name]))
		{
			$section = array_merge($section, $this->configGlobal[$name]);
		}
		if(isset($this->configUser[$name]))
		{
			$section = array_merge($section, $this->configUser[$name]);
		}
		if(isset($this->config[$name]))
		{
			$section = array_merge($section, $this->config[$name]);
		}
		return count($section) ? $section : null;
	}

	/**
	 * If called, we use the database_tests credentials
	 * and test configuration overrides
	 */
	public function setTestEnvironment($configTest = array())
	{
		$this->database = $this->database_tests;
		$this->config = $configTest;
	}
}