1--TEST--
2SQLite3 user authorizer trampoline callback
3--EXTENSIONS--
4sqlite3
5--FILE--
6<?php
7
8class TrampolineTest {
9    public function __call(string $name, array $arguments) {
10        echo 'Trampoline for ', $name, PHP_EOL;
11        if ($arguments[0] == SQLite3::SELECT) {
12            return SQLite3::OK;
13        }
14
15        return SQLite3::DENY;
16    }
17}
18$o = new TrampolineTest();
19$callback = [$o, 'authorizer'];
20
21$db = new SQLite3(':memory:');
22$db->enableExceptions(true);
23
24$db->setAuthorizer($callback);
25
26// This query should be accepted
27var_dump($db->querySingle('SELECT 1;'));
28
29try {
30    // This one should fail
31    var_dump($db->querySingle('CREATE TABLE test (a, b);'));
32} catch (\Exception $e) {
33    echo $e->getMessage() . "\n";
34}
35
36?>
37--EXPECT--
38Trampoline for authorizer
39int(1)
40Trampoline for authorizer
41Unable to prepare statement: not authorized
42