Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
DbTypes.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ubiquity\db\utils
;
4
14
class
DbTypes
{
15
const
TYPES
=[
"tinyint"
=>0,
"int"
=>0,
"decimal"
=>0,
"float"
=>0,
"double"
=>0,
"smallint"
=>0,
"mediumint"
=>0,
"bigint"
=>0,
16
"date"
=>
"NULL"
,
"time"
=>
"NULL"
,
"datetime"
=>
"CURRENT_TIMESTAMP"
,
"timestamp"
=>
"CURRENT_TIMESTAMP"
,
"year"
=>
"'0000'"
,
17
"tinytext"
=>
"NULL"
,
"text"
=>
"NULL"
,
"mediumtext"
=>
"NULL"
,
"longtext"
=>
"NULL"
,
18
"tinyblob"
=>
"NULL"
,
"blob"
=>
"NULL"
,
"mediumblob"
=>
"NULL"
,
"longblob"
=>
"NULL"
,
19
"char"
=>
"NULL"
,
"varchar"
=>
"NULL"
,
"binary"
=>
"NULL"
,
"varbinary"
=>
"NULL"
,
20
"enum"
=>
"''"
,
"set"
=>
"''"
21
];
22
const
DEFAULT_TYPE
=
"varchar(30)"
;
23
24
protected
static
$typeMatch
=
'@([\s\S]*?)((?:\((?:\d)+\))*?)$@'
;
25
protected
static
$sizeMatch
=
'@(?:[\s\S]*?)(?:\((\d+)\))*?$@'
;
26
protected
static
$intMatch
=
'@^.*?int.*?((?:\((?:\d)+\))*?)$@'
;
27
protected
static
$stringMatch
=
'@^.*?char|text|binary.*?((?:\((?:\d)+\))*?)$@'
;
28
protected
static
$floatMatch
=
'@^.*?float|decimal|numeric|double.*?((?:\((?:\d)+\))*?)$@'
;
29
30
31
protected
static
function
get_
($value,$regex,$pos=1){
32
$matches=[];
33
if
(\preg_match($regex, $value,$matches)) {
34
if
(isset($matches[$pos])){
35
return
$matches[$pos];
36
}
37
}
38
return
null
;
39
}
40
41
public
static
function
isInt
($fieldType){
42
return \preg_match(self::$intMatch, $fieldType);
43
}
44
45
public
static
function
isString
($fieldType){
46
return \preg_match(self::$stringMatch, $fieldType);
47
}
48
49
public
static
function
isFloat
($fieldType){
50
return \preg_match(self::$floatMatch, $fieldType);
51
}
52
53
public
static
function
isBoolean
($fieldType){
54
return
$fieldType===
'tinyint(1)'
|| $fieldType===
'boolean'
|| $fieldType===
'bool'
;
55
}
56
57
public
static
function
getSize
($dbType){
58
return
self::get_
($dbType, self::$sizeMatch);
59
}
60
61
public
static
function
getType
($dbType){
62
return
self::get_
($dbType, self::$typeMatch);
63
}
64
65
public
static
function
asPhpType
($dbType){
66
if
(self::isBoolean($dbType)){
67
return
'bool'
;
68
}
69
if
(self::isInt($dbType)){
70
return
'int'
;
71
}
72
if
(self::isFloat($dbType)){
73
return
'float'
;
74
}
75
if
(self::isString($dbType)){
76
return
'string'
;
77
}
78
return
''
;
79
}
80
81
}
82
Ubiquity\db\utils\DbTypes
Manage Databases types.
Definition
DbTypes.php:14
Ubiquity\db\utils\DbTypes\getSize
static getSize($dbType)
Definition
DbTypes.php:57
Ubiquity\db\utils\DbTypes\isString
static isString($fieldType)
Definition
DbTypes.php:45
Ubiquity\db\utils\DbTypes\DEFAULT_TYPE
const DEFAULT_TYPE
Definition
DbTypes.php:22
Ubiquity\db\utils\DbTypes\$intMatch
static $intMatch
Definition
DbTypes.php:26
Ubiquity\db\utils\DbTypes\asPhpType
static asPhpType($dbType)
Definition
DbTypes.php:65
Ubiquity\db\utils\DbTypes\TYPES
const TYPES
Definition
DbTypes.php:15
Ubiquity\db\utils\DbTypes\get_
static get_($value, $regex, $pos=1)
Definition
DbTypes.php:31
Ubiquity\db\utils\DbTypes\isInt
static isInt($fieldType)
Definition
DbTypes.php:41
Ubiquity\db\utils\DbTypes\$sizeMatch
static $sizeMatch
Definition
DbTypes.php:25
Ubiquity\db\utils\DbTypes\$typeMatch
static $typeMatch
Definition
DbTypes.php:24
Ubiquity\db\utils\DbTypes\$stringMatch
static $stringMatch
Definition
DbTypes.php:27
Ubiquity\db\utils\DbTypes\isBoolean
static isBoolean($fieldType)
Definition
DbTypes.php:53
Ubiquity\db\utils\DbTypes\isFloat
static isFloat($fieldType)
Definition
DbTypes.php:49
Ubiquity\db\utils\DbTypes\$floatMatch
static $floatMatch
Definition
DbTypes.php:28
Ubiquity\db\utils\DbTypes\getType
static getType($dbType)
Definition
DbTypes.php:61
Ubiquity\db\utils
Definition
DbTypes.php:3
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity
src
Ubiquity
db
utils
DbTypes.php
Generated on Sun Dec 10 2023 15:04:21 for
Ubiquity
by
doxygen
1.9.8