Completed
Push — scrutinizer ( 84e9d0...6a9613 )
by Fabio
22:48
created
framework/Web/UI/ActiveControls/TCallbackClientSide.php 4 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * TCallbackClientSide class file
4
- *
5
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6
- * @link https://github.com/pradosoft/prado
7
- * @copyright Copyright &copy; 2005-2015 The PRADO Group
8
- * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
- * @package System.Web.UI.ActiveControls
10
- */
3
+	 * TCallbackClientSide class file
4
+	 *
5
+	 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6
+	 * @link https://github.com/pradosoft/prado
7
+	 * @copyright Copyright &copy; 2005-2015 The PRADO Group
8
+	 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
+	 * @package System.Web.UI.ActiveControls
10
+	 */
11 11
 
12 12
 /**
13 13
  * TCallbackClientSide class.
Please login to merge, or discard this patch.
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	}
200 200
 
201 201
 	/**
202
-	 * @return boolean true to post the inputs of the form on callback, default
202
+	 * @return string true to post the inputs of the form on callback, default
203 203
 	 * is post the inputs on callback.
204 204
 	 */
205 205
 	public function getPostState()
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	}
218 218
 
219 219
 	/**
220
-	 * @return integer callback request timeout.
220
+	 * @return string callback request timeout.
221 221
 	 */
222 222
 	public function getRequestTimeOut()
223 223
 	{
@@ -261,6 +261,7 @@  discard block
 block discarded – undo
261 261
 	 * update. This will automatically set HasPrority to true.
262 262
 	 * @param boolean true enables the callback response to update the
263 263
 	 * viewstate.
264
+	 * @param boolean $value
264 265
 	 */
265 266
 	public function setEnablePageStateUpdate($value)
266 267
 	{
@@ -269,7 +270,7 @@  discard block
 block discarded – undo
269 270
 	}
270 271
 
271 272
 	/**
272
-	 * @return boolean client-side viewstate will be updated on callback
273
+	 * @return boolean|string client-side viewstate will be updated on callback
273 274
 	 * response if true. Default is true.
274 275
 	 */
275 276
 	public function getEnablePageStateUpdate()
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	public function setHasPriority($value)
253 253
 	{
254 254
 		// mimic the old behavior
255
-		if(!$value)
255
+		if (!$value)
256 256
 			$this->setEnablePageStateUpdate(false);
257 257
 	}
258 258
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	public function getEnablePageStateUpdate()
276 276
 	{
277 277
 		$option = $this->getOption('EnablePageStateUpdate');
278
-		return ($option===null) ? true : $option;
278
+		return ($option === null) ? true : $option;
279 279
 	}
280 280
 
281 281
 	/**
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 	 */
292 292
 	public function setPostBackTarget($value)
293 293
 	{
294
-		if($value instanceof TControl)
294
+		if ($value instanceof TControl)
295 295
 			$value = $value->getUniqueID();
296 296
 		$this->setOption('EventTarget', $value);
297 297
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -252,8 +252,9 @@  discard block
 block discarded – undo
252 252
 	public function setHasPriority($value)
253 253
 	{
254 254
 		// mimic the old behavior
255
-		if(!$value)
256
-			$this->setEnablePageStateUpdate(false);
255
+		if(!$value) {
256
+					$this->setEnablePageStateUpdate(false);
257
+		}
257 258
 	}
258 259
 
259 260
 	/**
@@ -291,8 +292,9 @@  discard block
 block discarded – undo
291 292
 	 */
292 293
 	public function setPostBackTarget($value)
293 294
 	{
294
-		if($value instanceof TControl)
295
-			$value = $value->getUniqueID();
295
+		if($value instanceof TControl) {
296
+					$value = $value->getUniqueID();
297
+		}
296 298
 		$this->setOption('EventTarget', $value);
297 299
 	}
298 300
 
Please login to merge, or discard this patch.
framework/Collections/TMap.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * TMap, TMapIterator classes
4
- *
5
- * @author Qiang Xue <[email protected]>
6
- * @link https://github.com/pradosoft/prado
7
- * @copyright Copyright &copy; 2005-2015 The PRADO Group
8
- * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
- * @package System.Collections
10
- */
3
+	 * TMap, TMapIterator classes
4
+	 *
5
+	 * @author Qiang Xue <[email protected]>
6
+	 * @link https://github.com/pradosoft/prado
7
+	 * @copyright Copyright &copy; 2005-2015 The PRADO Group
8
+	 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
+	 * @package System.Collections
10
+	 */
11 11
 
12 12
 /**
13 13
  * TMap class
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
  * @package System.Collections
31 31
  * @since 3.0
32 32
  */
33
-class TMap extends TComponent implements IteratorAggregate,ArrayAccess,Countable
33
+class TMap extends TComponent implements IteratorAggregate, ArrayAccess, Countable
34 34
 {
35 35
 	/**
36 36
 	 * @var array internal data storage
37 37
 	 */
38
-	private $_d=array();
38
+	private $_d = array();
39 39
 	/**
40 40
 	 * @var boolean whether this list is read-only
41 41
 	 */
42
-	private $_r=false;
42
+	private $_r = false;
43 43
 
44 44
 	/**
45 45
 	 * Returns an array with the names of all variables of this object that should NOT be serialized
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 	protected function __getZappableSleepProps(&$exprops)
51 51
 	{
52 52
 		parent::__getZappableSleepProps($exprops);
53
-		if ($this->_d===array())
53
+		if ($this->_d === array())
54 54
 			$exprops[] = "\0TMap\0_d";
55
-		if ($this->_r===false)
55
+		if ($this->_r === false)
56 56
 			$exprops[] = "\0TMap\0_r";
57 57
 	}
58 58
 
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 	 * @param boolean whether the list is read-only
64 64
 	 * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator.
65 65
 	 */
66
-	public function __construct($data=null,$readOnly=false)
66
+	public function __construct($data = null, $readOnly = false)
67 67
 	{
68
-		if($data!==null)
68
+		if ($data !== null)
69 69
 			$this->copyFrom($data);
70 70
 		$this->setReadOnly($readOnly);
71 71
 	}
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	protected function setReadOnly($value)
85 85
 	{
86
-		$this->_r=TPropertyValue::ensureBoolean($value);
86
+		$this->_r = TPropertyValue::ensureBoolean($value);
87 87
 	}
88 88
 
89 89
 	/**
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 */
94 94
 	public function getIterator()
95 95
 	{
96
-		return new ArrayIterator( $this->_d );
96
+		return new ArrayIterator($this->_d);
97 97
 	}
98 98
 
99 99
 	/**
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	 * @param mixed value
141 141
 	 * @throws TInvalidOperationException if the map is read-only
142 142
 	 */
143
-	public function add($key,$value)
143
+	public function add($key, $value)
144 144
 	{
145
-		if(!$this->_r)
146
-			$this->_d[$key]=$value;
145
+		if (!$this->_r)
146
+			$this->_d[$key] = $value;
147 147
 		else
148
-			throw new TInvalidOperationException('map_readonly',get_class($this));
148
+			throw new TInvalidOperationException('map_readonly', get_class($this));
149 149
 	}
150 150
 
151 151
 	/**
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
 	 */
157 157
 	public function remove($key)
158 158
 	{
159
-		if(!$this->_r)
159
+		if (!$this->_r)
160 160
 		{
161
-			if(isset($this->_d[$key]) || array_key_exists($key,$this->_d))
161
+			if (isset($this->_d[$key]) || array_key_exists($key, $this->_d))
162 162
 			{
163
-				$value=$this->_d[$key];
163
+				$value = $this->_d[$key];
164 164
 				unset($this->_d[$key]);
165 165
 				return $value;
166 166
 			}
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 				return null;
169 169
 		}
170 170
 		else
171
-			throw new TInvalidOperationException('map_readonly',get_class($this));
171
+			throw new TInvalidOperationException('map_readonly', get_class($this));
172 172
 	}
173 173
 
174 174
 	/**
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	public function clear()
178 178
 	{
179
-		foreach(array_keys($this->_d) as $key)
179
+		foreach (array_keys($this->_d) as $key)
180 180
 			$this->remove($key);
181 181
 	}
182 182
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 	 */
187 187
 	public function contains($key)
188 188
 	{
189
-		return isset($this->_d[$key]) || array_key_exists($key,$this->_d);
189
+		return isset($this->_d[$key]) || array_key_exists($key, $this->_d);
190 190
 	}
191 191
 
192 192
 	/**
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
 	 */
206 206
 	public function copyFrom($data)
207 207
 	{
208
-		if(is_array($data) || $data instanceof Traversable)
208
+		if (is_array($data) || $data instanceof Traversable)
209 209
 		{
210
-			if($this->getCount()>0)
210
+			if ($this->getCount() > 0)
211 211
 				$this->clear();
212
-			foreach($data as $key=>$value)
213
-				$this->add($key,$value);
212
+			foreach ($data as $key=>$value)
213
+				$this->add($key, $value);
214 214
 		}
215
-		else if($data!==null)
215
+		else if ($data !== null)
216 216
 			throw new TInvalidDataTypeException('map_data_not_iterable');
217 217
 	}
218 218
 
@@ -224,12 +224,12 @@  discard block
 block discarded – undo
224 224
 	 */
225 225
 	public function mergeWith($data)
226 226
 	{
227
-		if(is_array($data) || $data instanceof Traversable)
227
+		if (is_array($data) || $data instanceof Traversable)
228 228
 		{
229
-			foreach($data as $key=>$value)
230
-				$this->add($key,$value);
229
+			foreach ($data as $key=>$value)
230
+				$this->add($key, $value);
231 231
 		}
232
-		else if($data!==null)
232
+		else if ($data !== null)
233 233
 			throw new TInvalidDataTypeException('map_data_not_iterable');
234 234
 	}
235 235
 
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
 	 * @param integer the offset to set element
262 262
 	 * @param mixed the element value
263 263
 	 */
264
-	public function offsetSet($offset,$item)
264
+	public function offsetSet($offset, $item)
265 265
 	{
266
-		$this->add($offset,$item);
266
+		$this->add($offset, $item);
267 267
 	}
268 268
 
269 269
 	/**
Please login to merge, or discard this patch.
framework/Util/TCallChain.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -21,19 +21,19 @@  discard block
 block discarded – undo
21 21
 	/**
22 22
 	 *	@var {@link ArrayIterator} for moving through the chained method calls
23 23
 	 */
24
-	private $_iterator=null;
24
+	private $_iterator = null;
25 25
 
26 26
 	/**
27 27
 	 *	@var string the method name of the call chain
28 28
 	 */
29
-	private $_method=null;
29
+	private $_method = null;
30 30
 
31 31
 	/**
32 32
 	 * This initializes the list and the name of the method to be called
33 33
 	 *	@param string the name of the function call
34 34
 	 */
35 35
 	public function __construct($method) {
36
-		$this->_method=$method;
36
+		$this->_method = $method;
37 37
 		parent::__construct();
38 38
 	}
39 39
 
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 	 *			the object and method name as string
45 45
 	 *  @param array The array of arguments to the function call chain
46 46
 	 */
47
-	public function addCall($method,$args)
47
+	public function addCall($method, $args)
48 48
 	{
49
-		$this->add(array($method,$args));
49
+		$this->add(array($method, $args));
50 50
 	}
51 51
 
52 52
 	/**
@@ -90,26 +90,26 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function call()
92 92
 	{
93
-		$args=func_get_args();
94
-		if($this->getCount()===0)
95
-			return isset($args[0])?$args[0]:null;
93
+		$args = func_get_args();
94
+		if ($this->getCount() === 0)
95
+			return isset($args[0]) ? $args[0] : null;
96 96
 
97
-		if(!$this->_iterator)
97
+		if (!$this->_iterator)
98 98
 		{
99
-			$chain_array=array_reverse($this->toArray());
100
-			$this->_iterator=new ArrayIterator($chain_array);
99
+			$chain_array = array_reverse($this->toArray());
100
+			$this->_iterator = new ArrayIterator($chain_array);
101 101
 		}
102
-		if($this->_iterator->valid())
102
+		if ($this->_iterator->valid())
103 103
 			do {
104
-				$handler=$this->_iterator->current();
104
+				$handler = $this->_iterator->current();
105 105
 				$this->_iterator->next();
106
-				if(is_array($handler[0])&&$handler[0][0] instanceof IClassBehavior)
107
-					array_splice($handler[1],1,count($args),$args);
106
+				if (is_array($handler[0]) && $handler[0][0] instanceof IClassBehavior)
107
+					array_splice($handler[1], 1, count($args), $args);
108 108
 				else
109
-					array_splice($handler[1],0,count($args),$args);
110
-				$handler[1][]=$this;
111
-				$result=call_user_func_array($handler[0],$handler[1]);
112
-			} while($this->_iterator->valid());
109
+					array_splice($handler[1], 0, count($args), $args);
110
+				$handler[1][] = $this;
111
+				$result = call_user_func_array($handler[0], $handler[1]);
112
+			} while ($this->_iterator->valid());
113 113
 		else
114 114
 			$result = $args[0];
115 115
 		return $result;
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 	 * @param string method name of the unspecified object method
138 138
 	 * @param array arguments to the unspecified object method
139 139
 	 */
140
-	public function __dycall($method,$args)
140
+	public function __dycall($method, $args)
141 141
 	{
142
-		if($this->_method==$method)
143
-			return call_user_func_array(array($this,'call'),$args);
142
+		if ($this->_method == $method)
143
+			return call_user_func_array(array($this, 'call'), $args);
144 144
 		return null;
145 145
 	}
146 146
 }
147 147
\ No newline at end of file
Please login to merge, or discard this patch.
framework/I18N/core/TCache_Lite.php 3 patches
Indentation   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -46,575 +46,575 @@
 block discarded – undo
46 46
 class TCache_Lite
47 47
 {
48 48
 
49
-    // --- Private properties ---
50
-
51
-    /**
52
-    * Directory where to put the cache files
53
-    * (make sure to add a trailing slash)
54
-    *
55
-    * @var string $_cacheDir
56
-    */
57
-    protected $_cacheDir = '/tmp/';
58
-
59
-    /**
60
-    * Enable / disable caching
61
-    *
62
-    * (can be very usefull for the debug of cached scripts)
63
-    *
64
-    * @var boolean $_caching
65
-    */
66
-    protected $_caching = true;
67
-
68
-    /**
69
-    * Cache lifetime (in seconds)
70
-    *
71
-    * @var int $_lifeTime
72
-    */
73
-    protected $_lifeTime = 3600;
74
-
75
-    /**
76
-    * Enable / disable fileLocking
77
-    *
78
-    * (can avoid cache corruption under bad circumstances)
79
-    *
80
-    * @var boolean $_fileLocking
81
-    */
82
-    protected $_fileLocking = true;
83
-
84
-    /**
85
-    * Timestamp of the last valid cache
86
-    *
87
-    * @var int $_refreshTime
88
-    */
89
-    protected $_refreshTime;
90
-
91
-    /**
92
-    * File name (with path)
93
-    *
94
-    * @var string $_file
95
-    */
96
-    protected $_file;
97
-
98
-    /**
99
-    * Enable / disable write control (the cache is read just after writing
100
-    * to detect corrupt entries)
101
-    *
102
-    * Enable write control will lightly slow the cache writing but not the
103
-    * cache reading. Write control can detect some corrupt cache files but
104
-    * maybe it's not a perfect control
105
-    *
106
-    * @var boolean $_writeControl
107
-    */
108
-    protected $_writeControl = true;
109
-
110
-    /**
111
-    * Enable / disable read control
112
-    *
113
-    * If enabled, a control key is embeded in cache file and this key is
114
-    * compared with the one calculated after the reading.
115
-    *
116
-    * @var boolean $_writeControl
117
-    */
118
-    protected $_readControl = true;
119
-
120
-    /**
121
-    * Type of read control (only if read control is enabled)
122
-    *
123
-    * Available values are :
124
-    * 'md5' for a md5 hash control (best but slowest)
125
-    * 'crc32' for a crc32 hash control (lightly less safe but faster,
126
-    * better choice)
127
-    * 'strlen' for a length only test (fastest)
128
-    *
129
-    * @var boolean $_readControlType
130
-    */
131
-    protected $_readControlType = 'crc32';
132
-
133
-    /**
134
-    * Current cache id
135
-    *
136
-    * @var string $_id
137
-    */
138
-    protected $_id;
139
-
140
-    /**
141
-    * Current cache group
142
-    *
143
-    * @var string $_group
144
-    */
145
-    protected $_group;
146
-
147
-    /**
148
-    * Enable / Disable "Memory Caching"
149
-    *
150
-    * NB : There is no lifetime for memory caching !
151
-    *
152
-    * @var boolean $_memoryCaching
153
-    */
154
-    protected $_memoryCaching = false;
155
-
156
-    /**
157
-    * Enable / Disable "Only Memory Caching"
158
-    * (be carefull, memory caching is "beta quality")
159
-    *
160
-    * @var boolean $_onlyMemoryCaching
161
-    */
162
-    protected $_onlyMemoryCaching = false;
163
-
164
-    /**
165
-    * Memory caching array
166
-    *
167
-    * @var array $_memoryCachingArray
168
-    */
169
-    protected $_memoryCachingArray = array();
170
-
171
-    /**
172
-    * Memory caching counter
173
-    *
174
-    * @var int $memoryCachingCounter
175
-    */
176
-    protected $_memoryCachingCounter = 0;
177
-
178
-    /**
179
-    * Memory caching limit
180
-    *
181
-    * @var int $memoryCachingLimit
182
-    */
183
-    protected $_memoryCachingLimit = 1000;
184
-
185
-    /**
186
-    * File Name protection
187
-    *
188
-    * if set to true, you can use any cache id or group name
189
-    * if set to false, it can be faster but cache ids and group names
190
-    * will be used directly in cache file names so be carefull with
191
-    * special characters...
192
-    *
193
-    * @var boolean $fileNameProtection
194
-    */
195
-    protected $_fileNameProtection = true;
196
-
197
-    /**
198
-    * Enable / disable automatic serialization
199
-    *
200
-    * it can be used to save directly datas which aren't strings
201
-    * (but it's slower)
202
-    *
203
-    * @var boolean $_serialize
204
-    */
205
-    protected $_automaticSerialization = false;
206
-
207
-    // --- Public methods ---
208
-
209
-    /**
210
-    * Constructor
211
-    *
212
-    * $options is an assoc. Available options are :
213
-    * $options = array(
214
-    * 'cacheDir' => directory where to put the cache files (string),
215
-    * 'caching' => enable / disable caching (boolean),
216
-    * 'lifeTime' => cache lifetime in seconds (int),
217
-    * 'fileLocking' => enable / disable fileLocking (boolean),
218
-    * 'writeControl' => enable / disable write control (boolean),
219
-    * 'readControl' => enable / disable read control (boolean),
220
-    * 'readControlType' => type of read control 'crc32', 'md5', 'strlen',
221
-    * 'memoryCaching' => enable / disable memory caching (boolean),
222
-    * 'onlyMemoryCaching' => enable / disable only memory caching (boolean),
223
-    * 'memoryCachingLimit' => max nbr of records in memory caching (int),
224
-    * 'fileNameProtection' => enable / disable file name protection (boolean),
225
-    * 'automaticSerialization' => enable / disable serialization (boolean)
226
-    * );
227
-    *
228
-    * @param array $options options
229
-    * @access public
230
-    */
231
-    function TCache_Lite($options = array(null))
232
-    {
233
-        $availableOptions = array(	'automaticSerialization',
234
-        							'fileNameProtection',
235
-        							'memoryCaching',
236
-        							'onlyMemoryCaching',
237
-        							'memoryCachingLimit',
238
-        							'cacheDir',
239
-        							'caching',
240
-        							'lifeTime',
241
-        							'fileLocking',
242
-        							'writeControl',
243
-        							'readControl',
244
-        							'readControlType');
245
-        foreach($options as $key => $value) {
246
-            if(in_array($key, $availableOptions)) {
247
-                $property = '_'.$key;
248
-                $this->$property = $value;
249
-            }
250
-        }
251
-        $this->_refreshTime = time() - $this->_lifeTime;
49
+	// --- Private properties ---
50
+
51
+	/**
52
+	 * Directory where to put the cache files
53
+	 * (make sure to add a trailing slash)
54
+	 *
55
+	 * @var string $_cacheDir
56
+	 */
57
+	protected $_cacheDir = '/tmp/';
58
+
59
+	/**
60
+	 * Enable / disable caching
61
+	 *
62
+	 * (can be very usefull for the debug of cached scripts)
63
+	 *
64
+	 * @var boolean $_caching
65
+	 */
66
+	protected $_caching = true;
67
+
68
+	/**
69
+	 * Cache lifetime (in seconds)
70
+	 *
71
+	 * @var int $_lifeTime
72
+	 */
73
+	protected $_lifeTime = 3600;
74
+
75
+	/**
76
+	 * Enable / disable fileLocking
77
+	 *
78
+	 * (can avoid cache corruption under bad circumstances)
79
+	 *
80
+	 * @var boolean $_fileLocking
81
+	 */
82
+	protected $_fileLocking = true;
83
+
84
+	/**
85
+	 * Timestamp of the last valid cache
86
+	 *
87
+	 * @var int $_refreshTime
88
+	 */
89
+	protected $_refreshTime;
90
+
91
+	/**
92
+	 * File name (with path)
93
+	 *
94
+	 * @var string $_file
95
+	 */
96
+	protected $_file;
97
+
98
+	/**
99
+	 * Enable / disable write control (the cache is read just after writing
100
+	 * to detect corrupt entries)
101
+	 *
102
+	 * Enable write control will lightly slow the cache writing but not the
103
+	 * cache reading. Write control can detect some corrupt cache files but
104
+	 * maybe it's not a perfect control
105
+	 *
106
+	 * @var boolean $_writeControl
107
+	 */
108
+	protected $_writeControl = true;
109
+
110
+	/**
111
+	 * Enable / disable read control
112
+	 *
113
+	 * If enabled, a control key is embeded in cache file and this key is
114
+	 * compared with the one calculated after the reading.
115
+	 *
116
+	 * @var boolean $_writeControl
117
+	 */
118
+	protected $_readControl = true;
119
+
120
+	/**
121
+	 * Type of read control (only if read control is enabled)
122
+	 *
123
+	 * Available values are :
124
+	 * 'md5' for a md5 hash control (best but slowest)
125
+	 * 'crc32' for a crc32 hash control (lightly less safe but faster,
126
+	 * better choice)
127
+	 * 'strlen' for a length only test (fastest)
128
+	 *
129
+	 * @var boolean $_readControlType
130
+	 */
131
+	protected $_readControlType = 'crc32';
132
+
133
+	/**
134
+	 * Current cache id
135
+	 *
136
+	 * @var string $_id
137
+	 */
138
+	protected $_id;
139
+
140
+	/**
141
+	 * Current cache group
142
+	 *
143
+	 * @var string $_group
144
+	 */
145
+	protected $_group;
146
+
147
+	/**
148
+	 * Enable / Disable "Memory Caching"
149
+	 *
150
+	 * NB : There is no lifetime for memory caching !
151
+	 *
152
+	 * @var boolean $_memoryCaching
153
+	 */
154
+	protected $_memoryCaching = false;
155
+
156
+	/**
157
+	 * Enable / Disable "Only Memory Caching"
158
+	 * (be carefull, memory caching is "beta quality")
159
+	 *
160
+	 * @var boolean $_onlyMemoryCaching
161
+	 */
162
+	protected $_onlyMemoryCaching = false;
163
+
164
+	/**
165
+	 * Memory caching array
166
+	 *
167
+	 * @var array $_memoryCachingArray
168
+	 */
169
+	protected $_memoryCachingArray = array();
170
+
171
+	/**
172
+	 * Memory caching counter
173
+	 *
174
+	 * @var int $memoryCachingCounter
175
+	 */
176
+	protected $_memoryCachingCounter = 0;
177
+
178
+	/**
179
+	 * Memory caching limit
180
+	 *
181
+	 * @var int $memoryCachingLimit
182
+	 */
183
+	protected $_memoryCachingLimit = 1000;
184
+
185
+	/**
186
+	 * File Name protection
187
+	 *
188
+	 * if set to true, you can use any cache id or group name
189
+	 * if set to false, it can be faster but cache ids and group names
190
+	 * will be used directly in cache file names so be carefull with
191
+	 * special characters...
192
+	 *
193
+	 * @var boolean $fileNameProtection
194
+	 */
195
+	protected $_fileNameProtection = true;
196
+
197
+	/**
198
+	 * Enable / disable automatic serialization
199
+	 *
200
+	 * it can be used to save directly datas which aren't strings
201
+	 * (but it's slower)
202
+	 *
203
+	 * @var boolean $_serialize
204
+	 */
205
+	protected $_automaticSerialization = false;
206
+
207
+	// --- Public methods ---
208
+
209
+	/**
210
+	 * Constructor
211
+	 *
212
+	 * $options is an assoc. Available options are :
213
+	 * $options = array(
214
+	 * 'cacheDir' => directory where to put the cache files (string),
215
+	 * 'caching' => enable / disable caching (boolean),
216
+	 * 'lifeTime' => cache lifetime in seconds (int),
217
+	 * 'fileLocking' => enable / disable fileLocking (boolean),
218
+	 * 'writeControl' => enable / disable write control (boolean),
219
+	 * 'readControl' => enable / disable read control (boolean),
220
+	 * 'readControlType' => type of read control 'crc32', 'md5', 'strlen',
221
+	 * 'memoryCaching' => enable / disable memory caching (boolean),
222
+	 * 'onlyMemoryCaching' => enable / disable only memory caching (boolean),
223
+	 * 'memoryCachingLimit' => max nbr of records in memory caching (int),
224
+	 * 'fileNameProtection' => enable / disable file name protection (boolean),
225
+	 * 'automaticSerialization' => enable / disable serialization (boolean)
226
+	 * );
227
+	 *
228
+	 * @param array $options options
229
+	 * @access public
230
+	 */
231
+	function TCache_Lite($options = array(null))
232
+	{
233
+		$availableOptions = array(	'automaticSerialization',
234
+									'fileNameProtection',
235
+									'memoryCaching',
236
+									'onlyMemoryCaching',
237
+									'memoryCachingLimit',
238
+									'cacheDir',
239
+									'caching',
240
+									'lifeTime',
241
+									'fileLocking',
242
+									'writeControl',
243
+									'readControl',
244
+									'readControlType');
245
+		foreach($options as $key => $value) {
246
+			if(in_array($key, $availableOptions)) {
247
+				$property = '_'.$key;
248
+				$this->$property = $value;
249
+			}
250
+		}
251
+		$this->_refreshTime = time() - $this->_lifeTime;
252 252
 	}
253 253
 
254
-    /**
255
-    * Test if a cache is available and (if yes) return it
256
-    *
257
-    * @param string $id cache id
258
-    * @param string $group name of the cache group
259
-    * @param boolean $doNotTestCacheValidity if set to true, the cache
260
-    * validity won't be tested
261
-    * @return string data of the cache (or false if no cache available)
262
-    * @access public
263
-    */
264
-    function get($id, $group = 'default', $doNotTestCacheValidity = false)
265
-    {
266
-        $this->_id = $id;
267
-        $this->_group = $group;
268
-        $data = false;
269
-        if ($this->_caching) {
270
-            $this->_setFileName($id, $group);
271
-            if ($this->_memoryCaching) {
272
-                if (isset($this->_memoryCachingArray[$this->_file])) {
273
-                    if ($this->_automaticSerialization) {
274
-                        return unserialize(
275
-                        			$this->_memoryCachingArray[$this->_file]);
276
-                    } else {
277
-                        return $this->_memoryCachingArray[$this->_file];
278
-                    }
279
-                } else {
280
-                    if ($this->_onlyMemoryCaching) {
281
-                        return false;
282
-                    }
283
-                }
284
-            }
285
-            if ($doNotTestCacheValidity) {
286
-                if (file_exists($this->_file)) {
287
-                    $data = $this->_read();
288
-                }
289
-            } else {
290
-                if (@filemtime($this->_file) > $this->_refreshTime) {
291
-                    $data = $this->_read();
292
-                }
293
-            }
294
-            if (($data) and ($this->_memoryCaching)) {
295
-                $this->_memoryCacheAdd($this->_file, $data);
296
-            }
297
-            if ($this->_automaticSerialization && is_string($data)) {
298
-                $data = unserialize($data);
299
-            }
300
-            return $data;
301
-        }
302
-        return false;
303
-    }
304
-
305
-    /**
306
-    * Save some data in a cache file
307
-    *
308
-    * @param string $data data to put in cache (can be another type than strings
309
-    * if automaticSerialization is on)
310
-    * @param string $id cache id
311
-    * @param string $group name of the cache group
312
-    * @return boolean true if no problem
313
-    * @access public
314
-    */
315
-    function save($data, $id = null, $group = 'default')
316
-    {
317
-        if ($this->_caching) {
318
-            if ($this->_automaticSerialization) {
319
-                $data = serialize($data);
320
-            }
321
-            if (isset($id)) {
322
-                $this->_setFileName($id, $group);
323
-            }
324
-            if ($this->_memoryCaching) {
325
-                $this->_memoryCacheAdd($this->_file, $data);
326
-                if ($this->_onlyMemoryCaching) {
327
-                    return true;
328
-                }
329
-            }
330
-            if ($this->_writeControl) {
331
-                if (!$this->_writeAndControl($data)) {
332
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
333
-                    return false;
334
-                } else {
335
-                    return true;
336
-                }
337
-            } else {
338
-                return $this->_write($data);
339
-            }
340
-        }
341
-        return false;
342
-    }
343
-
344
-    /**
345
-    * Remove a cache file
346
-    *
347
-    * @param string $id cache id
348
-    * @param string $group name of the cache group
349
-    * @return boolean true if no problem
350
-    * @access public
351
-    */
352
-    function remove($id, $group = 'default')
353
-    {
354
-        $this->_setFileName($id, $group);
355
-        if (!@unlink($this->_file)) {
356
-            $this->raiseError('TCache_Lite : Unable to remove cache !', -3);
357
-            return false;
358
-        }
359
-        return true;
360
-    }
361
-
362
-    /**
363
-    * Clean the cache
364
-    *
365
-    * if no group is specified all cache files will be destroyed
366
-    * else only cache files of the specified group will be destroyed
367
-    *
368
-    * @param string $group name of the cache group
369
-    * @return boolean true if no problem
370
-    * @access public
371
-    */
372
-    function clean($group = false)
373
-    {
374
-        if ($this->_fileNameProtection) {
375
-            $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
376
-        } else {
377
-            $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
378
-        }
379
-        if ($this->_memoryCaching) {
380
-            while (list($key, $value) = each($this->_memoryCaching)) {
381
-                if (strpos($key, $motif, 0)) {
382
-                    unset($this->_memoryCaching[$key]);
383
-                    $this->_memoryCachingCounter =
384
-                    		$this->_memoryCachingCounter - 1;
385
-                }
386
-            }
387
-            if ($this->_onlyMemoryCaching) {
388
-                return true;
389
-            }
390
-        }
391
-        if (!($dh = opendir($this->_cacheDir))) {
392
-            $this->raiseError('TCache_Lite : Unable to open cache directory !');
393
-            return false;
394
-        }
395
-        while ($file = readdir($dh)) {
396
-            if (($file != '.') && ($file != '..')) {
397
-                $file = $this->_cacheDir . $file;
398
-                if (is_file($file)) {
399
-                    if (strpos($file, $motif, 0)) {
400
-                        if (!@unlink($file)) {
401
-             $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
402
-                            return false;
403
-                        }
404
-                    }
405
-                }
406
-            }
407
-        }
408
-        return true;
409
-    }
410
-
411
-	    /**
412
-    * Set a new life time
413
-    *
414
-    * @param int $newLifeTime new life time (in seconds)
415
-    * @access public
416
-    */
417
-    function setLifeTime($newLifeTime)
418
-    {
419
-        $this->_lifeTime = $newLifeTime;
420
-        $this->_refreshTime = time() - $newLifeTime;
421
-    }
422
-
423
-    /**
424
-    *
425
-    * @access public
426
-    */
427
-    function saveMemoryCachingState($id, $group = 'default')
428
-    {
429
-        if ($this->_caching) {
430
-            $array = array(
431
-                'counter' => $this->_memoryCachingCounter,
432
-                'array' => $this->_memoryCachingState
433
-            );
434
-            $data = serialize($array);
435
-            $this->save($data, $id, $group);
436
-        }
437
-    }
438
-
439
-    /**
440
-    *
441
-    * @access public
442
-    */
443
-    function getMemoryCachingState($id, $group = 'default',
444
-    								$doNotTestCacheValidity = false)
445
-    {
446
-        if ($this->_caching) {
447
-            if ($data = $this->get($id, $group, $doNotTestCacheValidity))
448
-            {
449
-                $array = unserialize($data);
450
-                $this->_memoryCachingCounter = $array['counter'];
451
-                $this->_memoryCachingArray = $array['array'];
452
-            }
453
-        }
454
-    }
455
-
456
-    /**
457
-    * Return the cache last modification time
458
-    *
459
-    * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !
460
-    *
461
-    * @return int last modification time
462
-    */
463
-    function lastModified() {
464
-        return filemtime($this->cache->_file);
465
-    }
466
-
467
-    /**
468
-    * Trigger a PEAR error
469
-    *
470
-    * To improve performances, the PEAR.php file is included dynamically.
471
-    * The file is so included only when an error is triggered. So, in most
472
-    * cases, the file isn't included and perfs are much better.
473
-    *
474
-    * @param string $msg error message
475
-    * @param int $code error code
476
-    * @access public
477
-    */
478
-    function raiseError($msg, $code)
479
-    {
480
-       throw new Exception($msg);
481
-    }
482
-
483
-    // --- Private methods ---
484
-
485
-    /**
486
-    *
487
-    * @access private
488
-    */
489
-    function _memoryCacheAdd($id, $data)
490
-    {
491
-        $this->_memoryCachingArray[$this->_file] = $data;
492
-        if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
493
-            list($key, $value) = each($this->_memoryCachingArray);
494
-            unset($this->_memoryCachingArray[$key]);
495
-        } else {
496
-            $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
497
-        }
498
-    }
499
-
500
-    /**
501
-    * Make a file name (with path)
502
-    *
503
-    * @param string $id cache id
504
-    * @param string $group name of the group
505
-    * @access private
506
-    */
507
-    function _setFileName($id, $group)
508
-    {
509
-        if ($this->_fileNameProtection) {
510
-            $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
511
-            						.md5($id));
512
-        } else {
513
-            $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
514
-        }
515
-    }
516
-
517
-    function getCacheFile()
518
-    {
519
-    	return $this->_file;
520
-    }
521
-
522
-    /**
523
-    * Read the cache file and return the content
524
-    *
525
-    * @return string content of the cache file
526
-    * @access private
527
-    */
528
-    function _read()
529
-    {
530
-        $fp = @fopen($this->_file, "rb");
531
-        if ($this->_fileLocking) @flock($fp, LOCK_SH);
532
-        if ($fp) {
533
-        	// because the filesize can be cached by PHP itself...
534
-            clearstatcache();
535
-            $length = @filesize($this->_file);
536
-            if ($this->_readControl) {
537
-                $hashControl = @fread($fp, 32);
538
-                $length = $length - 32;
539
-            }
540
-            $data = @fread($fp, $length);
541
-            if ($this->_fileLocking) @flock($fp, LOCK_UN);
542
-            @fclose($fp);
543
-            if ($this->_readControl) {
544
-                $hashData = $this->_hash($data, $this->_readControlType);
545
-                if ($hashData != $hashControl) {
546
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
547
-                    return false;
548
-                }
549
-            }
550
-            return $data;
551
-        }
552
-        $this->raiseError('Cache_Lite : Unable to read cache !', -2);
553
-        return false;
554
-    }
555
-
556
-    /**
557
-    * Write the given data in the cache file
558
-    *
559
-    * @param string $data data to put in cache
560
-    * @return boolean true if ok
561
-    * @access private
562
-    */
563
-    function _write($data)
564
-    {
565
-        $fp = @fopen($this->_file, "wb");
566
-        if ($fp) {
567
-            if ($this->_fileLocking) @flock($fp, LOCK_EX);
568
-            if ($this->_readControl) {
569
-                @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
570
-            }
571
-            $len = strlen($data);
572
-            @fwrite($fp, $data, $len);
573
-            if ($this->_fileLocking) @flock($fp, LOCK_UN);
574
-            @fclose($fp);
575
-            return true;
576
-        }
577
-        $this->raiseError('Cache_Lite : Unable to write cache !', -1);
578
-        return false;
579
-    }
580
-
581
-    /**
582
-    * Write the given data in the cache file and control it just after to avoid
583
-    * corrupted cache entries
584
-    *
585
-    * @param string $data data to put in cache
586
-    * @return boolean true if the test is ok
587
-    * @access private
588
-    */
589
-    function _writeAndControl($data)
590
-    {
591
-        $this->_write($data);
592
-        $dataRead = $this->_read($data);
593
-        return ($dataRead==$data);
594
-    }
595
-
596
-    /**
597
-    * Make a control key with the string containing datas
598
-    *
599
-    * @param string $data data
600
-    * @param string $controlType type of control 'md5', 'crc32' or 'strlen'
601
-    * @return string control key
602
-    * @access private
603
-    */
604
-    function _hash($data, $controlType)
605
-    {
606
-        switch ($controlType) {
607
-        case 'md5':
608
-            return md5($data);
609
-        case 'crc32':
610
-            return sprintf('% 32d', crc32($data));
611
-        case 'strlen':
612
-            return sprintf('% 32d', strlen($data));
613
-        default:
614
-            $this->raiseError('Unknown controlType ! '.
615
-            '(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
616
-        }
617
-    }
254
+	/**
255
+	 * Test if a cache is available and (if yes) return it
256
+	 *
257
+	 * @param string $id cache id
258
+	 * @param string $group name of the cache group
259
+	 * @param boolean $doNotTestCacheValidity if set to true, the cache
260
+	 * validity won't be tested
261
+	 * @return string data of the cache (or false if no cache available)
262
+	 * @access public
263
+	 */
264
+	function get($id, $group = 'default', $doNotTestCacheValidity = false)
265
+	{
266
+		$this->_id = $id;
267
+		$this->_group = $group;
268
+		$data = false;
269
+		if ($this->_caching) {
270
+			$this->_setFileName($id, $group);
271
+			if ($this->_memoryCaching) {
272
+				if (isset($this->_memoryCachingArray[$this->_file])) {
273
+					if ($this->_automaticSerialization) {
274
+						return unserialize(
275
+									$this->_memoryCachingArray[$this->_file]);
276
+					} else {
277
+						return $this->_memoryCachingArray[$this->_file];
278
+					}
279
+				} else {
280
+					if ($this->_onlyMemoryCaching) {
281
+						return false;
282
+					}
283
+				}
284
+			}
285
+			if ($doNotTestCacheValidity) {
286
+				if (file_exists($this->_file)) {
287
+					$data = $this->_read();
288
+				}
289
+			} else {
290
+				if (@filemtime($this->_file) > $this->_refreshTime) {
291
+					$data = $this->_read();
292
+				}
293
+			}
294
+			if (($data) and ($this->_memoryCaching)) {
295
+				$this->_memoryCacheAdd($this->_file, $data);
296
+			}
297
+			if ($this->_automaticSerialization && is_string($data)) {
298
+				$data = unserialize($data);
299
+			}
300
+			return $data;
301
+		}
302
+		return false;
303
+	}
304
+
305
+	/**
306
+	 * Save some data in a cache file
307
+	 *
308
+	 * @param string $data data to put in cache (can be another type than strings
309
+	 * if automaticSerialization is on)
310
+	 * @param string $id cache id
311
+	 * @param string $group name of the cache group
312
+	 * @return boolean true if no problem
313
+	 * @access public
314
+	 */
315
+	function save($data, $id = null, $group = 'default')
316
+	{
317
+		if ($this->_caching) {
318
+			if ($this->_automaticSerialization) {
319
+				$data = serialize($data);
320
+			}
321
+			if (isset($id)) {
322
+				$this->_setFileName($id, $group);
323
+			}
324
+			if ($this->_memoryCaching) {
325
+				$this->_memoryCacheAdd($this->_file, $data);
326
+				if ($this->_onlyMemoryCaching) {
327
+					return true;
328
+				}
329
+			}
330
+			if ($this->_writeControl) {
331
+				if (!$this->_writeAndControl($data)) {
332
+					@touch($this->_file, time() - 2*abs($this->_lifeTime));
333
+					return false;
334
+				} else {
335
+					return true;
336
+				}
337
+			} else {
338
+				return $this->_write($data);
339
+			}
340
+		}
341
+		return false;
342
+	}
343
+
344
+	/**
345
+	 * Remove a cache file
346
+	 *
347
+	 * @param string $id cache id
348
+	 * @param string $group name of the cache group
349
+	 * @return boolean true if no problem
350
+	 * @access public
351
+	 */
352
+	function remove($id, $group = 'default')
353
+	{
354
+		$this->_setFileName($id, $group);
355
+		if (!@unlink($this->_file)) {
356
+			$this->raiseError('TCache_Lite : Unable to remove cache !', -3);
357
+			return false;
358
+		}
359
+		return true;
360
+	}
361
+
362
+	/**
363
+	 * Clean the cache
364
+	 *
365
+	 * if no group is specified all cache files will be destroyed
366
+	 * else only cache files of the specified group will be destroyed
367
+	 *
368
+	 * @param string $group name of the cache group
369
+	 * @return boolean true if no problem
370
+	 * @access public
371
+	 */
372
+	function clean($group = false)
373
+	{
374
+		if ($this->_fileNameProtection) {
375
+			$motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
376
+		} else {
377
+			$motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
378
+		}
379
+		if ($this->_memoryCaching) {
380
+			while (list($key, $value) = each($this->_memoryCaching)) {
381
+				if (strpos($key, $motif, 0)) {
382
+					unset($this->_memoryCaching[$key]);
383
+					$this->_memoryCachingCounter =
384
+							$this->_memoryCachingCounter - 1;
385
+				}
386
+			}
387
+			if ($this->_onlyMemoryCaching) {
388
+				return true;
389
+			}
390
+		}
391
+		if (!($dh = opendir($this->_cacheDir))) {
392
+			$this->raiseError('TCache_Lite : Unable to open cache directory !');
393
+			return false;
394
+		}
395
+		while ($file = readdir($dh)) {
396
+			if (($file != '.') && ($file != '..')) {
397
+				$file = $this->_cacheDir . $file;
398
+				if (is_file($file)) {
399
+					if (strpos($file, $motif, 0)) {
400
+						if (!@unlink($file)) {
401
+			 $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
402
+							return false;
403
+						}
404
+					}
405
+				}
406
+			}
407
+		}
408
+		return true;
409
+	}
410
+
411
+		/**
412
+		 * Set a new life time
413
+		 *
414
+		 * @param int $newLifeTime new life time (in seconds)
415
+		 * @access public
416
+		 */
417
+	function setLifeTime($newLifeTime)
418
+	{
419
+		$this->_lifeTime = $newLifeTime;
420
+		$this->_refreshTime = time() - $newLifeTime;
421
+	}
422
+
423
+	/**
424
+	 *
425
+	 * @access public
426
+	 */
427
+	function saveMemoryCachingState($id, $group = 'default')
428
+	{
429
+		if ($this->_caching) {
430
+			$array = array(
431
+				'counter' => $this->_memoryCachingCounter,
432
+				'array' => $this->_memoryCachingState
433
+			);
434
+			$data = serialize($array);
435
+			$this->save($data, $id, $group);
436
+		}
437
+	}
438
+
439
+	/**
440
+	 *
441
+	 * @access public
442
+	 */
443
+	function getMemoryCachingState($id, $group = 'default',
444
+									$doNotTestCacheValidity = false)
445
+	{
446
+		if ($this->_caching) {
447
+			if ($data = $this->get($id, $group, $doNotTestCacheValidity))
448
+			{
449
+				$array = unserialize($data);
450
+				$this->_memoryCachingCounter = $array['counter'];
451
+				$this->_memoryCachingArray = $array['array'];
452
+			}
453
+		}
454
+	}
455
+
456
+	/**
457
+	 * Return the cache last modification time
458
+	 *
459
+	 * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !
460
+	 *
461
+	 * @return int last modification time
462
+	 */
463
+	function lastModified() {
464
+		return filemtime($this->cache->_file);
465
+	}
466
+
467
+	/**
468
+	 * Trigger a PEAR error
469
+	 *
470
+	 * To improve performances, the PEAR.php file is included dynamically.
471
+	 * The file is so included only when an error is triggered. So, in most
472
+	 * cases, the file isn't included and perfs are much better.
473
+	 *
474
+	 * @param string $msg error message
475
+	 * @param int $code error code
476
+	 * @access public
477
+	 */
478
+	function raiseError($msg, $code)
479
+	{
480
+	   throw new Exception($msg);
481
+	}
482
+
483
+	// --- Private methods ---
484
+
485
+	/**
486
+	 *
487
+	 * @access private
488
+	 */
489
+	function _memoryCacheAdd($id, $data)
490
+	{
491
+		$this->_memoryCachingArray[$this->_file] = $data;
492
+		if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
493
+			list($key, $value) = each($this->_memoryCachingArray);
494
+			unset($this->_memoryCachingArray[$key]);
495
+		} else {
496
+			$this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
497
+		}
498
+	}
499
+
500
+	/**
501
+	 * Make a file name (with path)
502
+	 *
503
+	 * @param string $id cache id
504
+	 * @param string $group name of the group
505
+	 * @access private
506
+	 */
507
+	function _setFileName($id, $group)
508
+	{
509
+		if ($this->_fileNameProtection) {
510
+			$this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
511
+									.md5($id));
512
+		} else {
513
+			$this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
514
+		}
515
+	}
516
+
517
+	function getCacheFile()
518
+	{
519
+		return $this->_file;
520
+	}
521
+
522
+	/**
523
+	 * Read the cache file and return the content
524
+	 *
525
+	 * @return string content of the cache file
526
+	 * @access private
527
+	 */
528
+	function _read()
529
+	{
530
+		$fp = @fopen($this->_file, "rb");
531
+		if ($this->_fileLocking) @flock($fp, LOCK_SH);
532
+		if ($fp) {
533
+			// because the filesize can be cached by PHP itself...
534
+			clearstatcache();
535
+			$length = @filesize($this->_file);
536
+			if ($this->_readControl) {
537
+				$hashControl = @fread($fp, 32);
538
+				$length = $length - 32;
539
+			}
540
+			$data = @fread($fp, $length);
541
+			if ($this->_fileLocking) @flock($fp, LOCK_UN);
542
+			@fclose($fp);
543
+			if ($this->_readControl) {
544
+				$hashData = $this->_hash($data, $this->_readControlType);
545
+				if ($hashData != $hashControl) {
546
+					@touch($this->_file, time() - 2*abs($this->_lifeTime));
547
+					return false;
548
+				}
549
+			}
550
+			return $data;
551
+		}
552
+		$this->raiseError('Cache_Lite : Unable to read cache !', -2);
553
+		return false;
554
+	}
555
+
556
+	/**
557
+	 * Write the given data in the cache file
558
+	 *
559
+	 * @param string $data data to put in cache
560
+	 * @return boolean true if ok
561
+	 * @access private
562
+	 */
563
+	function _write($data)
564
+	{
565
+		$fp = @fopen($this->_file, "wb");
566
+		if ($fp) {
567
+			if ($this->_fileLocking) @flock($fp, LOCK_EX);
568
+			if ($this->_readControl) {
569
+				@fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
570
+			}
571
+			$len = strlen($data);
572
+			@fwrite($fp, $data, $len);
573
+			if ($this->_fileLocking) @flock($fp, LOCK_UN);
574
+			@fclose($fp);
575
+			return true;
576
+		}
577
+		$this->raiseError('Cache_Lite : Unable to write cache !', -1);
578
+		return false;
579
+	}
580
+
581
+	/**
582
+	 * Write the given data in the cache file and control it just after to avoid
583
+	 * corrupted cache entries
584
+	 *
585
+	 * @param string $data data to put in cache
586
+	 * @return boolean true if the test is ok
587
+	 * @access private
588
+	 */
589
+	function _writeAndControl($data)
590
+	{
591
+		$this->_write($data);
592
+		$dataRead = $this->_read($data);
593
+		return ($dataRead==$data);
594
+	}
595
+
596
+	/**
597
+	 * Make a control key with the string containing datas
598
+	 *
599
+	 * @param string $data data
600
+	 * @param string $controlType type of control 'md5', 'crc32' or 'strlen'
601
+	 * @return string control key
602
+	 * @access private
603
+	 */
604
+	function _hash($data, $controlType)
605
+	{
606
+		switch ($controlType) {
607
+		case 'md5':
608
+			return md5($data);
609
+		case 'crc32':
610
+			return sprintf('% 32d', crc32($data));
611
+		case 'strlen':
612
+			return sprintf('% 32d', strlen($data));
613
+		default:
614
+			$this->raiseError('Unknown controlType ! '.
615
+			'(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
616
+		}
617
+	}
618 618
 
619 619
 }
620 620
 
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
     */
231 231
     function TCache_Lite($options = array(null))
232 232
     {
233
-        $availableOptions = array(	'automaticSerialization',
233
+        $availableOptions = array('automaticSerialization',
234 234
         							'fileNameProtection',
235 235
         							'memoryCaching',
236 236
         							'onlyMemoryCaching',
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
         							'writeControl',
243 243
         							'readControl',
244 244
         							'readControlType');
245
-        foreach($options as $key => $value) {
246
-            if(in_array($key, $availableOptions)) {
247
-                $property = '_'.$key;
245
+        foreach ($options as $key => $value) {
246
+            if (in_array($key, $availableOptions)) {
247
+                $property = '_' . $key;
248 248
                 $this->$property = $value;
249 249
             }
250 250
         }
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
             }
330 330
             if ($this->_writeControl) {
331 331
                 if (!$this->_writeAndControl($data)) {
332
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
332
+                    @touch($this->_file, time() - 2 * abs($this->_lifeTime));
333 333
                     return false;
334 334
                 } else {
335 335
                     return true;
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
     function clean($group = false)
373 373
     {
374 374
         if ($this->_fileNameProtection) {
375
-            $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
375
+            $motif = ($group) ? 'cache_' . md5($group) . '_' : 'cache_';
376 376
         } else {
377
-            $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
377
+            $motif = ($group) ? 'cache_' . $group . '_' : 'cache_';
378 378
         }
379 379
         if ($this->_memoryCaching) {
380 380
             while (list($key, $value) = each($this->_memoryCaching)) {
@@ -507,10 +507,10 @@  discard block
 block discarded – undo
507 507
     function _setFileName($id, $group)
508 508
     {
509 509
         if ($this->_fileNameProtection) {
510
-            $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
510
+            $this->_file = ($this->_cacheDir . 'cache_' . md5($group) . '_'
511 511
             						.md5($id));
512 512
         } else {
513
-            $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
513
+            $this->_file = $this->_cacheDir . 'cache_' . $group . '_' . $id;
514 514
         }
515 515
     }
516 516
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
             if ($this->_readControl) {
544 544
                 $hashData = $this->_hash($data, $this->_readControlType);
545 545
                 if ($hashData != $hashControl) {
546
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
546
+                    @touch($this->_file, time() - 2 * abs($this->_lifeTime));
547 547
                     return false;
548 548
                 }
549 549
             }
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
     {
591 591
         $this->_write($data);
592 592
         $dataRead = $this->_read($data);
593
-        return ($dataRead==$data);
593
+        return ($dataRead == $data);
594 594
     }
595 595
 
596 596
     /**
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
         case 'strlen':
612 612
             return sprintf('% 32d', strlen($data));
613 613
         default:
614
-            $this->raiseError('Unknown controlType ! '.
614
+            $this->raiseError('Unknown controlType ! ' .
615 615
             '(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
616 616
         }
617 617
     }
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -528,7 +528,9 @@  discard block
 block discarded – undo
528 528
     function _read()
529 529
     {
530 530
         $fp = @fopen($this->_file, "rb");
531
-        if ($this->_fileLocking) @flock($fp, LOCK_SH);
531
+        if ($this->_fileLocking) {
532
+        	@flock($fp, LOCK_SH);
533
+        }
532 534
         if ($fp) {
533 535
         	// because the filesize can be cached by PHP itself...
534 536
             clearstatcache();
@@ -538,7 +540,9 @@  discard block
 block discarded – undo
538 540
                 $length = $length - 32;
539 541
             }
540 542
             $data = @fread($fp, $length);
541
-            if ($this->_fileLocking) @flock($fp, LOCK_UN);
543
+            if ($this->_fileLocking) {
544
+            	@flock($fp, LOCK_UN);
545
+            }
542 546
             @fclose($fp);
543 547
             if ($this->_readControl) {
544 548
                 $hashData = $this->_hash($data, $this->_readControlType);
@@ -564,13 +568,17 @@  discard block
 block discarded – undo
564 568
     {
565 569
         $fp = @fopen($this->_file, "wb");
566 570
         if ($fp) {
567
-            if ($this->_fileLocking) @flock($fp, LOCK_EX);
571
+            if ($this->_fileLocking) {
572
+            	@flock($fp, LOCK_EX);
573
+            }
568 574
             if ($this->_readControl) {
569 575
                 @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
570 576
             }
571 577
             $len = strlen($data);
572 578
             @fwrite($fp, $data, $len);
573
-            if ($this->_fileLocking) @flock($fp, LOCK_UN);
579
+            if ($this->_fileLocking) {
580
+            	@flock($fp, LOCK_UN);
581
+            }
574 582
             @fclose($fp);
575 583
             return true;
576 584
         }
Please login to merge, or discard this patch.
framework/Collections/TList.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -34,22 +34,22 @@  discard block
 block discarded – undo
34 34
  * @package System.Collections
35 35
  * @since 3.0
36 36
  */
37
-class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countable
37
+class TList extends TComponent implements IteratorAggregate, ArrayAccess, Countable
38 38
 {
39 39
 	/**
40 40
 	 * internal data storage
41 41
 	 * @var array
42 42
 	 */
43
-	private $_d=array();
43
+	private $_d = array();
44 44
 	/**
45 45
 	 * number of items
46 46
 	 * @var integer
47 47
 	 */
48
-	private $_c=0;
48
+	private $_c = 0;
49 49
 	/**
50 50
 	 * @var boolean whether this list is read-only
51 51
 	 */
52
-	private $_r=false;
52
+	private $_r = false;
53 53
 
54 54
 	/**
55 55
 	 * Constructor.
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 	 * @param boolean whether the list is read-only
59 59
 	 * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator.
60 60
 	 */
61
-	public function __construct($data=null,$readOnly=false)
61
+	public function __construct($data = null, $readOnly = false)
62 62
 	{
63
-		if($data!==null)
63
+		if ($data !== null)
64 64
 			$this->copyFrom($data);
65 65
 		$this->setReadOnly($readOnly);
66 66
 	}
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	protected function setReadOnly($value)
80 80
 	{
81
-		$this->_r=TPropertyValue::ensureBoolean($value);
81
+		$this->_r = TPropertyValue::ensureBoolean($value);
82 82
 	}
83 83
 
84 84
 	/**
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	public function getIterator()
90 90
 	{
91
-		return new ArrayIterator( $this->_d );
91
+		return new ArrayIterator($this->_d);
92 92
 	}
93 93
 
94 94
 	/**
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function itemAt($index)
120 120
 	{
121
-		if($index>=0 && $index<$this->_c)
121
+		if ($index >= 0 && $index < $this->_c)
122 122
 			return $this->_d[$index];
123 123
 		else
124
-			throw new TInvalidDataValueException('list_index_invalid',$index);
124
+			throw new TInvalidDataValueException('list_index_invalid', $index);
125 125
 	}
126 126
 
127 127
 	/**
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 */
133 133
 	public function add($item)
134 134
 	{
135
-		$this->insertAt($this->_c,$item);
136
-		return $this->_c-1;
135
+		$this->insertAt($this->_c, $item);
136
+		return $this->_c - 1;
137 137
 	}
138 138
 
139 139
 	/**
@@ -145,22 +145,22 @@  discard block
 block discarded – undo
145 145
 	 * @throws TInvalidDataValueException If the index specified exceeds the bound
146 146
 	 * @throws TInvalidOperationException if the list is read-only
147 147
 	 */
148
-	public function insertAt($index,$item)
148
+	public function insertAt($index, $item)
149 149
 	{
150
-		if(!$this->_r)
150
+		if (!$this->_r)
151 151
 		{
152
-			if($index===$this->_c)
153
-				$this->_d[$this->_c++]=$item;
154
-			else if($index>=0 && $index<$this->_c)
152
+			if ($index === $this->_c)
153
+				$this->_d[$this->_c++] = $item;
154
+			else if ($index >= 0 && $index < $this->_c)
155 155
 			{
156
-				array_splice($this->_d,$index,0,array($item));
156
+				array_splice($this->_d, $index, 0, array($item));
157 157
 				$this->_c++;
158 158
 			}
159 159
 			else
160
-				throw new TInvalidDataValueException('list_index_invalid',$index);
160
+				throw new TInvalidDataValueException('list_index_invalid', $index);
161 161
 		}
162 162
 		else
163
-			throw new TInvalidOperationException('list_readonly',get_class($this));
163
+			throw new TInvalidOperationException('list_readonly', get_class($this));
164 164
 	}
165 165
 
166 166
 	/**
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
 	 */
175 175
 	public function remove($item)
176 176
 	{
177
-		if(!$this->_r)
177
+		if (!$this->_r)
178 178
 		{
179
-			if(($index=$this->indexOf($item))>=0)
179
+			if (($index = $this->indexOf($item)) >= 0)
180 180
 			{
181 181
 				$this->removeAt($index);
182 182
 				return $index;
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 				throw new TInvalidDataValueException('list_item_inexistent');
186 186
 		}
187 187
 		else
188
-			throw new TInvalidOperationException('list_readonly',get_class($this));
188
+			throw new TInvalidOperationException('list_readonly', get_class($this));
189 189
 	}
190 190
 
191 191
 	/**
@@ -197,25 +197,25 @@  discard block
 block discarded – undo
197 197
 	 */
198 198
 	public function removeAt($index)
199 199
 	{
200
-		if(!$this->_r)
200
+		if (!$this->_r)
201 201
 		{
202
-			if($index>=0 && $index<$this->_c)
202
+			if ($index >= 0 && $index < $this->_c)
203 203
 			{
204 204
 				$this->_c--;
205
-				if($index===$this->_c)
205
+				if ($index === $this->_c)
206 206
 					return array_pop($this->_d);
207 207
 				else
208 208
 				{
209
-					$item=$this->_d[$index];
210
-					array_splice($this->_d,$index,1);
209
+					$item = $this->_d[$index];
210
+					array_splice($this->_d, $index, 1);
211 211
 					return $item;
212 212
 				}
213 213
 			}
214 214
 			else
215
-				throw new TInvalidDataValueException('list_index_invalid',$index);
215
+				throw new TInvalidDataValueException('list_index_invalid', $index);
216 216
 		}
217 217
 		else
218
-			throw new TInvalidOperationException('list_readonly',get_class($this));
218
+			throw new TInvalidOperationException('list_readonly', get_class($this));
219 219
 	}
220 220
 
221 221
 	/**
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	 */
225 225
 	public function clear()
226 226
 	{
227
-		for($i=$this->_c-1;$i>=0;--$i)
227
+		for ($i = $this->_c - 1; $i >= 0; --$i)
228 228
 			$this->removeAt($i);
229 229
 	}
230 230
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	 */
235 235
 	public function contains($item)
236 236
 	{
237
-		return $this->indexOf($item)>=0;
237
+		return $this->indexOf($item) >= 0;
238 238
 	}
239 239
 
240 240
 	/**
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 	 */
244 244
 	public function indexOf($item)
245 245
 	{
246
-		if(($index=array_search($item,$this->_d,true))===false)
246
+		if (($index = array_search($item, $this->_d, true)) === false)
247 247
 			return -1;
248 248
 		else
249 249
 			return $index;
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
 	 */
261 261
 	public function insertBefore($baseitem, $item)
262 262
 	{
263
-		if(!$this->_r)
263
+		if (!$this->_r)
264 264
 		{
265
-			if(($index = $this->indexOf($baseitem)) == -1)
265
+			if (($index = $this->indexOf($baseitem)) == -1)
266 266
 				throw new TInvalidDataValueException('list_item_inexistent');
267 267
 
268 268
 			$this->insertAt($index, $item);
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 			return $index;
271 271
 		}
272 272
 		else
273
-			throw new TInvalidOperationException('list_readonly',get_class($this));
273
+			throw new TInvalidOperationException('list_readonly', get_class($this));
274 274
 	}
275 275
 
276 276
 	/**
@@ -284,9 +284,9 @@  discard block
 block discarded – undo
284 284
 	 */
285 285
 	public function insertAfter($baseitem, $item)
286 286
 	{
287
-		if(!$this->_r)
287
+		if (!$this->_r)
288 288
 		{
289
-			if(($index = $this->indexOf($baseitem)) == -1)
289
+			if (($index = $this->indexOf($baseitem)) == -1)
290 290
 				throw new TInvalidDataValueException('list_item_inexistent');
291 291
 
292 292
 			$this->insertAt($index + 1, $item);
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 			return $index + 1;
295 295
 		}
296 296
 		else
297
-			throw new TInvalidOperationException('list_readonly',get_class($this));
297
+			throw new TInvalidOperationException('list_readonly', get_class($this));
298 298
 	}
299 299
 
300 300
 	/**
@@ -313,14 +313,14 @@  discard block
 block discarded – undo
313 313
 	 */
314 314
 	public function copyFrom($data)
315 315
 	{
316
-		if(is_array($data) || ($data instanceof Traversable))
316
+		if (is_array($data) || ($data instanceof Traversable))
317 317
 		{
318
-			if($this->_c>0)
318
+			if ($this->_c > 0)
319 319
 				$this->clear();
320
-			foreach($data as $item)
320
+			foreach ($data as $item)
321 321
 				$this->add($item);
322 322
 		}
323
-		else if($data!==null)
323
+		else if ($data !== null)
324 324
 			throw new TInvalidDataTypeException('list_data_not_iterable');
325 325
 	}
326 326
 
@@ -332,12 +332,12 @@  discard block
 block discarded – undo
332 332
 	 */
333 333
 	public function mergeWith($data)
334 334
 	{
335
-		if(is_array($data) || ($data instanceof Traversable))
335
+		if (is_array($data) || ($data instanceof Traversable))
336 336
 		{
337
-			foreach($data as $item)
337
+			foreach ($data as $item)
338 338
 				$this->add($item);
339 339
 		}
340
-		else if($data!==null)
340
+		else if ($data !== null)
341 341
 			throw new TInvalidDataTypeException('list_data_not_iterable');
342 342
 	}
343 343
 
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 	 */
350 350
 	public function offsetExists($offset)
351 351
 	{
352
-		return ($offset>=0 && $offset<$this->_c);
352
+		return ($offset >= 0 && $offset < $this->_c);
353 353
 	}
354 354
 
355 355
 	/**
@@ -370,14 +370,14 @@  discard block
 block discarded – undo
370 370
 	 * @param integer the offset to set item
371 371
 	 * @param mixed the item value
372 372
 	 */
373
-	public function offsetSet($offset,$item)
373
+	public function offsetSet($offset, $item)
374 374
 	{
375
-		if($offset===null || $offset===$this->_c)
376
-			$this->insertAt($this->_c,$item);
375
+		if ($offset === null || $offset === $this->_c)
376
+			$this->insertAt($this->_c, $item);
377 377
 		else
378 378
 		{
379 379
 			$this->removeAt($offset);
380
-			$this->insertAt($offset,$item);
380
+			$this->insertAt($offset, $item);
381 381
 		}
382 382
 	}
383 383
 
Please login to merge, or discard this patch.
tests/unit/Web/THttpRequestTest.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -256,14 +256,14 @@  discard block
 block discarded – undo
256 256
     $acceptLanguages=array('fr', 'en-us','fr-fr','en');
257 257
     self::assertEquals($acceptLanguages, $request->getUserLanguages());
258 258
     */
259
-    throw new PHPUnit_Framework_IncompleteTestError();
259
+	throw new PHPUnit_Framework_IncompleteTestError();
260 260
   }
261 261
 
262 262
   public function testSetEnableCookieValidation() {
263
-    $request = new THttpRequest();
264
-    $request->init(null);
265
-    $request->setEnableCookieValidation (true);
266
-    self::assertEquals(true, $request->getEnableCookieValidation());
263
+	$request = new THttpRequest();
264
+	$request->init(null);
265
+	$request->setEnableCookieValidation (true);
266
+	self::assertEquals(true, $request->getEnableCookieValidation());
267 267
   }
268 268
 
269 269
   public function testGetCookies() {
@@ -288,25 +288,25 @@  discard block
 block discarded – undo
288 288
   }
289 289
 
290 290
   public function testGetUploadedFiles() {
291
-    $request = new THttpRequest ();
291
+	$request = new THttpRequest ();
292 292
   	$request->init (null);
293 293
   	self::assertEquals($_FILES, $request->getUploadedFiles());
294 294
   }
295 295
 
296 296
   public function testGetServerVariables() {
297
-    $request = new THttpRequest ();
297
+	$request = new THttpRequest ();
298 298
   	$request->init (null);
299 299
   	self::assertEquals($_SERVER, $request->getServerVariables());
300 300
   }
301 301
 
302 302
   public function testGetEnvironmentVariables() {
303
-    $request = new THttpRequest ();
303
+	$request = new THttpRequest ();
304 304
   	$request->init (null);
305 305
   	self::assertEquals($_ENV, $request->getEnvironmentVariables());
306 306
   }
307 307
 
308 308
   public function testConstructUrl() {
309
-    $request = new THttpRequest ();
309
+	$request = new THttpRequest ();
310 310
   	$request->init (null);
311 311
   	// Try to construct an url to the pageservice with some parameters
312 312
   	$url=$request->constructURL('page','Home',array('param1'=>'value1','param2'=>'value2'), true);
@@ -314,57 +314,57 @@  discard block
 block discarded – undo
314 314
   	// Try without encode &
315 315
 	$url=$request->constructURL('page','Home',array('param1'=>'value1','param2'=>'value2'), false);
316 316
 	self::assertEquals('/demos/personal/index.php?page=Home&param1=value1&param2=value2', $url);
317
-    // Try to use HTTPS even if the current request is sent via HTTP
318
-    //$url=$request->constructURL('page','Home',array('param1'=>'value1','param2'=>'value2'), false, false, true);
319
-    //self::assertEquals('https', substr($url,0,5));
317
+	// Try to use HTTPS even if the current request is sent via HTTP
318
+	//$url=$request->constructURL('page','Home',array('param1'=>'value1','param2'=>'value2'), false, false, true);
319
+	//self::assertEquals('https', substr($url,0,5));
320 320
   }
321 321
 
322 322
   public function testSetServiceID() {
323
-    $request = new THttpRequest ();
324
-    $request->setServiceId('page');
325
-    self::assertEquals('page', $request->getServiceId());
323
+	$request = new THttpRequest ();
324
+	$request->setServiceId('page');
325
+	self::assertEquals('page', $request->getServiceId());
326 326
   }
327 327
 
328 328
   public function testGetIterator() {
329
-    $request = new THttpRequest ();
330
-    $request->init(null);
331
-    self::assertInstanceOf ('ArrayIterator', $request->getIterator());
329
+	$request = new THttpRequest ();
330
+	$request->init(null);
331
+	self::assertInstanceOf ('ArrayIterator', $request->getIterator());
332 332
   }
333 333
 
334 334
   public function testGetCount() {
335
-    $request = new THttpRequest ();
336
-    $request->init(null);
337
-    // Simulate a request with just a service
335
+	$request = new THttpRequest ();
336
+	$request->init(null);
337
+	// Simulate a request with just a service
338 338
 	$_GET['page']='Home';
339
-    $request->resolveRequest(array('page'));
340
-    // Should return 1 (service param, and no get param)
339
+	$request->resolveRequest(array('page'));
340
+	// Should return 1 (service param, and no get param)
341 341
 	self::assertEquals(1, $request->getCount());
342 342
 	self::assertEquals(1, $request->count());
343 343
 
344 344
   }
345 345
 
346 346
   public function testGetKeys() {
347
-    $request = new THttpRequest ();
348
-    $request->init(null);
349
-    // Simulate a request with just a service
347
+	$request = new THttpRequest ();
348
+	$request->init(null);
349
+	// Simulate a request with just a service
350 350
 	$_GET['page']='Home';
351
-    $request->resolveRequest(array('page'));
351
+	$request->resolveRequest(array('page'));
352 352
 	self::assertEquals(array('page'), $request->getKeys());
353 353
   }
354 354
 
355 355
   public function testItemAt() {
356
-    $request = new THttpRequest ();
357
-    $request->init(null);
358
-    // Simulate a request with just a service
356
+	$request = new THttpRequest ();
357
+	$request->init(null);
358
+	// Simulate a request with just a service
359 359
 	$_GET['page']='Home';
360
-    $request->resolveRequest(array('page'));
360
+	$request->resolveRequest(array('page'));
361 361
 	self::assertEquals('Home', $request->itemAt('page'));
362 362
   }
363 363
 
364 364
   public function testAdd() {
365
-    $request = new THttpRequest ();
366
-    $request->init(null);
367
-    // Simulate a request with just a service
365
+	$request = new THttpRequest ();
366
+	$request->init(null);
367
+	// Simulate a request with just a service
368 368
 	$_GET['page']='Home';
369 369
 	$request->resolveRequest(array('page'));
370 370
 	$request->Add('param1','value1');
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
   }
373 373
 
374 374
   public function testRemove() {
375
-    $request = new THttpRequest ();
376
-    $request->init(null);
377
-    // Simulate a request with just a service
375
+	$request = new THttpRequest ();
376
+	$request->init(null);
377
+	// Simulate a request with just a service
378 378
 	$_GET['page']='Home';
379 379
 	$request->resolveRequest(array('page'));
380 380
 	// Remove an unknow key
@@ -384,9 +384,9 @@  discard block
 block discarded – undo
384 384
   }
385 385
 
386 386
   public function testContains() {
387
-    $request = new THttpRequest ();
388
-    $request->init(null);
389
-    // Simulate a request with just a service
387
+	$request = new THttpRequest ();
388
+	$request->init(null);
389
+	// Simulate a request with just a service
390 390
 	$_GET['page']='Home';
391 391
 	$request->resolveRequest(array('page'));
392 392
 	self::assertTrue($request->contains('page'));
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
 
396 396
   public function testClear() {
397 397
   	$request = new THttpRequest ();
398
-    $request->init(null);
399
-    // Simulate a request with just a service
398
+	$request->init(null);
399
+	// Simulate a request with just a service
400 400
 	$_GET['page']='Home';
401 401
 	$request->resolveRequest(array('page'));
402 402
 	$request->clear();
@@ -404,45 +404,45 @@  discard block
 block discarded – undo
404 404
   }
405 405
 
406 406
   public function testToArray() {
407
-    $request = new THttpRequest ();
408
-    $request->init(null);
409
-    // Simulate a request with just a service
407
+	$request = new THttpRequest ();
408
+	$request->init(null);
409
+	// Simulate a request with just a service
410 410
 	$_GET['page']='Home';
411 411
 	$request->resolveRequest(array('page'));
412 412
 	self::assertEquals(array ('page'=>'Home'), $request->toArray());
413 413
   }
414 414
 
415 415
   public function testOffsetExists() {
416
-    $request = new THttpRequest ();
417
-    $request->init (null);
418
-    // should not exists
419
-    self::assertFalse($request->offsetExists(0));
416
+	$request = new THttpRequest ();
417
+	$request->init (null);
418
+	// should not exists
419
+	self::assertFalse($request->offsetExists(0));
420 420
   }
421 421
 
422 422
   public function testOffsetGet() {
423
-    $request = new THttpRequest ();
424
-    $request->init (null);
425
-    // should not exists
426
-    self::assertNull($request->offsetGet(0));
423
+	$request = new THttpRequest ();
424
+	$request->init (null);
425
+	// should not exists
426
+	self::assertNull($request->offsetGet(0));
427 427
   }
428 428
 
429 429
   public function testOffsetSet() {
430
-    $request = new THttpRequest ();
431
-    $request->init (null);
432
-    $request->offsetSet(0, 'test');
433
-    // should not exists
434
-    self::assertEquals('test',$request->offsetGet(0));
430
+	$request = new THttpRequest ();
431
+	$request->init (null);
432
+	$request->offsetSet(0, 'test');
433
+	// should not exists
434
+	self::assertEquals('test',$request->offsetGet(0));
435 435
   }
436 436
 
437 437
   public function testOffsetUnset() {
438
-    $request = new THttpRequest ();
439
-    $request->init (null);
440
-    $request->offsetSet(0, 'test');
441
-    // Count should be 1
442
-    self::assertEquals (1, $request->count());
443
-    $request->offsetUnset(0);
444
-    // Now, count should be zero
445
-    self::assertEquals (0, $request->count());
438
+	$request = new THttpRequest ();
439
+	$request->init (null);
440
+	$request->offsetSet(0, 'test');
441
+	// Count should be 1
442
+	self::assertEquals (1, $request->count());
443
+	$request->offsetUnset(0);
444
+	// Now, count should be zero
445
+	self::assertEquals (0, $request->count());
446 446
   }
447 447
 
448 448
   public function testGetSetID() {
Please login to merge, or discard this patch.
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
 		$_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip,deflate';
33 33
 		$_SERVER['HTTP_ACCEPT_CHARSET'] = 'ISO-8859-1,utf-8;q=0.7,*;q=0.7';
34 34
 
35
-		$_COOKIE['phpsessid']='0123456789abcdef';
35
+		$_COOKIE['phpsessid'] = '0123456789abcdef';
36 36
 
37
-		$_FILES['userfile']=array ('name' => 'test.jpg','type' => 'image/jpg', 'size' => 10240, 'tmp_name' => 'tmpXXAZECZ', 'error'=>0);
38
-		if(self::$app === null) {
39
-			self::$app = new TApplication(dirname(__FILE__).'/app');
37
+		$_FILES['userfile'] = array('name' => 'test.jpg', 'type' => 'image/jpg', 'size' => 10240, 'tmp_name' => 'tmpXXAZECZ', 'error'=>0);
38
+		if (self::$app === null) {
39
+			self::$app = new TApplication(dirname(__FILE__) . '/app');
40 40
 		}
41 41
 	}
42 42
 
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 		$request->init(null);
65 65
 		self::assertInstanceOf('TUri', $request->getUrl());
66 66
 		// Try with $_SERVER['HTTP_HOST'] empty
67
-		$request=null;
67
+		$request = null;
68 68
 		$request = new THttpRequest();
69 69
 		$request->init(null);
70
-		$_SERVER['HTTP_HOST']='';
70
+		$_SERVER['HTTP_HOST'] = '';
71 71
 		self::assertInstanceOf('TUri', $request->getUrl());
72 72
 	}
73 73
 
@@ -84,35 +84,35 @@  discard block
 block discarded – undo
84 84
 		try {
85 85
 			$request->init(null);
86 86
 			$request->getUrlManagerModule();
87
-			self::fail ('httprequest_urlmanager_inexist exception not thrown');
87
+			self::fail('httprequest_urlmanager_inexist exception not thrown');
88 88
 		} catch (TConfigurationException $e) {
89 89
 
90 90
 		}
91
-		$request=null;
91
+		$request = null;
92 92
 
93 93
 
94 94
 		// Try with valid module id, but not instance of TUrlManager
95
-		$module=new TAssetManager();
96
-		self::$app->setModule('badmanager',$module);
95
+		$module = new TAssetManager();
96
+		self::$app->setModule('badmanager', $module);
97 97
 		$request = new THttpRequest();
98 98
 		$request->setUrlManager('badmanager');
99 99
 		try {
100 100
 			$request->init(null);
101 101
 			$request->getUrlManagerModule();
102
-			self::fail ('httprequest_urlmanager_invalid exception not thrown');
102
+			self::fail('httprequest_urlmanager_invalid exception not thrown');
103 103
 		} catch (TConfigurationException $e) {
104 104
 
105 105
 		}
106
-		$request=null;
106
+		$request = null;
107 107
 
108 108
 		// Finally, try with a valid manager
109
-		$module=new TUrlManager ();
110
-		self::$app->setModule('goodmanager',$module);
109
+		$module = new TUrlManager();
110
+		self::$app->setModule('goodmanager', $module);
111 111
 		$request = new THttpRequest();
112 112
 		$request->setUrlManager('goodmanager');
113 113
 		$request->init(null);
114
-		self::assertEquals ('goodmanager', $request->getUrlManager());
115
-		self::assertInstanceOf ('TUrlManager',$request->getUrlManagerModule());
114
+		self::assertEquals('goodmanager', $request->getUrlManager());
115
+		self::assertInstanceOf('TUrlManager', $request->getUrlManagerModule());
116 116
 
117 117
 	}
118 118
 
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 		$request->setUrlFormat('Path');
122 122
 		self::assertEquals('Path', $request->getUrlFormat());
123 123
 		// Test invalid
124
-		try  {
124
+		try {
125 125
 			$request->setUrlFormat('Bad');
126
-			self::fail ('Bad Value exception not thrown');
126
+			self::fail('Bad Value exception not thrown');
127 127
 		} catch (TInvalidDataValueException $e) {}
128 128
 	}
129 129
 
@@ -262,57 +262,57 @@  discard block
 block discarded – undo
262 262
   public function testSetEnableCookieValidation() {
263 263
     $request = new THttpRequest();
264 264
     $request->init(null);
265
-    $request->setEnableCookieValidation (true);
265
+    $request->setEnableCookieValidation(true);
266 266
     self::assertEquals(true, $request->getEnableCookieValidation());
267 267
   }
268 268
 
269 269
   public function testGetCookies() {
270
-  	$request = new THttpRequest ();
271
-  	$request->init (null);
272
-  	$request->setEnableCookieValidation (false);
273
-  	$cookies=$request->getCookies();
270
+  	$request = new THttpRequest();
271
+  	$request->init(null);
272
+  	$request->setEnableCookieValidation(false);
273
+  	$cookies = $request->getCookies();
274 274
   	self::assertInstanceOf('THttpCookieCollection', $cookies);
275 275
   	self::assertEquals('0123456789abcdef', $cookies->itemAt('phpsessid')->getValue());
276 276
   	$request = null;
277 277
 
278 278
   	// Test with cookie validation
279
-	$security=new TSecurityManager();
280
-	self::$app->setModule ('security', $security);
281
-	$_COOKIE['phpsessid']=$security->hashData('0123456789abcdef');
282
-	$request = new THttpRequest ();
283
-  	$request->init (null);
284
-  	$request->setEnableCookieValidation (true);
285
-  	$cookies=$request->getCookies();
279
+	$security = new TSecurityManager();
280
+	self::$app->setModule('security', $security);
281
+	$_COOKIE['phpsessid'] = $security->hashData('0123456789abcdef');
282
+	$request = new THttpRequest();
283
+  	$request->init(null);
284
+  	$request->setEnableCookieValidation(true);
285
+  	$cookies = $request->getCookies();
286 286
   	self::assertInstanceOf('THttpCookieCollection', $cookies);
287 287
   	self::assertEquals('0123456789abcdef', $cookies->itemAt('phpsessid')->getValue());
288 288
   }
289 289
 
290 290
   public function testGetUploadedFiles() {
291
-    $request = new THttpRequest ();
292
-  	$request->init (null);
291
+    $request = new THttpRequest();
292
+  	$request->init(null);
293 293
   	self::assertEquals($_FILES, $request->getUploadedFiles());
294 294
   }
295 295
 
296 296
   public function testGetServerVariables() {
297
-    $request = new THttpRequest ();
298
-  	$request->init (null);
297
+    $request = new THttpRequest();
298
+  	$request->init(null);
299 299
   	self::assertEquals($_SERVER, $request->getServerVariables());
300 300
   }
301 301
 
302 302
   public function testGetEnvironmentVariables() {
303
-    $request = new THttpRequest ();
304
-  	$request->init (null);
303
+    $request = new THttpRequest();
304
+  	$request->init(null);
305 305
   	self::assertEquals($_ENV, $request->getEnvironmentVariables());
306 306
   }
307 307
 
308 308
   public function testConstructUrl() {
309
-    $request = new THttpRequest ();
310
-  	$request->init (null);
309
+    $request = new THttpRequest();
310
+  	$request->init(null);
311 311
   	// Try to construct an url to the pageservice with some parameters
312
-  	$url=$request->constructURL('page','Home',array('param1'=>'value1','param2'=>'value2'), true);
312
+  	$url = $request->constructURL('page', 'Home', array('param1'=>'value1', 'param2'=>'value2'), true);
313 313
   	self::assertEquals('/demos/personal/index.php?page=Home&amp;param1=value1&amp;param2=value2', $url);
314 314
   	// Try without encode &
315
-	$url=$request->constructURL('page','Home',array('param1'=>'value1','param2'=>'value2'), false);
315
+	$url = $request->constructURL('page', 'Home', array('param1'=>'value1', 'param2'=>'value2'), false);
316 316
 	self::assertEquals('/demos/personal/index.php?page=Home&param1=value1&param2=value2', $url);
317 317
     // Try to use HTTPS even if the current request is sent via HTTP
318 318
     //$url=$request->constructURL('page','Home',array('param1'=>'value1','param2'=>'value2'), false, false, true);
@@ -320,22 +320,22 @@  discard block
 block discarded – undo
320 320
   }
321 321
 
322 322
   public function testSetServiceID() {
323
-    $request = new THttpRequest ();
323
+    $request = new THttpRequest();
324 324
     $request->setServiceId('page');
325 325
     self::assertEquals('page', $request->getServiceId());
326 326
   }
327 327
 
328 328
   public function testGetIterator() {
329
-    $request = new THttpRequest ();
329
+    $request = new THttpRequest();
330 330
     $request->init(null);
331
-    self::assertInstanceOf ('ArrayIterator', $request->getIterator());
331
+    self::assertInstanceOf('ArrayIterator', $request->getIterator());
332 332
   }
333 333
 
334 334
   public function testGetCount() {
335
-    $request = new THttpRequest ();
335
+    $request = new THttpRequest();
336 336
     $request->init(null);
337 337
     // Simulate a request with just a service
338
-	$_GET['page']='Home';
338
+	$_GET['page'] = 'Home';
339 339
     $request->resolveRequest(array('page'));
340 340
     // Should return 1 (service param, and no get param)
341 341
 	self::assertEquals(1, $request->getCount());
@@ -344,116 +344,116 @@  discard block
 block discarded – undo
344 344
   }
345 345
 
346 346
   public function testGetKeys() {
347
-    $request = new THttpRequest ();
347
+    $request = new THttpRequest();
348 348
     $request->init(null);
349 349
     // Simulate a request with just a service
350
-	$_GET['page']='Home';
350
+	$_GET['page'] = 'Home';
351 351
     $request->resolveRequest(array('page'));
352 352
 	self::assertEquals(array('page'), $request->getKeys());
353 353
   }
354 354
 
355 355
   public function testItemAt() {
356
-    $request = new THttpRequest ();
356
+    $request = new THttpRequest();
357 357
     $request->init(null);
358 358
     // Simulate a request with just a service
359
-	$_GET['page']='Home';
359
+	$_GET['page'] = 'Home';
360 360
     $request->resolveRequest(array('page'));
361 361
 	self::assertEquals('Home', $request->itemAt('page'));
362 362
   }
363 363
 
364 364
   public function testAdd() {
365
-    $request = new THttpRequest ();
365
+    $request = new THttpRequest();
366 366
     $request->init(null);
367 367
     // Simulate a request with just a service
368
-	$_GET['page']='Home';
368
+	$_GET['page'] = 'Home';
369 369
 	$request->resolveRequest(array('page'));
370
-	$request->Add('param1','value1');
370
+	$request->Add('param1', 'value1');
371 371
 	self::assertEquals('value1', $request->itemAt('param1'));
372 372
   }
373 373
 
374 374
   public function testRemove() {
375
-    $request = new THttpRequest ();
375
+    $request = new THttpRequest();
376 376
     $request->init(null);
377 377
     // Simulate a request with just a service
378
-	$_GET['page']='Home';
378
+	$_GET['page'] = 'Home';
379 379
 	$request->resolveRequest(array('page'));
380 380
 	// Remove an unknow key
381
-	self::assertNull($request->remove('param1','value1'));
381
+	self::assertNull($request->remove('param1', 'value1'));
382 382
 	// Remove a key
383 383
 	self::assertEquals('Home', $request->remove('page'));
384 384
   }
385 385
 
386 386
   public function testContains() {
387
-    $request = new THttpRequest ();
387
+    $request = new THttpRequest();
388 388
     $request->init(null);
389 389
     // Simulate a request with just a service
390
-	$_GET['page']='Home';
390
+	$_GET['page'] = 'Home';
391 391
 	$request->resolveRequest(array('page'));
392 392
 	self::assertTrue($request->contains('page'));
393 393
 	self::assertFalse($request->contains('param'));
394 394
   }
395 395
 
396 396
   public function testClear() {
397
-  	$request = new THttpRequest ();
397
+  	$request = new THttpRequest();
398 398
     $request->init(null);
399 399
     // Simulate a request with just a service
400
-	$_GET['page']='Home';
400
+	$_GET['page'] = 'Home';
401 401
 	$request->resolveRequest(array('page'));
402 402
 	$request->clear();
403
-	self::assertEquals(0,$request->getCount());
403
+	self::assertEquals(0, $request->getCount());
404 404
   }
405 405
 
406 406
   public function testToArray() {
407
-    $request = new THttpRequest ();
407
+    $request = new THttpRequest();
408 408
     $request->init(null);
409 409
     // Simulate a request with just a service
410
-	$_GET['page']='Home';
410
+	$_GET['page'] = 'Home';
411 411
 	$request->resolveRequest(array('page'));
412
-	self::assertEquals(array ('page'=>'Home'), $request->toArray());
412
+	self::assertEquals(array('page'=>'Home'), $request->toArray());
413 413
   }
414 414
 
415 415
   public function testOffsetExists() {
416
-    $request = new THttpRequest ();
417
-    $request->init (null);
416
+    $request = new THttpRequest();
417
+    $request->init(null);
418 418
     // should not exists
419 419
     self::assertFalse($request->offsetExists(0));
420 420
   }
421 421
 
422 422
   public function testOffsetGet() {
423
-    $request = new THttpRequest ();
424
-    $request->init (null);
423
+    $request = new THttpRequest();
424
+    $request->init(null);
425 425
     // should not exists
426 426
     self::assertNull($request->offsetGet(0));
427 427
   }
428 428
 
429 429
   public function testOffsetSet() {
430
-    $request = new THttpRequest ();
431
-    $request->init (null);
430
+    $request = new THttpRequest();
431
+    $request->init(null);
432 432
     $request->offsetSet(0, 'test');
433 433
     // should not exists
434
-    self::assertEquals('test',$request->offsetGet(0));
434
+    self::assertEquals('test', $request->offsetGet(0));
435 435
   }
436 436
 
437 437
   public function testOffsetUnset() {
438
-    $request = new THttpRequest ();
439
-    $request->init (null);
438
+    $request = new THttpRequest();
439
+    $request->init(null);
440 440
     $request->offsetSet(0, 'test');
441 441
     // Count should be 1
442
-    self::assertEquals (1, $request->count());
442
+    self::assertEquals(1, $request->count());
443 443
     $request->offsetUnset(0);
444 444
     // Now, count should be zero
445
-    self::assertEquals (0, $request->count());
445
+    self::assertEquals(0, $request->count());
446 446
   }
447 447
 
448 448
   public function testGetSetID() {
449
-  	$request=new THttpRequest();
449
+  	$request = new THttpRequest();
450 450
   	$request->init(null);
451 451
   	$request->setID('testId');
452 452
   	self::assertEquals('testId', $request->getID());
453 453
   }
454 454
 
455 455
   public function testGetSetUrlParamSeparator() {
456
-  	$request=new THttpRequest();
456
+  	$request = new THttpRequest();
457 457
   	$request->init(null);
458 458
   	// Try an invalid separator
459 459
 	try {
@@ -467,29 +467,29 @@  discard block
 block discarded – undo
467 467
   }
468 468
 
469 469
   public function testGetServiceParameter() {
470
-  	$request=new THttpRequest();
470
+  	$request = new THttpRequest();
471 471
   	$request->init(null);
472
-  	$_GET['page']='Home';
472
+  	$_GET['page'] = 'Home';
473 473
 	$request->resolveRequest(array('page'));
474 474
 	self::assertEquals('Home', $request->getServiceParameter());
475 475
   }
476 476
 
477 477
   public function testGetRequestResolved() {
478
-  	$request=new THttpRequest();
478
+  	$request = new THttpRequest();
479 479
   	$request->init(null);
480 480
   	self::assertFalse($request->getRequestResolved());
481
-  	$_GET['page']='Home';
481
+  	$_GET['page'] = 'Home';
482 482
 	$request->resolveRequest(array('page'));
483 483
 	self::assertTrue($request->getRequestResolved());
484 484
   }
485 485
 
486
-  public function testRequestWithUrlMapping () {
487
-  	Prado::Using ('System.Web.TUrlMapping');
488
-  	$confstr='<config><url ServiceId="testService" ServiceParameter="testServiceParam" pattern="test/{param}/?" parameters.param="\w+"/></config>';
489
-	$config=new TXmlDocument('1.0','utf8');
486
+  public function testRequestWithUrlMapping() {
487
+  	Prado::Using('System.Web.TUrlMapping');
488
+  	$confstr = '<config><url ServiceId="testService" ServiceParameter="testServiceParam" pattern="test/{param}/?" parameters.param="\w+"/></config>';
489
+	$config = new TXmlDocument('1.0', 'utf8');
490 490
 	$config->loadFromString($confstr);
491
-  	$module=new TUrlMapping ();
492
-	self::$app->setModule('friendly-url',$module);
491
+  	$module = new TUrlMapping();
492
+	self::$app->setModule('friendly-url', $module);
493 493
 	if (isset ($_GET['page'])) unset ($_GET['page']); // Remove service from a previous test !
494 494
 	$_SERVER['REQUEST_URI'] = '/index.php/test/value2';
495 495
 	$_SERVER['SCRIPT_NAME'] = '/index.php';
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 	$request->setUrlManager('friendly-url');
501 501
 	$request->setUrlFormat(THttpRequestUrlFormat::Path);
502 502
 	$request->init(null);
503
-	$module->init ($config);
504
-	self::assertEquals('testService', $request->resolveRequest(array ('page', 'testService')));
503
+	$module->init($config);
504
+	self::assertEquals('testService', $request->resolveRequest(array('page', 'testService')));
505 505
   }
506 506
 }
507 507
\ No newline at end of file
Please login to merge, or discard this patch.