Skip to content
This repository
Browse code

make it possible to override all of basics.php

  • Loading branch information...
commit 99b798fa9a49c876721a9b6d60178f9c7e991f0c 1 parent 6664acb
Andy Dawson authored September 05, 2012

Showing 1 changed file with 430 additions and 350 deletions. Show diff stats Hide diff stats

  1. 780  lib/Cake/basics.php
780  lib/Cake/basics.php
@@ -30,6 +30,8 @@
30 30
 	define('MONTH', 2592000);
31 31
 	define('YEAR', 31536000);
32 32
 
  33
+if (!function_exists('config')) {
  34
+
33 35
 /**
34 36
  * Loads configuration files. Receives a set of configuration files
35 37
  * to load.
@@ -40,24 +42,28 @@
40 42
  * @return boolean Success
41 43
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#config
42 44
  */
43  
-function config() {
44  
-	$args = func_get_args();
45  
-	foreach ($args as $arg) {
46  
-		if (file_exists(APP . 'Config' . DS . $arg . '.php')) {
47  
-			include_once APP . 'Config' . DS . $arg . '.php';
48  
-
49  
-			if (count($args) == 1) {
50  
-				return true;
51  
-			}
52  
-		} else {
53  
-			if (count($args) == 1) {
54  
-				return false;
  45
+	function config() {
  46
+		$args = func_get_args();
  47
+		foreach ($args as $arg) {
  48
+			if (file_exists(APP . 'Config' . DS . $arg . '.php')) {
  49
+				include_once APP . 'Config' . DS . $arg . '.php';
  50
+
  51
+				if (count($args) == 1) {
  52
+					return true;
  53
+				}
  54
+			} else {
  55
+				if (count($args) == 1) {
  56
+					return false;
  57
+				}
55 58
 			}
56 59
 		}
  60
+		return true;
57 61
 	}
58  
-	return true;
  62
+
59 63
 }
60 64
 
  65
+if (!function_exists('debug')) {
  66
+
61 67
 /**
62 68
  * Prints out debug information about given variable.
63 69
  *
@@ -69,18 +75,18 @@ function config() {
69 75
  * @link http://book.cakephp.org/2.0/en/development/debugging.html#basic-debugging
70 76
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#debug
71 77
  */
72  
-function debug($var = false, $showHtml = null, $showFrom = true) {
73  
-	if (Configure::read('debug') > 0) {
74  
-		App::uses('Debugger', 'Utility');
75  
-		$file = '';
76  
-		$line = '';
77  
-		$lineInfo = '';
78  
-		if ($showFrom) {
79  
-			$trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
80  
-			$file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
81  
-			$line = $trace[0]['line'];
82  
-		}
83  
-		$html = <<<HTML
  78
+	function debug($var = false, $showHtml = null, $showFrom = true) {
  79
+		if (Configure::read('debug') > 0) {
  80
+			App::uses('Debugger', 'Utility');
  81
+			$file = '';
  82
+			$line = '';
  83
+			$lineInfo = '';
  84
+			if ($showFrom) {
  85
+				$trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
  86
+				$file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
  87
+				$line = $trace[0]['line'];
  88
+			}
  89
+			$html = <<<HTML
84 90
 <div class="cake-debug-output">
85 91
 %s
86 92
 <pre class="cake-debug">
@@ -88,32 +94,34 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
88 94
 </pre>
89 95
 </div>
90 96
 HTML;
91  
-		$text = <<<TEXT
  97
+			$text = <<<TEXT
92 98
 %s
93 99
 ########## DEBUG ##########
94 100
 %s
95 101
 ###########################
96 102
 TEXT;
97  
-		$template = $html;
98  
-		if (php_sapi_name() == 'cli' || $showHtml === false) {
99  
-			$template = $text;
100  
-			if ($showFrom) {
101  
-				$lineInfo = sprintf('%s (line %s)', $file, $line);
102  
-			}
103  
-		}
104  
-		if ($showHtml === null && $template !== $text) {
105  
-			$showHtml = true;
106  
-		}
107  
-		$var = Debugger::exportVar($var, 25);
108  
-		if ($showHtml) {
109 103
 			$template = $html;
110  
-			$var = h($var);
111  
-			if ($showFrom) {
112  
-				$lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
  104
+			if (php_sapi_name() == 'cli' || $showHtml === false) {
  105
+				$template = $text;
  106
+				if ($showFrom) {
  107
+					$lineInfo = sprintf('%s (line %s)', $file, $line);
  108
+				}
  109
+			}
  110
+			if ($showHtml === null && $template !== $text) {
  111
+				$showHtml = true;
113 112
 			}
  113
+			$var = Debugger::exportVar($var, 25);
  114
+			if ($showHtml) {
  115
+				$template = $html;
  116
+				$var = h($var);
  117
+				if ($showFrom) {
  118
+					$lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
  119
+				}
  120
+			}
  121
+			printf($template, $lineInfo, $var);
114 122
 		}
115  
-		printf($template, $lineInfo, $var);
116 123
 	}
  124
+
117 125
 }
118 126
 
119 127
 if (!function_exists('sortByKey')) {
@@ -151,6 +159,8 @@ function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
151 159
 
152 160
 }
153 161
 
  162
+if (!function_exists('h')) {
  163
+
154 164
 /**
155 165
  * Convenience method for htmlspecialchars.
156 166
  *
@@ -162,36 +172,40 @@ function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
162 172
  * @return string Wrapped text
163 173
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#h
164 174
  */
165  
-function h($text, $double = true, $charset = null) {
166  
-	if (is_array($text)) {
167  
-		$texts = array();
168  
-		foreach ($text as $k => $t) {
169  
-			$texts[$k] = h($t, $double, $charset);
170  
-		}
171  
-		return $texts;
172  
-	} elseif (is_object($text)) {
173  
-		if (method_exists($text, '__toString')) {
174  
-			$text = (string)$text;
175  
-		} else {
176  
-			$text = '(object)' . get_class($text);
  175
+	function h($text, $double = true, $charset = null) {
  176
+		if (is_array($text)) {
  177
+			$texts = array();
  178
+			foreach ($text as $k => $t) {
  179
+				$texts[$k] = h($t, $double, $charset);
  180
+			}
  181
+			return $texts;
  182
+		} elseif (is_object($text)) {
  183
+			if (method_exists($text, '__toString')) {
  184
+				$text = (string)$text;
  185
+			} else {
  186
+				$text = '(object)' . get_class($text);
  187
+			}
  188
+		} elseif (is_bool($text)) {
  189
+			return $text;
177 190
 		}
178  
-	} elseif (is_bool($text)) {
179  
-		return $text;
180  
-	}
181 191
 
182  
-	static $defaultCharset = false;
183  
-	if ($defaultCharset === false) {
184  
-		$defaultCharset = Configure::read('App.encoding');
185  
-		if ($defaultCharset === null) {
186  
-			$defaultCharset = 'UTF-8';
  192
+		static $defaultCharset = false;
  193
+		if ($defaultCharset === false) {
  194
+			$defaultCharset = Configure::read('App.encoding');
  195
+			if ($defaultCharset === null) {
  196
+				$defaultCharset = 'UTF-8';
  197
+			}
187 198
 		}
  199
+		if (is_string($double)) {
  200
+			$charset = $double;
  201
+		}
  202
+		return htmlspecialchars($text, ENT_QUOTES, ($charset) ? $charset : $defaultCharset, $double);
188 203
 	}
189  
-	if (is_string($double)) {
190  
-		$charset = $double;
191  
-	}
192  
-	return htmlspecialchars($text, ENT_QUOTES, ($charset) ? $charset : $defaultCharset, $double);
  204
+
193 205
 }
194 206
 
  207
+if (!function_exists('pluginSplit')) {
  208
+
195 209
 /**
196 210
  * Splits a dot syntax plugin name into its plugin and classname.
197 211
  * If $name does not have a dot, then index 0 will be null.
@@ -204,17 +218,21 @@ function h($text, $double = true, $charset = null) {
204 218
  * @return array Array with 2 indexes.  0 => plugin name, 1 => classname
205 219
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#pluginSplit
206 220
  */
207  
-function pluginSplit($name, $dotAppend = false, $plugin = null) {
208  
-	if (strpos($name, '.') !== false) {
209  
-		$parts = explode('.', $name, 2);
210  
-		if ($dotAppend) {
211  
-			$parts[0] .= '.';
  221
+	function pluginSplit($name, $dotAppend = false, $plugin = null) {
  222
+		if (strpos($name, '.') !== false) {
  223
+			$parts = explode('.', $name, 2);
  224
+			if ($dotAppend) {
  225
+				$parts[0] .= '.';
  226
+			}
  227
+			return $parts;
212 228
 		}
213  
-		return $parts;
  229
+		return array($plugin, $name);
214 230
 	}
215  
-	return array($plugin, $name);
  231
+
216 232
 }
217 233
 
  234
+if (!function_exists('pr')) {
  235
+
218 236
 /**
219 237
  * Print_r convenience function, which prints out <PRE> tags around
220 238
  * the output of given array. Similar to debug().
@@ -223,14 +241,18 @@ function pluginSplit($name, $dotAppend = false, $plugin = null) {
223 241
  * @param array $var Variable to print out
224 242
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#pr
225 243
  */
226  
-function pr($var) {
227  
-	if (Configure::read('debug') > 0) {
228  
-		echo '<pre>';
229  
-		print_r($var);
230  
-		echo '</pre>';
  244
+	function pr($var) {
  245
+		if (Configure::read('debug') > 0) {
  246
+			echo '<pre>';
  247
+			print_r($var);
  248
+			echo '</pre>';
  249
+		}
231 250
 	}
  251
+
232 252
 }
233 253
 
  254
+if (!function_exists('am')) {
  255
+
234 256
 /**
235 257
  * Merge a group of arrays
236 258
  *
@@ -241,18 +263,22 @@ function pr($var) {
241 263
  * @return array All array parameters merged into one
242 264
  * @link http://book.cakephp.org/2.0/en/development/debugging.html#am
243 265
  */
244  
-function am() {
245  
-	$r = array();
246  
-	$args = func_get_args();
247  
-	foreach ($args as $a) {
248  
-		if (!is_array($a)) {
249  
-			$a = array($a);
250  
-		}
251  
-		$r = array_merge($r, $a);
  266
+	function am() {
  267
+		$r = array();
  268
+		$args = func_get_args();
  269
+		foreach ($args as $a) {
  270
+			if (!is_array($a)) {
  271
+				$a = array($a);
  272
+			}
  273
+			$r = array_merge($r, $a);
  274
+		}
  275
+		return $r;
252 276
 	}
253  
-	return $r;
  277
+
254 278
 }
255 279
 
  280
+if (!function_exists('env')) {
  281
+
256 282
 /**
257 283
  * Gets an environment variable from available sources, and provides emulation
258 284
  * for unsupported or inconsistent environment variables (i.e. DOCUMENT_ROOT on
@@ -263,105 +289,109 @@ function am() {
263 289
  * @return string Environment variable setting.
264 290
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#env
265 291
  */
266  
-function env($key) {
267  
-	if ($key === 'HTTPS') {
268  
-		if (isset($_SERVER['HTTPS'])) {
269  
-			return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
  292
+	function env($key) {
  293
+		if ($key === 'HTTPS') {
  294
+			if (isset($_SERVER['HTTPS'])) {
  295
+				return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
  296
+			}
  297
+			return (strpos(env('SCRIPT_URI'), 'https://') === 0);
270 298
 		}
271  
-		return (strpos(env('SCRIPT_URI'), 'https://') === 0);
272  
-	}
273 299
 
274  
-	if ($key === 'SCRIPT_NAME') {
275  
-		if (env('CGI_MODE') && isset($_ENV['SCRIPT_URL'])) {
276  
-			$key = 'SCRIPT_URL';
  300
+		if ($key === 'SCRIPT_NAME') {
  301
+			if (env('CGI_MODE') && isset($_ENV['SCRIPT_URL'])) {
  302
+				$key = 'SCRIPT_URL';
  303
+			}
277 304
 		}
278  
-	}
279 305
 
280  
-	$val = null;
281  
-	if (isset($_SERVER[$key])) {
282  
-		$val = $_SERVER[$key];
283  
-	} elseif (isset($_ENV[$key])) {
284  
-		$val = $_ENV[$key];
285  
-	} elseif (getenv($key) !== false) {
286  
-		$val = getenv($key);
287  
-	}
  306
+		$val = null;
  307
+		if (isset($_SERVER[$key])) {
  308
+			$val = $_SERVER[$key];
  309
+		} elseif (isset($_ENV[$key])) {
  310
+			$val = $_ENV[$key];
  311
+		} elseif (getenv($key) !== false) {
  312
+			$val = getenv($key);
  313
+		}
288 314
 
289  
-	if ($key === 'REMOTE_ADDR' && $val === env('SERVER_ADDR')) {
290  
-		$addr = env('HTTP_PC_REMOTE_ADDR');
291  
-		if ($addr !== null) {
292  
-			$val = $addr;
  315
+		if ($key === 'REMOTE_ADDR' && $val === env('SERVER_ADDR')) {
  316
+			$addr = env('HTTP_PC_REMOTE_ADDR');
  317
+			if ($addr !== null) {
  318
+				$val = $addr;
  319
+			}
293 320
 		}
294  
-	}
295 321
 
296  
-	if ($val !== null) {
297  
-		return $val;
298  
-	}
  322
+		if ($val !== null) {
  323
+			return $val;
  324
+		}
299 325
 
300  
-	switch ($key) {
301  
-		case 'SCRIPT_FILENAME':
302  
-			if (defined('SERVER_IIS') && SERVER_IIS === true) {
303  
-				return str_replace('\\\\', '\\', env('PATH_TRANSLATED'));
304  
-			}
305  
-			break;
306  
-		case 'DOCUMENT_ROOT':
307  
-			$name = env('SCRIPT_NAME');
308  
-			$filename = env('SCRIPT_FILENAME');
309  
-			$offset = 0;
310  
-			if (!strpos($name, '.php')) {
311  
-				$offset = 4;
312  
-			}
313  
-			return substr($filename, 0, -(strlen($name) + $offset));
314  
-			break;
315  
-		case 'PHP_SELF':
316  
-			return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
317  
-			break;
318  
-		case 'CGI_MODE':
319  
-			return (PHP_SAPI === 'cgi');
320  
-			break;
321  
-		case 'HTTP_BASE':
322  
-			$host = env('HTTP_HOST');
323  
-			$parts = explode('.', $host);
324  
-			$count = count($parts);
325  
-
326  
-			if ($count === 1) {
327  
-				return '.' . $host;
328  
-			} elseif ($count === 2) {
329  
-				return '.' . $host;
330  
-			} elseif ($count === 3) {
331  
-				$gTLD = array(
332  
-					'aero',
333  
-					'asia',
334  
-					'biz',
335  
-					'cat',
336  
-					'com',
337  
-					'coop',
338  
-					'edu',
339  
-					'gov',
340  
-					'info',
341  
-					'int',
342  
-					'jobs',
343  
-					'mil',
344  
-					'mobi',
345  
-					'museum',
346  
-					'name',
347  
-					'net',
348  
-					'org',
349  
-					'pro',
350  
-					'tel',
351  
-					'travel',
352  
-					'xxx'
353  
-				);
354  
-				if (in_array($parts[1], $gTLD)) {
  326
+		switch ($key) {
  327
+			case 'SCRIPT_FILENAME':
  328
+				if (defined('SERVER_IIS') && SERVER_IIS === true) {
  329
+					return str_replace('\\\\', '\\', env('PATH_TRANSLATED'));
  330
+				}
  331
+				break;
  332
+			case 'DOCUMENT_ROOT':
  333
+				$name = env('SCRIPT_NAME');
  334
+				$filename = env('SCRIPT_FILENAME');
  335
+				$offset = 0;
  336
+				if (!strpos($name, '.php')) {
  337
+					$offset = 4;
  338
+				}
  339
+				return substr($filename, 0, -(strlen($name) + $offset));
  340
+				break;
  341
+			case 'PHP_SELF':
  342
+				return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
  343
+				break;
  344
+			case 'CGI_MODE':
  345
+				return (PHP_SAPI === 'cgi');
  346
+				break;
  347
+			case 'HTTP_BASE':
  348
+				$host = env('HTTP_HOST');
  349
+				$parts = explode('.', $host);
  350
+				$count = count($parts);
  351
+
  352
+				if ($count === 1) {
355 353
 					return '.' . $host;
  354
+				} elseif ($count === 2) {
  355
+					return '.' . $host;
  356
+				} elseif ($count === 3) {
  357
+					$gTLD = array(
  358
+						'aero',
  359
+						'asia',
  360
+						'biz',
  361
+						'cat',
  362
+						'com',
  363
+						'coop',
  364
+						'edu',
  365
+						'gov',
  366
+						'info',
  367
+						'int',
  368
+						'jobs',
  369
+						'mil',
  370
+						'mobi',
  371
+						'museum',
  372
+						'name',
  373
+						'net',
  374
+						'org',
  375
+						'pro',
  376
+						'tel',
  377
+						'travel',
  378
+						'xxx'
  379
+					);
  380
+					if (in_array($parts[1], $gTLD)) {
  381
+						return '.' . $host;
  382
+					}
356 383
 				}
357  
-			}
358  
-			array_shift($parts);
359  
-			return '.' . implode('.', $parts);
360  
-			break;
  384
+				array_shift($parts);
  385
+				return '.' . implode('.', $parts);
  386
+				break;
  387
+		}
  388
+		return null;
361 389
 	}
362  
-	return null;
  390
+
363 391
 }
364 392
 
  393
+if (!function_exists('cache')) {
  394
+
365 395
 /**
366 396
  * Reads/writes temporary data to cache files or session.
367 397
  *
@@ -372,48 +402,52 @@ function env($key) {
372 402
  * @return mixed  The contents of the temporary file.
373 403
  * @deprecated Please use Cache::write() instead
374 404
  */
375  
-function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
376  
-	if (Configure::read('Cache.disable')) {
377  
-		return null;
378  
-	}
379  
-	$now = time();
  405
+	function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
  406
+		if (Configure::read('Cache.disable')) {
  407
+			return null;
  408
+		}
  409
+		$now = time();
380 410
 
381  
-	if (!is_numeric($expires)) {
382  
-		$expires = strtotime($expires, $now);
383  
-	}
  411
+		if (!is_numeric($expires)) {
  412
+			$expires = strtotime($expires, $now);
  413
+		}
384 414
 
385  
-	switch (strtolower($target)) {
386  
-		case 'cache':
387  
-			$filename = CACHE . $path;
388  
-		break;
389  
-		case 'public':
390  
-			$filename = WWW_ROOT . $path;
391  
-		break;
392  
-		case 'tmp':
393  
-			$filename = TMP . $path;
394  
-		break;
395  
-	}
396  
-	$timediff = $expires - $now;
397  
-	$filetime = false;
  415
+		switch (strtolower($target)) {
  416
+			case 'cache':
  417
+				$filename = CACHE . $path;
  418
+			break;
  419
+			case 'public':
  420
+				$filename = WWW_ROOT . $path;
  421
+			break;
  422
+			case 'tmp':
  423
+				$filename = TMP . $path;
  424
+			break;
  425
+		}
  426
+		$timediff = $expires - $now;
  427
+		$filetime = false;
398 428
 
399  
-	if (file_exists($filename)) {
400  
-		$filetime = @filemtime($filename);
401  
-	}
  429
+		if (file_exists($filename)) {
  430
+			$filetime = @filemtime($filename);
  431
+		}
402 432
 
403  
-	if ($data === null) {
404  
-		if (file_exists($filename) && $filetime !== false) {
405  
-			if ($filetime + $timediff < $now) {
406  
-				@unlink($filename);
407  
-			} else {
408  
-				$data = @file_get_contents($filename);
  433
+		if ($data === null) {
  434
+			if (file_exists($filename) && $filetime !== false) {
  435
+				if ($filetime + $timediff < $now) {
  436
+					@unlink($filename);
  437
+				} else {
  438
+					$data = @file_get_contents($filename);
  439
+				}
409 440
 			}
  441
+		} elseif (is_writable(dirname($filename))) {
  442
+			@file_put_contents($filename, $data, LOCK_EX);
410 443
 		}
411  
-	} elseif (is_writable(dirname($filename))) {
412  
-		@file_put_contents($filename, $data, LOCK_EX);
  444
+		return $data;
413 445
 	}
414  
-	return $data;
  446
+
415 447
 }
416 448
 
  449
+if (!function_exists('clearCache')) {
  450
+
417 451
 /**
418 452
  * Used to delete files in the cache directories, or clear contents of cache directories
419 453
  *
@@ -424,58 +458,62 @@ function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
424 458
  * @param string $ext The file extension you are deleting
425 459
  * @return true if files found and deleted false otherwise
426 460
  */
427  
-function clearCache($params = null, $type = 'views', $ext = '.php') {
428  
-	if (is_string($params) || $params === null) {
429  
-		$params = preg_replace('/\/\//', '/', $params);
430  
-		$cache = CACHE . $type . DS . $params;
  461
+	function clearCache($params = null, $type = 'views', $ext = '.php') {
  462
+		if (is_string($params) || $params === null) {
  463
+			$params = preg_replace('/\/\//', '/', $params);
  464
+			$cache = CACHE . $type . DS . $params;
431 465
 
432  
-		if (is_file($cache . $ext)) {
433  
-			@unlink($cache . $ext);
434  
-			return true;
435  
-		} elseif (is_dir($cache)) {
436  
-			$files = glob($cache . '*');
  466
+			if (is_file($cache . $ext)) {
  467
+				@unlink($cache . $ext);
  468
+				return true;
  469
+			} elseif (is_dir($cache)) {
  470
+				$files = glob($cache . '*');
437 471
 
438  
-			if ($files === false) {
439  
-				return false;
440  
-			}
  472
+				if ($files === false) {
  473
+					return false;
  474
+				}
441 475
 
442  
-			foreach ($files as $file) {
443  
-				if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
444  
-					@unlink($file);
  476
+				foreach ($files as $file) {
  477
+					if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
  478
+						@unlink($file);
  479
+					}
445 480
 				}
446  
-			}
447  
-			return true;
448  
-		} else {
449  
-			$cache = array(
450  
-				CACHE . $type . DS . '*' . $params . $ext,
451  
-				CACHE . $type . DS . '*' . $params . '_*' . $ext
452  
-			);
453  
-			$files = array();
454  
-			while ($search = array_shift($cache)) {
455  
-				$results = glob($search);
456  
-				if ($results !== false) {
457  
-					$files = array_merge($files, $results);
  481
+				return true;
  482
+			} else {
  483
+				$cache = array(
  484
+					CACHE . $type . DS . '*' . $params . $ext,
  485
+					CACHE . $type . DS . '*' . $params . '_*' . $ext
  486
+				);
  487
+				$files = array();
  488
+				while ($search = array_shift($cache)) {
  489
+					$results = glob($search);
  490
+					if ($results !== false) {
  491
+						$files = array_merge($files, $results);
  492
+					}
458 493
 				}
459  
-			}
460  
-			if (empty($files)) {
461  
-				return false;
462  
-			}
463  
-			foreach ($files as $file) {
464  
-				if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
465  
-					@unlink($file);
  494
+				if (empty($files)) {
  495
+					return false;
  496
+				}
  497
+				foreach ($files as $file) {
  498
+					if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
  499
+						@unlink($file);
  500
+					}
466 501
 				}
  502
+				return true;
  503
+			}
  504
+		} elseif (is_array($params)) {
  505
+			foreach ($params as $file) {
  506
+				clearCache($file, $type, $ext);
467 507
 			}
468 508
 			return true;
469 509
 		}
470  
-	} elseif (is_array($params)) {
471  
-		foreach ($params as $file) {
472  
-			clearCache($file, $type, $ext);
473  
-		}
474  
-		return true;
  510
+		return false;
475 511
 	}
476  
-	return false;
  512
+
477 513
 }
478 514
 
  515
+if (!function_exists('stripslashes_deep')) {
  516
+
479 517
 /**
480 518
  * Recursively strips slashes from all values in an array
481 519
  *
@@ -483,17 +521,21 @@ function clearCache($params = null, $type = 'views', $ext = '.php') {
483 521
  * @return mixed What is returned from calling stripslashes
484 522
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#stripslashes_deep
485 523
  */
486  
-function stripslashes_deep($values) {
487  
-	if (is_array($values)) {
488  
-		foreach ($values as $key => $value) {
489  
-			$values[$key] = stripslashes_deep($value);
  524
+	function stripslashes_deep($values) {
  525
+		if (is_array($values)) {
  526
+			foreach ($values as $key => $value) {
  527
+				$values[$key] = stripslashes_deep($value);
  528
+			}
  529
+		} else {
  530
+			$values = stripslashes($values);
490 531
 		}
491  
-	} else {
492  
-		$values = stripslashes($values);
  532
+		return $values;
493 533
 	}
494  
-	return $values;
  534
+
495 535
 }
496 536
 
  537
+if (!function_exists('__')) {
  538
+
497 539
 /**
498 540
  * Returns a translated string if one is found; Otherwise, the submitted message.
499 541
  *
@@ -502,21 +544,25 @@ function stripslashes_deep($values) {
502 544
  * @return mixed translated string
503 545
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__
504 546
  */
505  
-function __($singular, $args = null) {
506  
-	if (!$singular) {
507  
-		return;
508  
-	}
  547
+	function __($singular, $args = null) {
  548
+		if (!$singular) {
  549
+			return;
  550
+		}
509 551
 
510  
-	App::uses('I18n', 'I18n');
511  
-	$translated = I18n::translate($singular);
512  
-	if ($args === null) {
513  
-		return $translated;
514  
-	} elseif (!is_array($args)) {
515  
-		$args = array_slice(func_get_args(), 1);
  552
+		App::uses('I18n', 'I18n');
  553
+		$translated = I18n::translate($singular);
  554
+		if ($args === null) {
  555
+			return $translated;
  556
+		} elseif (!is_array($args)) {
  557
+			$args = array_slice(func_get_args(), 1);
  558
+		}
  559
+		return vsprintf($translated, $args);
516 560
 	}
517  
-	return vsprintf($translated, $args);
  561
+
518 562
 }
519 563
 
  564
+if (!function_exists('__n')) {
  565
+
520 566
 /**
521 567
  * Returns correct plural form of message identified by $singular and $plural for count $count.
522 568
  * Some languages have more than one form for plural messages dependent on the count.
@@ -528,21 +574,25 @@ function __($singular, $args = null) {
528 574
  * @return mixed plural form of translated string
529 575
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__n
530 576
  */
531  
-function __n($singular, $plural, $count, $args = null) {
532  
-	if (!$singular) {
533  
-		return;
534  
-	}
  577
+	function __n($singular, $plural, $count, $args = null) {
  578
+		if (!$singular) {
  579
+			return;
  580
+		}
535 581
 
536  
-	App::uses('I18n', 'I18n');
537  
-	$translated = I18n::translate($singular, $plural, null, 6, $count);
538  
-	if ($args === null) {
539  
-		return $translated;
540  
-	} elseif (!is_array($args)) {
541  
-		$args = array_slice(func_get_args(), 3);
  582
+		App::uses('I18n', 'I18n');
  583
+		$translated = I18n::translate($singular, $plural, null, 6, $count);
  584
+		if ($args === null) {
  585
+			return $translated;
  586
+		} elseif (!is_array($args)) {
  587
+			$args = array_slice(func_get_args(), 3);
  588
+		}
  589
+		return vsprintf($translated, $args);
542 590
 	}
543  
-	return vsprintf($translated, $args);
  591
+
544 592
 }
545 593
 
  594
+if (!function_exists('__d')) {
  595
+
546 596
 /**
547 597
  * Allows you to override the current domain for a single message lookup.
548 598
  *
@@ -552,20 +602,24 @@ function __n($singular, $plural, $count, $args = null) {
552 602
  * @return translated string
553 603
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__d
554 604
  */
555  
-function __d($domain, $msg, $args = null) {
556  
-	if (!$msg) {
557  
-		return;
558  
-	}
559  
-	App::uses('I18n', 'I18n');
560  
-	$translated = I18n::translate($msg, null, $domain);
561  
-	if ($args === null) {
562  
-		return $translated;
563  
-	} elseif (!is_array($args)) {
564  
-		$args = array_slice(func_get_args(), 2);
  605
+	function __d($domain, $msg, $args = null) {
  606
+		if (!$msg) {
  607
+			return;
  608
+		}
  609
+		App::uses('I18n', 'I18n');
  610
+		$translated = I18n::translate($msg, null, $domain);
  611
+		if ($args === null) {
  612
+			return $translated;
  613
+		} elseif (!is_array($args)) {
  614
+			$args = array_slice(func_get_args(), 2);
  615
+		}
  616
+		return vsprintf($translated, $args);
565 617
 	}
566  
-	return vsprintf($translated, $args);
  618
+
567 619
 }
568 620
 
  621
+if (!function_exists('__dn')) {
  622
+
569 623
 /**
570 624
  * Allows you to override the current domain for a single plural message lookup.
571 625
  * Returns correct plural form of message identified by $singular and $plural for count $count
@@ -579,20 +633,24 @@ function __d($domain, $msg, $args = null) {
579 633
  * @return plural form of translated string
580 634
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dn
581 635
  */
582  
-function __dn($domain, $singular, $plural, $count, $args = null) {
583  
-	if (!$singular) {
584  
-		return;
585  
-	}
586  
-	App::uses('I18n', 'I18n');
587  
-	$translated = I18n::translate($singular, $plural, $domain, 6, $count);
588  
-	if ($args === null) {
589  
-		return $translated;
590  
-	} elseif (!is_array($args)) {
591  
-		$args = array_slice(func_get_args(), 4);
  636
+	function __dn($domain, $singular, $plural, $count, $args = null) {
  637
+		if (!$singular) {
  638
+			return;
  639
+		}
  640
+		App::uses('I18n', 'I18n');
  641
+		$translated = I18n::translate($singular, $plural, $domain, 6, $count);
  642
+		if ($args === null) {
  643
+			return $translated;
  644
+		} elseif (!is_array($args)) {
  645
+			$args = array_slice(func_get_args(), 4);
  646
+		}
  647
+		return vsprintf($translated, $args);
592 648
 	}
593  
-	return vsprintf($translated, $args);
  649
+
594 650
 }
595 651
 
  652
+if (!function_exists('__dc')) {
  653
+
596 654
 /**
597 655
  * Allows you to override the current domain for a single message lookup.
598 656
  * It also allows you to specify a category.
@@ -617,20 +675,24 @@ function __dn($domain, $singular, $plural, $count, $args = null) {
617 675
  * @return translated string
618 676
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dc
619 677
  */
620  
-function __dc($domain, $msg, $category, $args = null) {
621  
-	if (!$msg) {
622  
-		return;
623  
-	}
624  
-	App::uses('I18n', 'I18n');
625  
-	$translated = I18n::translate($msg, null, $domain, $category);
626  
-	if ($args === null) {
627  
-		return $translated;
628  
-	} elseif (!is_array($args)) {
629  
-		$args = array_slice(func_get_args(), 3);
  678
+	function __dc($domain, $msg, $category, $args = null) {
  679
+		if (!$msg) {
  680
+			return;
  681
+		}
  682
+		App::uses('I18n', 'I18n');
  683
+		$translated = I18n::translate($msg, null, $domain, $category);
  684
+		if ($args === null) {
  685
+			return $translated;
  686
+		} elseif (!is_array($args)) {
  687
+			$args = array_slice(func_get_args(), 3);
  688
+		}
  689
+		return vsprintf($translated, $args);
630 690
 	}
631  
-	return vsprintf($translated, $args);
  691
+
632 692
 }
633 693
 
  694
+if (!function_exists('__dcn')) {
  695
+
634 696
 /**
635 697
  * Allows you to override the current domain for a single plural message lookup.
636 698
  * It also allows you to specify a category.
@@ -659,20 +721,24 @@ function __dc($domain, $msg, $category, $args = null) {
659 721
  * @return plural form of translated string
660 722
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dcn
661 723
  */
662  
-function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
663  
-	if (!$singular) {
664  
-		return;
665  
-	}
666  
-	App::uses('I18n', 'I18n');
667  
-	$translated = I18n::translate($singular, $plural, $domain, $category, $count);
668  
-	if ($args === null) {
669  
-		return $translated;
670  
-	} elseif (!is_array($args)) {
671  
-		$args = array_slice(func_get_args(), 5);
  724
+	function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
  725
+		if (!$singular) {
  726
+			return;
  727
+		}
  728
+		App::uses('I18n', 'I18n');
  729
+		$translated = I18n::translate($singular, $plural, $domain, $category, $count);
  730
+		if ($args === null) {
  731
+			return $translated;
  732
+		} elseif (!is_array($args)) {
  733
+			$args = array_slice(func_get_args(), 5);
  734
+		}
  735
+		return vsprintf($translated, $args);
672 736
 	}
673  
-	return vsprintf($translated, $args);
  737
+
674 738
 }
675 739
 
  740
+if (!function_exists('__c')) {
  741
+
676 742
 /**
677 743
  * The category argument allows a specific category of the locale settings to be used for fetching a message.
678 744
  * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
@@ -693,20 +759,24 @@ function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
693 759
  * @return translated string
694 760
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
695 761
  */
696  
-function __c($msg, $category, $args = null) {
697  
-	if (!$msg) {
698  
-		return;
699  
-	}
700  
-	App::uses('I18n', 'I18n');
701  
-	$translated = I18n::translate($msg, null, null, $category);
702  
-	if ($args === null) {
703  
-		return $translated;
704  
-	} elseif (!is_array($args)) {
705  
-		$args = array_slice(func_get_args(), 2);
  762
+	function __c($msg, $category, $args = null) {
  763
+		if (!$msg) {
  764
+			return;
  765
+		}
  766
+		App::uses('I18n', 'I18n');
  767
+		$translated = I18n::translate($msg, null, null, $category);
  768
+		if ($args === null) {
  769
+			return $translated;
  770
+		} elseif (!is_array($args)) {
  771
+			$args = array_slice(func_get_args(), 2);
  772
+		}
  773
+		return vsprintf($translated, $args);
706 774
 	}
707  
-	return vsprintf($translated, $args);
  775
+
708 776
 }
709 777
 
  778
+if (!function_exists('LogError')) {
  779
+
710 780
 /**
711 781
  * Shortcut to Log::write.
712 782
  *
@@ -714,13 +784,17 @@ function __c($msg, $category, $args = null) {
714 784
  * @return void
715 785
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#LogError
716 786
  */
717  
-function LogError($message) {
718  
-	App::uses('CakeLog', 'Log');
719  
-	$bad = array("\n", "\r", "\t");
720  
-	$good = ' ';
721  
-	CakeLog::write('error', str_replace($bad, $good, $message));
  787
+	function LogError($message) {
  788
+		App::uses('CakeLog', 'Log');
  789
+		$bad = array("\n", "\r", "\t");
  790
+		$good = ' ';
  791
+		CakeLog::write('error', str_replace($bad, $good, $message));
  792
+	}
  793
+
722 794
 }
723 795
 
  796
+if (!function_exists('fileExistsInPath')) {
  797
+
724 798
 /**
725 799
  * Searches include path for files.
726 800
  *
@@ -728,20 +802,24 @@ function LogError($message) {
728 802
  * @return Full path to file if exists, otherwise false
729 803
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#fileExistsInPath
730 804
  */
731  
-function fileExistsInPath($file) {
732  
-	$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
733  
-	foreach ($paths as $path) {
734  
-		$fullPath = $path . DS . $file;
735  
-
736  
-		if (file_exists($fullPath)) {
737  
-			return $fullPath;
738  
-		} elseif (file_exists($file)) {
739  
-			return $file;
  805
+	function fileExistsInPath($file) {
  806
+		$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
  807
+		foreach ($paths as $path) {
  808
+			$fullPath = $path . DS . $file;
  809
+
  810
+			if (file_exists($fullPath)) {
  811
+				return $fullPath;
  812
+			} elseif (file_exists($file)) {
  813
+				return $file;
  814
+			}
740 815
 		}
  816
+		return false;
741 817
 	}
742  
-	return false;
  818
+
743 819
 }
744 820
 
  821
+if (!function_exists('convertSlash')) {
  822
+
745 823
 /**
746 824
  * Convert forward slashes to underscores and removes first and last underscores in a string
747 825
  *
@@ -749,9 +827,11 @@ function fileExistsInPath($file) {
749 827
  * @return string with underscore remove from start and end of string
750 828
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#convertSlash
751 829
  */
752  
-function convertSlash($string) {
753  
-	$string = trim($string, '/');
754  
-	$string = preg_replace('/\/\//', '/', $string);
755  
-	$string = str_replace('/', '_', $string);
756  
-	return $string;
  830
+	function convertSlash($string) {
  831
+		$string = trim($string, '/');
  832
+		$string = preg_replace('/\/\//', '/', $string);
  833
+		$string = str_replace('/', '_', $string);
  834
+		return $string;
  835
+	}
  836
+
757 837
 }

0 notes on commit 99b798f

Marc Würth

SERVER_IIS seems to be an undocumented or rather not anymore documented config switch, which was , according to the posts in the Cake's Google group, used in the past to change the behavior of Cake to circumvent how IIS sets some enviornment variables.

https://groups.google.com/forum/?fromgroups&nomobile=true#!searchin/cake-php/SERVER_IIS

I suggest we either document it properly or remove it.
I'd tend to the latter...

Please sign in to comment.
Something went wrong with that request. Please try again.