SqlParser\Context::isKeyword PHP Method

isKeyword() public static method

Checks if the given string is a keyword.
public static isKeyword ( string $str, boolean $isReserved = false ) : integer
$str string String to be checked.
$isReserved boolean Checks if the keyword is reserved.
return integer
    public static function isKeyword($str, $isReserved = false)
    {
        $str = strtoupper($str);
        if (isset(static::$KEYWORDS[$str])) {
            if ($isReserved) {
                if (!(static::$KEYWORDS[$str] & Token::FLAG_KEYWORD_RESERVED)) {
                    return null;
                }
            }
            return static::$KEYWORDS[$str];
        }
        return null;
    }

Usage Example

Example #1
0
 public function testIsKeyword()
 {
     $this->assertEquals(1 | Token::FLAG_KEYWORD_RESERVED, Context::isKeyword('SELECT'));
     $this->assertEquals(1 | Token::FLAG_KEYWORD_RESERVED, Context::isKeyword('ALL'));
     $this->assertEquals(1 | Token::FLAG_KEYWORD_RESERVED, Context::isKeyword('DISTINCT'));
     $this->assertEquals(1 | Token::FLAG_KEYWORD_RESERVED | Token::FLAG_KEYWORD_COMPOSED | Token::FLAG_KEYWORD_KEY, Context::isKeyword('PRIMARY KEY'));
     $this->assertEquals(1 | Token::FLAG_KEYWORD_RESERVED | Token::FLAG_KEYWORD_COMPOSED, Context::isKeyword('CHARACTER SET'));
     $this->assertEquals(1 | Token::FLAG_KEYWORD_RESERVED, Context::isKeyword('FROM', true));
     $this->assertEquals(null, Context::isKeyword('MODIFY', true));
     $this->assertEquals(null, Context::isKeyword('foo'));
     $this->assertEquals(null, Context::isKeyword('bar baz'));
 }
All Usage Examples Of SqlParser\Context::isKeyword