| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 10 /** 11 * @package core 12 * @version $Id: common.inc.php 5994 2007-06-15 10:54:41Z pachanga $ 13 */ 14 $GLOBALS['LIMB_LAZY_CLASS_PATHS'] = array(); 15 16 function lmb_resolve_include_path($path) 17 { 18 //this will be replaced with stream_resolve_include_path() in the future versions of PHP 19 foreach(lmb_get_include_path_items() as $dir) 20 { 21 $full_path = "$dir/$path"; 22 if(is_file($full_path) || is_dir($full_path)) 23 return $full_path; 24 } 25 } 26 27 function lmb_is_readable($file) 28 { 29 $fh = @fopen($file, 'r', true); 30 if(!is_resource($fh)) 31 return false; 32 33 fclose($fh); 34 return true; 35 } 36 37 function lmb_glob($path) 38 { 39 if(lmb_is_path_absolute($path)) 40 return glob($path); 41 42 foreach(lmb_get_include_path_items() as $dir) 43 { 44 if($res = glob("$dir/$path")) 45 return $res; 46 } 47 return array(); 48 } 49 50 function lmb_get_include_path_items() 51 { 52 return explode(PATH_SEPARATOR, get_include_path()); 53 } 54 55 function lmb_is_path_absolute($path) 56 { 57 if(!$path) 58 return false; 59 60 //very trivial check, is more comprehensive required? 61 return (($path{0} == '/' || $path{0} == '\\') || 62 (strlen($path) > 2 && $path{1} == ':')); 63 } 64 65 function lmb_require($file_path, $optional = false) 66 { 67 static $tried = array(); 68 69 if(isset($tried[$file_path])) 70 return; 71 else 72 $tried[$file_path] = true; 73 74 if(strpos($file_path, '*') !== false) 75 { 76 foreach(lmb_glob($file_path) as $path) 77 lmb_require($path, $optional); 78 return; 79 } 80 81 if($optional && !lmb_is_readable($file_path)) 82 return; 83 84 $file = basename($file_path); 85 $items = explode('.', $file); 86 87 if(isset($items[1])) 88 { 89 if($items[1] == 'class' || $items[1] == 'interface') 90 { 91 $GLOBALS['LIMB_LAZY_CLASS_PATHS'][$items[0]] = $file_path; 92 return; 93 } 94 } 95 else 96 { 97 if($items[1] == 'class' && class_exists($items[0], false)) 98 return; 99 if($items[1] == 'interface' && interface_exists($items[0], false)) 100 return; 101 } 102 103 if(!include_once($file_path)) 104 throw new lmbException("Could not include source file '$file_path'"); 105 } 106 107 function lmb_require_optional($file_path) 108 { 109 lmb_require($file_path, true); 110 } 111 112 function lmb_autoload($name) 113 { 114 if(isset($GLOBALS['LIMB_LAZY_CLASS_PATHS'][$name])) 115 { 116 $file_path = $GLOBALS['LIMB_LAZY_CLASS_PATHS'][$name]; 117 if(!include($file_path)) 118 throw new lmbException("Could not include source file '$file_path'"); 119 } 120 } 121 122 function lmb_var_dump($obj, $echo = false) 123 { 124 ob_start(); 125 var_dump($obj); 126 $dump = ob_get_contents(); 127 ob_end_clean(); 128 129 if($echo) 130 { 131 if(PHP_SAPI != 'cli') 132 { 133 echo '<pre>'; 134 echo $dump; 135 echo '</pre>'; 136 } 137 else 138 echo $dump; 139 } 140 else 141 return $dump; 142 } 143 144 function lmb_camel_case($str, $ucfirst = true) 145 { 146 $items = explode('_', $str); 147 $len = sizeof($items); 148 $first = true; 149 $res = ''; 150 for($i=0;$i<$len;$i++) 151 { 152 $item = $items[$i]; 153 if($item) 154 { 155 //we don't ucfirst first word by default 156 $res .= ($first && !$ucfirst ? $item : ucfirst($item)); 157 $first = false; 158 //skipping next "_" if it's not last 159 if($i+1 < $len-1 && !$items[$i+1]) 160 $i++; 161 } 162 else 163 $res .= '_'; 164 } 165 166 return ($ucfirst) ? ucfirst($res) : $res; 167 } 168 169 function lmb_under_scores($str) 170 { 171 $items = preg_split('~([A-Z][a-z0-9]+)~', $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); 172 $res = ''; 173 foreach($items as $item) 174 $res .= ($item == '_' ? '' : '_') . strtolower($item); 175 return substr($res, 1); 176 } 177 178 function lmb_humanize($str) 179 { 180 return str_replace('_', ' ', lmb_uder_scores($str)); 181 } 182 183 lmb_require('limb/core/src/exception/lmbException.class.php'); 184 185 spl_autoload_register('lmb_autoload'); 186 187 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Jul 25 03:54:57 2008 | Cross-referenced by PHPXref 0.7 |