-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathHelpers.php
More file actions
69 lines (58 loc) · 1.68 KB
/
Helpers.php
File metadata and controls
69 lines (58 loc) · 1.68 KB
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
66
67
68
69
<?php
declare(strict_types=1);
namespace CzProject\SqlGenerator;
use DateTimeInterface;
class Helpers
{
/**
* @throws StaticClassException
*/
public function __construct()
{
throw new StaticClassException('This is static class.');
}
/**
* @throws InvalidArgumentException
* @see https://api.dibiphp.com/3.0/source-Dibi.Translator.php.html#174
*/
public static function formatValue(mixed $value, IDriver $driver): string
{
if (is_string($value)) {
return $driver->escapeText($value);
}
elseif (is_int($value)) {
return (string)$value;
}
elseif (is_float($value)) {
return rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.');
}
elseif (is_bool($value)) {
return $driver->escapeBool($value);
}
elseif ($value === NULL) {
return 'NULL';
}
elseif ($value instanceof DateTimeInterface) {
return $driver->escapeDateTime($value);
}
throw new InvalidArgumentException("Unsupported value type.");
}
public static function escapeTableName(TableName|string $tableName, IDriver $driver): string
{
if ($tableName instanceof TableName) {
return $tableName->toString($driver);
}
return $driver->escapeIdentifier($tableName);
}
public static function createTableName(TableName|string $tableName): TableName|string
{
if (is_string($tableName) && strpos($tableName, '.')) {
return TableName::create($tableName);
}
return $tableName;
}
public static function normalizeNewLines(string $s): string
{
return str_replace(["\r\n", "\r"], "\n", $s);
}
}