packages/ztd-query-core/tests/Fake/FakeSqlPlaceholderEscaper.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Fake;
6
7use ZtdQuery\Platform\SqlPlaceholderEscaper;
8
9/**
10 * An escaper that doubles every question mark.
11 *
12 * A rewritten statement may carry text a driver would otherwise read as a
13 * positional placeholder. Which character that is, and how it is escaped,
14 * belongs to the driver; doubling is enough to show what the contract is for.
15 */
16final class FakeSqlPlaceholderEscaper implements SqlPlaceholderEscaper
17{
18    /**
19     * Writes the statement so a driver reads no placeholder that was not meant.
20     *
21     * @param string $sql Statement as it stands
22     *
23     * @return string The statement, with every placeholder character escaped
24     */
25    public function escape(string $sql): string
26    {
27        return str_replace('?', '??', $sql);
28    }
29}
30