-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEscaper.php
65 lines (57 loc) · 1.15 KB
/
Escaper.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
62
63
64
65
<?php
namespace ModernPDO;
/**
* Class for escape strings.
*/
class Escaper
{
/**
* Escaper constructor.
*/
public function __construct(
private \PDO $pdo,
) {
}
/**
* Escapes and returns string.
*/
private function string(string $string): string
{
return mb_substr($this->pdo->quote($string), 1, -1);
}
/**
* Escapes and returns table name.
*/
public function table(string $name): string
{
return $this->string($name);
}
/**
* Escapes and returns column name.
*/
public function column(string $name): string
{
return $this->string($name);
}
/**
* Escapes and returns key name.
*/
public function key(string $name): string
{
return $this->string($name);
}
/**
* Escapes and returns string field value.
*/
public function stringValue(string $value): string
{
return $this->string($value);
}
/**
* Escapes and returns bool field value.
*/
public function boolValue(bool $value): string
{
return $value === true ? '1' : '0';
}
}