-
Notifications
You must be signed in to change notification settings - Fork 0
/
Format.php
61 lines (54 loc) · 1.42 KB
/
Format.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php namespace Devtools;
use Devtools\DateFormat;
class Format
{
public static function snakeToCamelCase($underscore)
{
return preg_replace_callback(
"/(_\\w)/u",
function ($match) {
return strToUpper(substr($match[0], 1));
},
$underscore
);
}
public static function camelToSnakeCase($camelCase)
{
return preg_replace_callback(
"/([A-Z])/u",
function ($match) {
return '_'.strtolower($match[0]);
},
$camelCase
);
}
public static function sql($dirty)
{
return self::stripWhitespace($dirty);
}
public static function stripWhitespace($dirty)
{
return preg_replace("/[ \\t\\n]+/u", " ", $dirty);
}
public static function stringify($array, $force = false, $quotation="'")
{
$ret = "";
if (!is_array($array)) {
$array = array($array);
}
foreach ($array as $element) {
if (!empty($ret)) {
$ret .= ",";
}
$ret .= (!$force && is_numeric($element))
? $element
: $quotation.$element.$quotation;
}
return $ret;
}
public static function mysqlDate($date)
{
$mysql = new DateFormat\MySQL();
return $mysql->from(new DateFormat\US($date))->__toString();
}
}