KumbiaPHP beta2-dev
Framework PHP en español
util.php
Ir a la documentación de este archivo.
00001 <?php
00021 /*
00022  * Utilidades para uso general del framework
00023  * 
00024  */
00025 class Util
00026 {
00034     public static function camelcase($s, $lower=FALSE)
00035     {
00036         // Notacion lowerCamelCase
00037         if($lower) {
00038             return self::lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ',$s))));
00039         }
00040         
00041         return str_replace(' ', '', ucwords(str_replace('_', ' ',$s)));
00042     }
00043         
00050         public static function uncamelize($str) 
00051         {
00052                 return self::smallcase($str);
00053         }
00054         
00060     public static function smallcase($s) 
00061         {
00062         return strtolower(preg_replace('/([A-Z])/', "_\\1", self::lcfirst($s)));
00063     }
00064         
00070     public static function underscore($s)
00071     {
00072         return strtr($s,' ','_');
00073     }
00074         
00080     public static function dash($s)
00081     {
00082         return strtr($s,' ','-');
00083     }
00084         
00090     public static function humanize($s)
00091     {
00092         return strtr($s,'_-','  ');
00093     }
00094         
00104     public static function array_merge_overwrite($a1, $a2)
00105     {
00106         return $a2+$a1;
00107     }
00108         
00117     public static function array_insert(&$array, $position, $insert)
00118     {
00119         array_splice($array, $position, 0, $insert);
00120     }
00121 
00128         public static function getParams($params){
00129         $data = array();
00130         foreach($params as $p) {
00131             if(is_string($p)) {
00132                 $match = explode(': ', $p, 2);
00133                 if(isset($match[1])) {
00134                     $data[$match[0]] = $match[1];
00135                 } else {
00136                     $data[] = $p;
00137                 }
00138             } else {
00139                 $data[] = $p;
00140             }
00141         }
00142         return $data;
00143         }
00144 
00151     public static function encomillar($lista)
00152     {
00153         $items = explode(',', $lista);
00154         return '"'.implode('","',$items).'"';
00155     }
00156 
00166     public static function mkpath($path)
00167     {
00168         if(file_exists($path) or @mkdir($path)) return TRUE;
00169         return (self::mkpath(dirname($path)) and mkdir($path));
00170     }
00171 
00181     public static function removedir($dir)
00182     {
00183         // Obtengo los archivos en el directorio a eliminar
00184         if($files = array_merge(glob("$dir/*"), glob("$dir/.*"))) {
00185             // Elimino cada subdirectorio o archivo
00186             foreach($files as $file) {
00187                 // Si no son los directorios "." o ".." 
00188                 if(!preg_match("/^.*\/?[\.]{1,2}$/",$file)) {
00189                     if(is_dir($file)) {
00190                         return self::removedir($file);
00191                     } elseif(!@unlink($file)) {
00192                         return FALSE;
00193                     }
00194                 }
00195             }
00196         }
00197         return @rmdir($dir);
00198     }
00199         
00206     public static function lcfirst($s) {
00207         $s[0] = strtolower($s[0]);
00208                 return $s;
00209     }
00210 }
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Enumeraciones