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

Compat.php « Config « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e4de6eadc741034ef743c78e6f8f0a66f694bb0b (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?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
 */

/**
 * Backward compatibility ayer
 *
 * @todo remove this in 2.0
 * @since 1.7
 * @deprecated 1.7
 * @see Piwik::createConfigObject()
 *
 * @package Piwik
 * @subpackage Piwik_Config
 */
class Piwik_Config_Compat_Array
{
	private $data;
	private $parent;

	/**
	 * Constructor
	 *
	 * @param array $data configuration section
	 */
	public function __construct($parent, array $data)
	{
		$this->parent = $parent;
		$this->data = $data;
	}

	/**
	 * Get value by name
	 *
	 * @param string $name
	 * @return mixed
	 */
	public function __get($name)
	{
		$tmp = $this->data[$name];
		return is_array($tmp) ? new Piwik_Config_Compat_Array($this, $tmp) : $tmp;
	}

	/**
	 * Set name, value pair
	 *
	 * @param string $name
	 * @param mixed $value
	 */
	public function __set($name, $value)
	{
		if (is_object($value) && get_class($value) == 'Piwik_Config_Compat_Array')
		{
			$value = $value->toArray();
		}

		$this->data[$name] = $value;
		$this->setDirtyBit();
	}

	/**
	 * Convert object to array
	 *
	 * @return array
	 */
	public function toArray()
	{
		return $this->data;
	}

	/**
	 * Set dirty bit
	 */
	public function setDirtyBit()
	{
		$this->parent->setDirtyBit();
	}
}

class Piwik_Config_Compat
{
	private $config;
	private $data;
	private $enabled;
	private $dirty;

	/**
	 * Constructor
	 */
	public function __construct()
	{
		$this->config = Piwik_Config::getInstance();
		$this->data = array();
		$this->enabled = true;
		$this->dirty = false;
	}

	/**
	 * Destructor
	 */
	public function __destruct()
	{
		if ($this->enabled && $this->dirty)
		{
			$this->config->forceSave();
		}
		$this->config->clear();
	}

	/**
	 * Get value by name
	 *
	 * @param string $name
	 * @return mixed
	 */
	public function __get($name)
	{
		if (!isset($this->data[$name]))
		{
			$this->data[$name] = $this->config->__get($name);
		}

		$tmp = $this->data[$name];
		return is_array($tmp) ? new Piwik_Config_Compat_Array($this, $tmp) : $tmp;
	}

	/**
	 * Set name, value pair
	 *
	 * @param string $name
	 * @param mixed $value
	 */
	public function __set($name, $value)
	{
		if (is_object($value) && get_class($value) == 'Piwik_Config_Compat_Array')
		{
			$value = $value->toArray();
		}

		$this->config->__set($name, $value);
		$this->dirty = true;
	}

	/**
	 * Set dirty bit
	 */
	public function setDirtyBit()
	{
		$this->dirty = true;
	}

	/**
	 * Disable saving of configuration changes
	 */
	public function disableSavingConfigurationFileUpdates()
	{
		$this->enabled = false;
	}
}