[ Index ] |
PHP Cross Reference of phool |
[Summary view] [Print] [Text view]
1 <?php 2 //============================================================================= 3 /** 4 * @copyright Francois Laupretre <phool@tekwire.net> 5 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0 6 * @category phool 7 * @package phool 8 */ 9 //============================================================================ 10 11 namespace Phool; 12 13 class Util 14 { 15 16 //--------- 17 18 public static function envIsWeb() 19 { 20 return (php_sapi_name()!='cli'); 21 } 22 23 //---- 24 25 public static function envIsWindows() 26 { 27 return (substr(PHP_OS, 0, 3) == 'WIN'); 28 } 29 30 //--------- 31 // Adapted from PEAR 32 33 public static function loadExtension($ext) 34 { 35 if (extension_loaded($ext)) return; 36 37 if (PHP_OS == 'AIX') $suffix = 'a'; 38 else $suffix = PHP_SHLIB_SUFFIX; 39 40 @dl('php_'.$ext.'.'.$suffix) || @dl($ext.'.'.$suffix); 41 42 if (!extension_loaded($ext)) throw new \Exception("$ext: Cannot load extension"); 43 } 44 45 //--------- 46 // Require several extensions. Allows to list every extensions that are not 47 // present. 48 49 public static function loadExtensions($ext_list) 50 { 51 $failed_ext=array(); 52 foreach($ext_list as $ext) 53 { 54 try { self::loadExtension($ext); } 55 catch (\Exception $e) { $failed_ext[]=$ext; } 56 } 57 if (count($failed_ext)) 58 throw new \Exception('Cannot load the following required extension(s): ' 59 .implode(' ',$failed_ext)); 60 } 61 62 //--------- 63 // Replacement for substr() 64 // Difference : returns '' instead of false (when index out of range) 65 66 public static function substr($buf,$position,$len=NULL) 67 { 68 $str=is_null($len) ? substr($buf,$position) : substr($buf,$position,$len); 69 if ($str===false) $str=''; 70 return $str; 71 } 72 73 //--------- 74 // This function must be called before every file access 75 // In PHP 6, magic_quotes_runtime is suppressed and set_magic_quotes_runtime() 76 // does not exist any more. 77 78 private static $mqr_exists=null; 79 private static $mqr_level=0; 80 private static $mqr_save; 81 82 public static function disableMQR() 83 { 84 if (is_null(self::$mqr_exists)) 85 self::$mqr_exists=function_exists('set_magic_quotes_runtime'); 86 87 if (!self::$mqr_exists) return; 88 89 if (self::$mqr_level==0) 90 { 91 self::$mqr_save=get_magic_quotes_runtime(); 92 set_magic_quotes_runtime(0); 93 } 94 self::$mqr_level++; 95 } 96 97 //--------- 98 // This function must be called after every file access 99 100 public static function restoreMQR() 101 { 102 if (is_null(self::$mqr_exists)) 103 self::$mqr_exists=function_exists('set_magic_quotes_runtime'); 104 105 if (!self::$mqr_exists) return; 106 107 self::$mqr_level--; 108 if (self::$mqr_level==0) set_magic_quotes_runtime(self::$mqr_save); 109 } 110 111 //--------- 112 113 public static function mkArray($data) 114 { 115 if (is_null($data)) return array(); 116 if (!is_array($data)) $data=array($data); 117 return $data; 118 } 119 120 //--------------------------------- 121 122 public static function callMethod($object,$method,$args) 123 { 124 return call_user_func_array(array($object,$method),$args); 125 } 126 127 //---------- 128 } // End of class 129 //============================================================================= 130 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jun 4 19:17:11 2015 | Cross-referenced by PHPXref 0.7.1 |