1<?php
2
3namespace Doctrine\DBAL\Platforms\Keywords;
4
5use function array_flip;
6use function array_map;
7use function strtoupper;
8
9/**
10 * Abstract interface for a SQL reserved keyword dictionary.
11 */
12abstract class KeywordList
13{
14    /** @var string[]|null */
15    private $keywords;
16
17    /**
18     * Checks if the given word is a keyword of this dialect/vendor platform.
19     *
20     * @param string $word
21     *
22     * @return bool
23     */
24    public function isKeyword($word)
25    {
26        if ($this->keywords === null) {
27            $this->initializeKeywords();
28        }
29
30        return isset($this->keywords[strtoupper($word)]);
31    }
32
33    /**
34     * @return void
35     */
36    protected function initializeKeywords()
37    {
38        $this->keywords = array_flip(array_map('strtoupper', $this->getKeywords()));
39    }
40
41    /**
42     * Returns the list of keywords.
43     *
44     * @return string[]
45     */
46    abstract protected function getKeywords();
47
48    /**
49     * Returns the name of this keyword list.
50     *
51     * @return string
52     */
53    abstract public function getName();
54}
55