00001 <?php
00022 class Util
00023 {
00031 public static function camelcase($s, $lower=false)
00032 {
00033 $s = strtr($s, '_', ' ');
00034 $s = ucwords($s);
00035 $s = str_replace(' ', '', $s);
00036
00040 if($lower) {
00041 $s = self::lcfirst($s);
00042 }
00043 return $s;
00044 }
00045
00052 public static function uncamelize($str) {
00053 $str = self::lcfirst($str);
00054 return strtolower(preg_replace('/([A-Z])/', '_\\1', $str));
00055 }
00056
00062 public static function smallcase($s) {
00063 return strtolower(preg_replace('/([A-Z])/', "_\\1", $s));
00064 }
00070 public static function underscore($s)
00071 {
00072 return strtr($s,' ','_');
00073 }
00079 public static function dash($s)
00080 {
00081 return strtr($s,' ','-');
00082 }
00088 public static function humanize($s)
00089 {
00090 return strtr($s,'_-',' ');
00091 }
00100 public static function array_merge_overwrite($a1, $a2)
00101 {
00102 foreach($a2 as $key2 => $value2){
00103 if(!is_array($value2)){
00104 $a1[$key2] = $value2;
00105 } else {
00106 if(!isset($a1[$key2])){
00107 $a1[$key2] = null;
00108 }
00109 if(!is_array($a1[$key2])){
00110 $a1[$key2] = $value2;
00111 } else {
00112 $a1[$key2] = self::arrayMergeOverwrite($a1[$key2], $a2[$key2]);
00113 }
00114 }
00115 }
00116 return $a1;
00117 }
00125 public static function array_insert(&$array, $index, $value)
00126 {
00127 $array2 = array_splice($array, $index);
00128 array_push($array, $value);
00129 $array = array_merge($array, $array2);
00130 }
00131
00138 public static function get_params($params)
00139 {
00140 $params = explode(', ', $params);
00141 $data = array();
00142 foreach($params as $p) {
00143 $match = explode(': ', $p, 2);
00144 $data[$match[0]] = $match[1];
00145 }
00146 return $data;
00147 }
00154 public static function getParams($params){
00155 $data = array();
00156 foreach ($params as $p) {
00157 if(is_string($p) && preg_match('/^(\w+): (.*)/', $p, $match)){
00158 $data[$match[1]] = $match[2];
00159 } else {
00160 $data[] = $p;
00161 }
00162 }
00163 return $data;
00164 }
00165
00166
00167
00168
00169
00170
00171
00172 public static function encomillar($lista)
00173 {
00174 $items = explode(',', $lista);
00175 $encomillada= '"'.implode('","',$items).'"';
00176 return $encomillada;
00177 }
00178
00185 public static function mkpath($path)
00186 {
00187 if(@mkdir($path) or file_exists($path)) return true;
00188 return (mkpath(dirname($path)) and mkdir($path));
00189 }
00190
00197 public static function removedir($dir)
00198 {
00199
00203 if($files = array_merge(glob("$dir/*"), glob("$dir/.*"))) {
00207 foreach($files as $file) {
00211 if(!preg_match("/^.*\/?[\.]{1,2}$/",$file)) {
00212 if(is_dir($file)) {
00213 return self::removeDir($file);
00214 } elseif(!@unlink($file)) {
00215 return false;
00216 }
00217 }
00218 }
00219 }
00220 return @rmdir($dir);
00221 }
00228 public static function lcfirst($s) {
00229 $s{0} = strtolower($s{0});
00230 return $s;
00231 }
00232 }