| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
class sfToolkit |
|---|
| 22 |
{ |
|---|
| 23 |
|
|---|
| 24 |
* Extract the class or interface name from filename. |
|---|
| 25 |
* |
|---|
| 26 |
* @param string A filename. |
|---|
| 27 |
* |
|---|
| 28 |
* @return string A class or interface name, if one can be extracted, otherwise null. |
|---|
| 29 |
*/ |
|---|
| 30 |
public static function extractClassName($filename) |
|---|
| 31 |
{ |
|---|
| 32 |
$retval = null; |
|---|
| 33 |
|
|---|
| 34 |
if (self::isPathAbsolute($filename)) |
|---|
| 35 |
{ |
|---|
| 36 |
$filename = basename($filename); |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
$pattern = '/(.*?)\.(class|interface)\.php/i'; |
|---|
| 40 |
|
|---|
| 41 |
if (preg_match($pattern, $filename, $match)) |
|---|
| 42 |
{ |
|---|
| 43 |
$retval = $match[1]; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
return $retval; |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
* Clear all files in a given directory. |
|---|
| 51 |
* |
|---|
| 52 |
* @param string An absolute filesystem path to a directory. |
|---|
| 53 |
* |
|---|
| 54 |
* @return void |
|---|
| 55 |
*/ |
|---|
| 56 |
public static function clearDirectory($directory) |
|---|
| 57 |
{ |
|---|
| 58 |
if (!is_dir($directory)) |
|---|
| 59 |
{ |
|---|
| 60 |
return; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
$fp = opendir($directory); |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
$ignore = array('.', '..', 'CVS', '.svn'); |
|---|
| 68 |
|
|---|
| 69 |
while (($file = readdir($fp)) !== false) |
|---|
| 70 |
{ |
|---|
| 71 |
if (!in_array($file, $ignore)) |
|---|
| 72 |
{ |
|---|
| 73 |
if (is_link($directory.'/'.$file)) |
|---|
| 74 |
{ |
|---|
| 75 |
|
|---|
| 76 |
unlink($directory.'/'.$file); |
|---|
| 77 |
} |
|---|
| 78 |
else if (is_dir($directory.'/'.$file)) |
|---|
| 79 |
{ |
|---|
| 80 |
|
|---|
| 81 |
self::clearDirectory($directory.'/'.$file); |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
rmdir($directory.'/'.$file); |
|---|
| 85 |
} |
|---|
| 86 |
else |
|---|
| 87 |
{ |
|---|
| 88 |
|
|---|
| 89 |
unlink($directory.'/'.$file); |
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
closedir($fp); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
* Clear all files and directories corresponding to a glob pattern. |
|---|
| 100 |
* |
|---|
| 101 |
* @param string An absolute filesystem pattern. |
|---|
| 102 |
* |
|---|
| 103 |
* @return void |
|---|
| 104 |
*/ |
|---|
| 105 |
public static function clearGlob($pattern) |
|---|
| 106 |
{ |
|---|
| 107 |
$files = glob($pattern); |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
sort($files); |
|---|
| 111 |
|
|---|
| 112 |
foreach ($files as $file) |
|---|
| 113 |
{ |
|---|
| 114 |
if (is_dir($file)) |
|---|
| 115 |
{ |
|---|
| 116 |
|
|---|
| 117 |
self::clearDirectory($file); |
|---|
| 118 |
} |
|---|
| 119 |
else |
|---|
| 120 |
{ |
|---|
| 121 |
|
|---|
| 122 |
unlink($file); |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
* Determine if a filesystem path is absolute. |
|---|
| 129 |
* |
|---|
| 130 |
* @param path A filesystem path. |
|---|
| 131 |
* |
|---|
| 132 |
* @return bool true, if the path is absolute, otherwise false. |
|---|
| 133 |
*/ |
|---|
| 134 |
public static function isPathAbsolute($path) |
|---|
| 135 |
{ |
|---|
| 136 |
if ($path[0] == '/' || $path[0] == '\\' || |
|---|
| 137 |
(strlen($path) > 3 && ctype_alpha($path[0]) && |
|---|
| 138 |
$path[1] == ':' && |
|---|
| 139 |
($path[2] == '\\' || $path[2] == '/') |
|---|
| 140 |
) |
|---|
| 141 |
) |
|---|
| 142 |
{ |
|---|
| 143 |
return true; |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
return false; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
* Determine if a lock file is present. |
|---|
| 151 |
* |
|---|
| 152 |
* @param integer A max amount of life time for the lock file. |
|---|
| 153 |
* |
|---|
| 154 |
* @return bool true, if the lock file is present, otherwise false. |
|---|
| 155 |
*/ |
|---|
| 156 |
public static function hasLockFile($lockFile, $maxLockFileLifeTime = 0) |
|---|
| 157 |
{ |
|---|
| 158 |
$isLocked = false; |
|---|
| 159 |
if (is_readable($lockFile) && ($last_access = fileatime($lockFile))) |
|---|
| 160 |
{ |
|---|
| 161 |
$now = time(); |
|---|
| 162 |
$timeDiff = $now - $last_access; |
|---|
| 163 |
|
|---|
| 164 |
if (!$maxLockFileLifeTime || $timeDiff < $maxLockFileLifeTime) |
|---|
| 165 |
{ |
|---|
| 166 |
$isLocked = true; |
|---|
| 167 |
} |
|---|
| 168 |
else |
|---|
| 169 |
{ |
|---|
| 170 |
$isLocked = @unlink($lockFile) ? false : true; |
|---|
| 171 |
} |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
return $isLocked; |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
public static function stripComments($source) |
|---|
| 178 |
{ |
|---|
| 179 |
if (!sfConfig::get('sf_strip_comments', true) || !function_exists('token_get_all')) |
|---|
| 180 |
{ |
|---|
| 181 |
return $source; |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
$ignore = array(T_COMMENT => true, T_DOC_COMMENT => true); |
|---|
| 185 |
$output = ''; |
|---|
| 186 |
|
|---|
| 187 |
foreach (token_get_all($source) as $token) |
|---|
| 188 |
{ |
|---|
| 189 |
|
|---|
| 190 |
if (isset($token[1])) |
|---|
| 191 |
{ |
|---|
| 192 |
|
|---|
| 193 |
if (!isset($ignore[$token[0]])) |
|---|
| 194 |
{ |
|---|
| 195 |
|
|---|
| 196 |
$output .= $token[1]; |
|---|
| 197 |
} |
|---|
| 198 |
} |
|---|
| 199 |
else |
|---|
| 200 |
{ |
|---|
| 201 |
|
|---|
| 202 |
$output .= $token; |
|---|
| 203 |
} |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
return $output; |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
public static function stripslashesDeep($value) |
|---|
| 210 |
{ |
|---|
| 211 |
return is_array($value) ? array_map(array('sfToolkit', 'stripslashesDeep'), $value) : stripslashes($value); |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
/* |
|---|
| 216 |
* array arrayDeepMerge ( array array1 [, array array2 [, array ...]] ) |
|---|
| 217 |
* |
|---|
| 218 |
* Like array_merge |
|---|
| 219 |
* |
|---|
| 220 |
* arrayDeepMerge() merges the elements of one or more arrays together so |
|---|
| 221 |
* that the values of one are appended to the end of the previous one. It |
|---|
| 222 |
* returns the resulting array. |
|---|
| 223 |
* If the input arrays have the same string keys, then the later value for |
|---|
| 224 |
* that key will overwrite the previous one. If, however, the arrays contain |
|---|
| 225 |
* numeric keys, the later value will not overwrite the original value, but |
|---|
| 226 |
* will be appended. |
|---|
| 227 |
* If only one array is given and the array is numerically indexed, the keys |
|---|
| 228 |
* get reindexed in a continuous way. |
|---|
| 229 |
* |
|---|
| 230 |
* Different from array_merge |
|---|
| 231 |
* If string keys have arrays for values, these arrays will merge recursively. |
|---|
| 232 |
*/ |
|---|
| 233 |
public static function arrayDeepMerge() |
|---|
| 234 |
{ |
|---|
| 235 |
switch (func_num_args()) |
|---|
| 236 |
{ |
|---|
| 237 |
case 0: |
|---|
| 238 |
return false; |
|---|
| 239 |
case 1: |
|---|
| 240 |
return func_get_arg(0); |
|---|
| 241 |
case 2: |
|---|
| 242 |
$args = func_get_args(); |
|---|
| 243 |
$args[2] = array(); |
|---|
| 244 |
if (is_array($args[0]) && is_array($args[1])) |
|---|
| 245 |
{ |
|---|
| 246 |
foreach (array_unique(array_merge(array_keys($args[0]),array_keys($args[1]))) as $key) |
|---|
| 247 |
{ |
|---|
| 248 |
$isKey0 = array_key_exists($key, $args[0]); |
|---|
| 249 |
$isKey1 = array_key_exists($key, $args[1]); |
|---|
| 250 |
if ($isKey0 && $isKey1 && is_array($args[0][$key]) && is_array($args[1][$key])) |
|---|
| 251 |
{ |
|---|
| 252 |
$args[2][$key] = self::arrayDeepMerge($args[0][$key], $args[1][$key]); |
|---|
| 253 |
} |
|---|
| 254 |
else if ($isKey0 && $isKey1) |
|---|
| 255 |
{ |
|---|
| 256 |
$args[2][$key] = $args[1][$key]; |
|---|
| 257 |
} |
|---|
| 258 |
else if (!$isKey1) |
|---|
| 259 |
{ |
|---|
| 260 |
$args[2][$key] = $args[0][$key]; |
|---|
| 261 |
} |
|---|
| 262 |
else if (!$isKey0) |
|---|
| 263 |
{ |
|---|
| 264 |
$args[2][$key] = $args[1][$key]; |
|---|
| 265 |
} |
|---|
| 266 |
} |
|---|
| 267 |
return $args[2]; |
|---|
| 268 |
} |
|---|
| 269 |
else |
|---|
| 270 |
{ |
|---|
| 271 |
return $args[1]; |
|---|
| 272 |
} |
|---|
| 273 |
default : |
|---|
| 274 |
$args = func_get_args(); |
|---|
| 275 |
$args[1] = sfToolkit::arrayDeepMerge($args[0], $args[1]); |
|---|
| 276 |
array_shift($args); |
|---|
| 277 |
return call_user_func_array(array('sfToolkit', 'arrayDeepMerge'), $args); |
|---|
| 278 |
break; |
|---|
| 279 |
} |
|---|
| 280 |
} |
|---|
| 281 |
|
|---|
| 282 |
public static function stringToArray($string) |
|---|
| 283 |
{ |
|---|
| 284 |
preg_match_all('/ |
|---|
| 285 |
\s*(\w+) # key \\1 |
|---|
| 286 |
\s*=\s* # = |
|---|
| 287 |
(\'|")? # values may be included in \' or " \\2 |
|---|
| 288 |
(.*?) # value \\3 |
|---|
| 289 |
(?(2) \\2) # matching \' or " if needed \\4 |
|---|
| 290 |
\s*(?: |
|---|
| 291 |
(?=\w+\s*=) | \s*$ # followed by another key= or the end of the string |
|---|
| 292 |
) |
|---|
| 293 |
/x', $string, $matches, PREG_SET_ORDER); |
|---|
| 294 |
|
|---|
| 295 |
$attributes = array(); |
|---|
| 296 |
foreach ($matches as $val) |
|---|
| 297 |
{ |
|---|
| 298 |
$attributes[$val[1]] = self::literalize($val[3]); |
|---|
| 299 |
} |
|---|
| 300 |
|
|---|
| 301 |
return $attributes; |
|---|
| 302 |
} |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
* Finds the type of the passed value, returns the value as the new type. |
|---|
| 306 |
* |
|---|
| 307 |
* @param string |
|---|
| 308 |
* @return mixed |
|---|
| 309 |
*/ |
|---|
| 310 |
public static function literalize($value, $quoted = false) |
|---|
| 311 |
{ |
|---|
| 312 |
|
|---|
| 313 |
$value = trim($value); |
|---|
| 314 |
$lvalue = strtolower($value); |
|---|
| 315 |
|
|---|
| 316 |
if (in_array($lvalue, array('null', '~', ''))) |
|---|
| 317 |
{ |
|---|
| 318 |
$value = null; |
|---|
| 319 |
} |
|---|
| 320 |
else if (in_array($lvalue, array('true', 'on', '+', 'yes'))) |
|---|
| 321 |
{ |
|---|
| 322 |
$value = true; |
|---|
| 323 |
} |
|---|
| 324 |
else if (in_array($lvalue, array('false', 'off', '-', 'no'))) |
|---|
| 325 |
{ |
|---|
| 326 |
$value = false; |
|---|
| 327 |
} |
|---|
| 328 |
else if (ctype_digit($value)) |
|---|
| 329 |
{ |
|---|
| 330 |
$value = (int) $value; |
|---|
| 331 |
} |
|---|
| 332 |
else if (is_numeric($value)) |
|---|
| 333 |
{ |
|---|
| 334 |
$value = (float) $value; |
|---|
| 335 |
} |
|---|
| 336 |
else |
|---|
| 337 |
{ |
|---|
| 338 |
$value = self::replaceConstants($value); |
|---|
| 339 |
if ($quoted) |
|---|
| 340 |
{ |
|---|
| 341 |
$value = '\''.str_replace('\'', '\\\'', $value).'\''; |
|---|
| 342 |
} |
|---|
| 343 |
} |
|---|
| 344 |
|
|---|
| 345 |
return $value; |
|---|
| 346 |
} |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
* Replaces constant identifiers in a scalar value. |
|---|
| 350 |
* |
|---|
| 351 |
* @param string the value to perform the replacement on |
|---|
| 352 |
* @return string the value with substitutions made |
|---|
| 353 |
*/ |
|---|
| 354 |
public static function replaceConstants($value) |
|---|
| 355 |
{ |
|---|
| 356 |
return is_string($value) ? preg_replace_callback('/%(.+?)%/', create_function('$v', 'return sfConfig::has(strtolower($v[1])) ? sfConfig::get(strtolower($v[1])) : "%{$v[1]}%";'), $value) : $value; |
|---|
| 357 |
} |
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
* Returns subject replaced with regular expression matchs |
|---|
| 361 |
* |
|---|
| 362 |
* @param mixed subject to search |
|---|
| 363 |
* @param array array of search => replace pairs |
|---|
| 364 |
*/ |
|---|
| 365 |
public static function pregtr($search, $replacePairs) |
|---|
| 366 |
{ |
|---|
| 367 |
return preg_replace(array_keys($replacePairs), array_values($replacePairs), $search); |
|---|
| 368 |
} |
|---|
| 369 |
|
|---|
| 370 |
public static function isArrayValuesEmpty($array) |
|---|
| 371 |
{ |
|---|
| 372 |
static $isEmpty = true; |
|---|
| 373 |
foreach ($array as $value) |
|---|
| 374 |
{ |
|---|
| 375 |
$isEmpty = (is_array($value)) ? self::isArrayValuesEmpty($value) : (strlen($value) == 0); |
|---|
| 376 |
if (!$isEmpty) |
|---|
| 377 |
{ |
|---|
| 378 |
break; |
|---|
| 379 |
} |
|---|
| 380 |
} |
|---|
| 381 |
|
|---|
| 382 |
return $isEmpty; |
|---|
| 383 |
} |
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
* Checks if a string is an utf8. |
|---|
| 387 |
* |
|---|
| 388 |
* Yi Stone Li<yili@yahoo-inc.com> |
|---|
| 389 |
* Copyright (c) 2007 Yahoo! Inc. All rights reserved. |
|---|
| 390 |
* Licensed under the BSD open source license |
|---|
| 391 |
* |
|---|
| 392 |
* @param string |
|---|
| 393 |
* |
|---|
| 394 |
* @return bool true if $string is valid UTF-8 and false otherwise. |
|---|
| 395 |
*/ |
|---|
| 396 |
public static function isUTF8($string) |
|---|
| 397 |
{ |
|---|
| 398 |
for ($idx = 0, $strlen = strlen($string); $idx < $strlen; $idx++) |
|---|
| 399 |
{ |
|---|
| 400 |
$byte = ord($string[$idx]); |
|---|
| 401 |
|
|---|
| 402 |
if ($byte & 0x80) |
|---|
| 403 |
{ |
|---|
| 404 |
if (($byte & 0xE0) == 0xC0) |
|---|
| 405 |
{ |
|---|
| 406 |
|
|---|
| 407 |
$bytes_remaining = 1; |
|---|
| 408 |
} |
|---|
| 409 |
else if (($byte & 0xF0) == 0xE0) |
|---|
| 410 |
{ |
|---|
| 411 |
|
|---|
| 412 |
$bytes_remaining = 2; |
|---|
| 413 |
} |
|---|
| 414 |
else if (($byte & 0xF8) == 0xF0) |
|---|
| 415 |
{ |
|---|
| 416 |
|
|---|
| 417 |
$bytes_remaining = 3; |
|---|
| 418 |
} |
|---|
| 419 |
else |
|---|
| 420 |
{ |
|---|
| 421 |
return false; |
|---|
| 422 |
} |
|---|
| 423 |
|
|---|
| 424 |
if ($idx + $bytes_remaining >= $strlen) |
|---|
| 425 |
{ |
|---|
| 426 |
return false; |
|---|
| 427 |
} |
|---|
| 428 |
|
|---|
| 429 |
while ($bytes_remaining--) |
|---|
| 430 |
{ |
|---|
| 431 |
if ((ord($string[++$idx]) & 0xC0) != 0x80) |
|---|
| 432 |
{ |
|---|
| 433 |
return false; |
|---|
| 434 |
} |
|---|
| 435 |
} |
|---|
| 436 |
} |
|---|
| 437 |
} |
|---|
| 438 |
|
|---|
| 439 |
return true; |
|---|
| 440 |
} |
|---|
| 441 |
|
|---|
| 442 |
public static function &getArrayValueForPathByRef(&$values, $name, $default = null) |
|---|
| 443 |
{ |
|---|
| 444 |
if (false !== ($offset = strpos($name, '['))) |
|---|
| 445 |
{ |
|---|
| 446 |
if (isset($values[substr($name, 0, $offset)])) |
|---|
| 447 |
{ |
|---|
| 448 |
$array = &$values[substr($name, 0, $offset)]; |
|---|
| 449 |
|
|---|
| 450 |
while ($pos = strpos($name, '[', $offset)) |
|---|
| 451 |
{ |
|---|
| 452 |
$end = strpos($name, ']', $pos); |
|---|
| 453 |
if ($end == $pos + 1) |
|---|
| 454 |
{ |
|---|
| 455 |
|
|---|
| 456 |
break; |
|---|
| 457 |
} |
|---|
| 458 |
else if (!isset($array[substr($name, $pos + 1, $end - $pos - 1)])) |
|---|
| 459 |
{ |
|---|
| 460 |
return $default; |
|---|
| 461 |
} |
|---|
| 462 |
else if (is_array($array)) |
|---|
| 463 |
{ |
|---|
| 464 |
$array = &$array[substr($name, $pos + 1, $end - $pos - 1)]; |
|---|
| 465 |
$offset = $end; |
|---|
| 466 |
} |
|---|
| 467 |
else |
|---|
| 468 |
{ |
|---|
| 469 |
return $default; |
|---|
| 470 |
} |
|---|
| 471 |
} |
|---|
| 472 |
|
|---|
| 473 |
return $array; |
|---|
| 474 |
} |
|---|
| 475 |
} |
|---|
| 476 |
|
|---|
| 477 |
return $default; |
|---|
| 478 |
} |
|---|
| 479 |
|
|---|
| 480 |
public static function getArrayValueForPath($values, $name, $default = null) |
|---|
| 481 |
{ |
|---|
| 482 |
if (false !== ($offset = strpos($name, '['))) |
|---|
| 483 |
{ |
|---|
| 484 |
if (isset($values[substr($name, 0, $offset)])) |
|---|
| 485 |
{ |
|---|
| 486 |
$array = $values[substr($name, 0, $offset)]; |
|---|
| 487 |
|
|---|
| 488 |
while ($pos = strpos($name, '[', $offset)) |
|---|
| 489 |
{ |
|---|
| 490 |
$end = strpos($name, ']', $pos); |
|---|
| 491 |
if ($end == $pos + 1) |
|---|
| 492 |
{ |
|---|
| 493 |
|
|---|
| 494 |
break; |
|---|
| 495 |
} |
|---|
| 496 |
else if (!isset($array[substr($name, $pos + 1, $end - $pos - 1)])) |
|---|
| 497 |
{ |
|---|
| 498 |
return $default; |
|---|
| 499 |
} |
|---|
| 500 |
else if (is_array($array)) |
|---|
| 501 |
{ |
|---|
| 502 |
$array = $array[substr($name, $pos + 1, $end - $pos - 1)]; |
|---|
| 503 |
$offset = $end; |
|---|
| 504 |
} |
|---|
| 505 |
else |
|---|
| 506 |
{ |
|---|
| 507 |
return $default; |
|---|
| 508 |
} |
|---|
| 509 |
} |
|---|
| 510 |
|
|---|
| 511 |
return $array; |
|---|
| 512 |
} |
|---|
| 513 |
} |
|---|
| 514 |
|
|---|
| 515 |
return $default; |
|---|
| 516 |
} |
|---|
| 517 |
|
|---|
| 518 |
public static function getPhpCli() |
|---|
| 519 |
{ |
|---|
| 520 |
$path = getenv('PATH') ? getenv('PATH') : getenv('Path'); |
|---|
| 521 |
$suffixes = DIRECTORY_SEPARATOR == '\\' ? (getenv('PATHEXT') ? explode(PATH_SEPARATOR, getenv('PATHEXT')) : array('.exe', '.bat', '.cmd', '.com')) : array(''); |
|---|
| 522 |
foreach (array('php5', 'php') as $phpCli) |
|---|
| 523 |
{ |
|---|
| 524 |
foreach ($suffixes as $suffix) |
|---|
| 525 |
{ |
|---|
| 526 |
foreach (explode(PATH_SEPARATOR, $path) as $dir) |
|---|
| 527 |
{ |
|---|
| 528 |
$file = $dir.DIRECTORY_SEPARATOR.$phpCli.$suffix; |
|---|
| 529 |
if (is_executable($file)) |
|---|
| 530 |
{ |
|---|
| 531 |
return $file; |
|---|
| 532 |
} |
|---|
| 533 |
} |
|---|
| 534 |
} |
|---|
| 535 |
} |
|---|
| 536 |
|
|---|
| 537 |
throw new sfException('Unable to find PHP executable'); |
|---|
| 538 |
} |
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
* From PEAR System.php |
|---|
| 542 |
* |
|---|
| 543 |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
|---|
| 544 |
* that is available through the world-wide-web at the following URI: |
|---|
| 545 |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
|---|
| 546 |
* the PHP License and are unable to obtain it through the web, please |
|---|
| 547 |
* send a note to license@php.net so we can mail you a copy immediately. |
|---|
| 548 |
* |
|---|
| 549 |
* @author Tomas V.V.Cox <cox@idecnet.com> |
|---|
| 550 |
* @copyright 1997-2006 The PHP Group |
|---|
| 551 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
|---|
| 552 |
*/ |
|---|
| 553 |
public static function getTmpDir() |
|---|
| 554 |
{ |
|---|
| 555 |
if (DIRECTORY_SEPARATOR == '\\') |
|---|
| 556 |
{ |
|---|
| 557 |
if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) |
|---|
| 558 |
{ |
|---|
| 559 |
return $var; |
|---|
| 560 |
} |
|---|
| 561 |
if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) |
|---|
| 562 |
{ |
|---|
| 563 |
return $var; |
|---|
| 564 |
} |
|---|
| 565 |
if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) |
|---|
| 566 |
{ |
|---|
| 567 |
return $var; |
|---|
| 568 |
} |
|---|
| 569 |
|
|---|
| 570 |
return getenv('SystemRoot').'\temp'; |
|---|
| 571 |
} |
|---|
| 572 |
|
|---|
| 573 |
if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) |
|---|
| 574 |
{ |
|---|
| 575 |
return $var; |
|---|
| 576 |
} |
|---|
| 577 |
|
|---|
| 578 |
return '/tmp'; |
|---|
| 579 |
} |
|---|
| 580 |
} |
|---|
| 581 |
|
|---|