KeywordList.php 1.06 KB
Newer Older
1 2 3 4
<?php

namespace Doctrine\DBAL\Platforms\Keywords;

5 6 7 8
use function array_flip;
use function array_map;
use function strtoupper;

9 10 11 12 13
/**
 * Abstract interface for a SQL reserved keyword dictionary.
 */
abstract class KeywordList
{
14
    /** @var string[]|null */
15
    private $keywords = null;
16

17
    /**
Benjamin Morel's avatar
Benjamin Morel committed
18
     * Checks if the given word is a keyword of this dialect/vendor platform.
19
     *
Benjamin Morel's avatar
Benjamin Morel committed
20 21
     * @param string $word
     *
22
     * @return bool
23 24 25 26 27 28
     */
    public function isKeyword($word)
    {
        if ($this->keywords === null) {
            $this->initializeKeywords();
        }
29

30 31
        return isset($this->keywords[strtoupper($word)]);
    }
32

Benjamin Morel's avatar
Benjamin Morel committed
33 34 35
    /**
     * @return void
     */
36 37 38 39
    protected function initializeKeywords()
    {
        $this->keywords = array_flip(array_map('strtoupper', $this->getKeywords()));
    }
40

Benjamin Morel's avatar
Benjamin Morel committed
41 42 43
    /**
     * Returns the list of keywords.
     *
44
     * @return string[]
Benjamin Morel's avatar
Benjamin Morel committed
45
     */
46
    abstract protected function getKeywords();
47

48
    /**
Benjamin Morel's avatar
Benjamin Morel committed
49
     * Returns the name of this keyword list.
50
     *
51 52 53 54
     * @return string
     */
    abstract public function getName();
}