packages/ztd-query-core/src/Exception/UnsupportedSqlException.php

1<?php
2
3declare(strict_types=1);
4
5namespace ZtdQuery\Exception;
6
7use Throwable;
8
9/**
10 * Refuses a statement ZTD cannot simulate.
11 *
12 * ZTD never writes to the database, so a statement it cannot work out the
13 * effect of is refused rather than run. The statement is carried whole,
14 * because what a caller needs in order to act on this is which statement was
15 * refused, not only that one was.
16 */
17final class UnsupportedSqlException extends SimulationException
18{
19    /** @var string The statement being refused, as written */
20    private string $sql;
21
22    /** @var string What about it ZTD cannot simulate */
23    private string $category;
24
25    /**
26     * @param string $sql The statement being refused, as written
27     * @param string $category What about it ZTD cannot simulate
28     * @param Throwable|null $previous What made this impossible, where something did
29     */
30    public function __construct(string $sql, string $category = 'Unsupported', ?Throwable $previous = null)
31    {
32        parent::__construct(sprintf('ZTD Write Protection: %s SQL statement.', $category), 0, $previous);
33        $this->sql = $sql;
34        $this->category = $category;
35    }
36
37    /**
38     * Answers the statement being refused.
39     *
40     * @return string The statement, as written
41     */
42    public function getSql(): string
43    {
44        return $this->sql;
45    }
46
47    /**
48     * Answers what about the statement ZTD cannot simulate.
49     *
50     * @return string What was refused
51     */
52    public function getCategory(): string
53    {
54        return $this->category;
55    }
56}
57