Beispiel #1
0
 private function condition($type, $wheres, $op = 'AND')
 {
     $op = strtoupper($op);
     if ($op != 'AND' && $op != 'OR') {
         throw new DBException(L('Bad logical operator specified') . ': ' . $op);
     }
     if (is_array($wheres)) {
         $d = [];
         foreach ($wheres as $k => $v) {
             if (is_array($v)) {
                 if (empty($v[2]) && $v[1][0] != 'I' && $v[1][1] != 'S') {
                     throw new DBException(L('No right value') . ' #' . $k . ': ' . $v[0] . ' ' . $v[1]);
                 }
                 if (!in_array(strtoupper($v[1]), ['=', '!=', '<', '<=', '>', '>=', 'LIKE', 'RLIKE', 'IS NULL', 'IS NOT NULL'])) {
                     throw new DBException(L('Bad conditional') . ' #' . $k . ': ' . $v[1]);
                 }
                 $d[] = $v[0] . ' ' . strtoupper($v[1]) . (!empty($v[2]) ? ' ' . ($v[2] == '?' ? $v[2] : "'" . str_replace(["\r", "\n", "\t", "", ""], ['\\r', '\\n', '\\t', '\\x1a', '\\x00'], addslashes(strtoupper($v[1]) == 'LIKE' ? DS::like($v[2]) : (is_array($v[2]) || is_object($v[2]) ? json_encode($v[2]) : $v[2]))) . "'") : '');
             } else {
                 $d[] = $v;
             }
         }
         if (!empty($d)) {
             $this->{$type}[] = '(' . implode(' ' . strtoupper($op) . ' ', $d) . ')';
         }
     } else {
         $this->{$type}[] = $wheres;
     }
     return $this;
 }