Exemplo n.º 1
0
    private static $operators = ["STRING_NEQ" => ["!=", "not", "is not"], "NUMERIC_NEQ" => ["!=", "not", "is not"], "DATETIME_NEQ" => ["!=", "<>", "not", "is not"], "NUMERIC_LTE" => ["<="], "DATETIME_LTE" => ["<="], "NUMERIC_GTE" => [">="], "DATETIME_GTE" => [">="], "NUMERIC_LT" => ["<", "less than"], "DATETIME_LT" => ["<", "before"], "NUMERIC_GT" => [">", "more than"], "DATETIME_GT" => [">", "after"], "STRING_LIKE" => ["~", "like"], "STRING_EQ" => ["=", "equals", "is"], "NUMERIC_EQ" => ["=", "equals", "is"], "DATETIME_EQ" => ["=", "on", "is", "at"], "IN" => ["in"]];
    private static $operatorTokenAssociations = ["T_OP_NEQ" => ["STRING_NEQ", "NUMERIC_NEQ", "DATETIME_NEQ"], "T_OP_EQ" => ["STRING_EQ", "NUMERIC_EQ", "DATETIME_EQ"], "T_OP_GTE" => ["NUMERIC_GTE", "DATETIME_GTE"], "T_OP_GT" => ["NUMERIC_GT", "DATETIME_GT"], "T_OP_LTE" => ["NUMERIC_LTE", "DATETIME_LTE"], "T_OP_LT" => ["NUMERIC_LT", "DATETIME_LT"], "T_OP_LIKE" => ["STRING_LIKE"], "T_OP_IN" => ["IN"]];
    /**
     * @var bool
     */
    private static $initialised = false;
    public static function initialize()
    {
        if (self::$initialised) {
            return;
        }
        $tokens = [];
        foreach (self::$operatorTokenAssociations as $token => $operators) {
            $strings = [];
            foreach ($operators as $operator) {
                $strings = array_merge($strings, self::$operators[$operator]);
            }
            $strings = array_unique($strings);
            usort($strings, function ($a, $b) {
                return strlen($a) - strlen($b);
            });
            $regex = "/^(" . implode("|", $strings) . ")(\\s|\$)/i";
            $tokens[$regex] = $token;
        }
        self::$terminalTokens = array_merge($tokens, self::$baseTokens);
        self::$initialised = true;
    }
}
// Initialise the static class
Tokens::initialize();