-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractPlaceholderHandler.php
58 lines (45 loc) · 1.13 KB
/
AbstractPlaceholderHandler.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
<?php
namespace FpDbTest;
use Exception;
abstract class AbstractPlaceholderHandler
{
private const SUPPORTS_TYPES = [
'float',
'int',
'string',
'bool',
'NULL',
];
abstract function getSpecifier(): string;
abstract function handle($value);
function doHandle($value)
{
if ($value === Database::SKIP) {
return $value;
}
if (in_array(Nullable::class, class_uses($this)) && $value === null) {
return 'NULL';
}
return $this->handle($value);
}
public function handlePrimitive($value)
{
$type = gettype($value);
if (!in_array($type, self::SUPPORTS_TYPES)) {
throw new Exception("Unsupported type $type for value $value");
}
if ($type == 'string') {
return "'" . $value . "'";
}
if ($type == 'boolean') {
return (int) $value;
}
if ($value === null) {
return 'NULL';
}
}
public function escapeId(string $string): string
{
return "`$string`";
}
}