-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEscaper.php
More file actions
31 lines (26 loc) · 969 Bytes
/
Escaper.php
File metadata and controls
31 lines (26 loc) · 969 Bytes
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
<?php
declare(strict_types=1);
namespace SimPod\ClickHouseClient\Sql;
use function str_replace;
/**
* phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
*
* @link https://github.com/ClickHouse/clickhouse-jdbc/blob/8481c1323f5de09bb9dbbf67085e5e1b2585756a/src/main/java/ru/yandex/clickhouse/ClickHouseUtil.java
*/
final readonly class Escaper
{
public static function escape(string $s): string
{
return str_replace(
// phpcs:disable SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace.SpaceAfterComma
// phpcs:ignore SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace.SpaceBeforeArrayClose
['\\', "\n", "\t", "\b", "\f", "\r", "\0", "'", '`' ],
['\\\\', "\\n", "\\t", "\\b", "\f", "\\r", "\\0", "\\'", '\\`'],
$s,
);
}
public static function quoteIdentifier(string $s): string
{
return '`' . self::escape($s) . '`';
}
}