KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
util.php
Ir a la documentación de este archivo.
1 <?php
30 class Util
31 {
32 
40  public static function camelcase($s, $lower=FALSE)
41  {
42  // Notacion lowerCamelCase
43  if ($lower) {
44  return self::lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $s))));
45  }
46 
47  return str_replace(' ', '', ucwords(str_replace('_', ' ', $s)));
48  }
49 
57  public static function uncamelize($str)
58  {
59  return self::smallcase($str);
60  }
61 
67  public static function smallcase($s)
68  {
69  return strtolower(preg_replace('/([A-Z])/', "_\\1", self::lcfirst($s)));
70  }
71 
77  public static function underscore($s)
78  {
79  return strtr($s, ' ', '_');
80  }
81 
87  public static function dash($s)
88  {
89  return strtr($s, ' ', '-');
90  }
91 
97  public static function humanize($s)
98  {
99  return strtr($s, '_-', ' ');
100  }
101 
111  public static function array_merge_overwrite($a1, $a2)
112  {
113  return $a2 + $a1;
114  }
115 
124  public static function array_insert(&$array, $position, $insert)
125  {
126  array_splice($array, $position, 0, $insert);
127  }
128 
135  public static function getParams($params)
136  {
137  $data = array();
138  foreach ($params as $p) {
139  if (is_string($p)) {
140  $match = explode(': ', $p, 2);
141  if (isset($match[1])) {
142  $data[$match[0]] = $match[1];
143  } else {
144  $data[] = $p;
145  }
146  } else {
147  $data[] = $p;
148  }
149  }
150  return $data;
151  }
152 
159  public static function encomillar($lista)
160  {
161  $items = explode(',', $lista);
162  return '"' . implode('","', $items) . '"';
163  }
164 
174  public static function mkpath($path)
175  {
176  return FileUtil::mkdir($path);
177  }
178 
188  public static function removedir($dir)
189  {
190  return FileUtil::rmdir($dir);
191  }
192 
199  public static function lcfirst($s)
200  {
201  $s[0] = strtolower($s[0]);
202  return $s;
203  }
204 
205 }