packages/sql-semantics-mysql/src/Statement/Account/Privilege/Level/ObjectKind.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\MySql\Statement\Account\Privilege\Level;
6
7/**
8 * The kind of object the ON clause of GRANT and REVOKE names: a table (the default), a stored function or a stored procedure.
9 *
10 * Mirrors Acl_type. `ON TABLE` and `ON` without a kind are the same request.
11 * Source: https://dev.mysql.com/doc/refman/8.4/en/grant.html#grant-object-quoting.
12 *
13 * @visibility public
14 * @example Reading the keyword of a kind
15 *     [\SqlSemantics\Platform\MySql\Statement\Account\Privilege\Level\ObjectKind::Procedure->keyword(), \SqlSemantics\Platform\MySql\Statement\Account\Privilege\Level\ObjectKind::Table->keyword()] // => ['PROCEDURE', null]
16 */
17enum ObjectKind
18{
19    case Table;
20    case Function;
21    case Procedure;
22
23    /**
24     * Answers the keyword the writer emits: none for a table.
25     */
26    public function keyword(): ?string
27    {
28        return match ($this) {
29            self::Table => null,
30            self::Function => 'FUNCTION',
31            self::Procedure => 'PROCEDURE',
32        };
33    }
34}
35