/** * Retrieves an operator from the available operators. * * Throws an AdldapException if no operator is found. * * @param string $operator * * @throws InvalidQueryOperatorException * * @return string */ private function validateOperator($operator) { $operators = Operator::all(); $key = array_search(strtolower($operator), $operators); if ($key !== false && array_key_exists($key, $operators)) { return $operators[$key]; } $operators = implode(', ', $operators); $message = "Operator: {$operator} cannot be used in an LDAP query. Available operators are: {$operators}"; throw new InvalidQueryOperatorException($message); }
/** * Assembles a single where query based * on its operator and returns it. * * @param Where $where * * @return string|null */ protected function compileWhere(Where $where) { // The compile function prefix. $prefix = 'compile'; // Get the operator from the where. $operator = $where->getOperator(); // Get the name of the operator. $name = array_search($operator, Operator::all()); if ($name !== false) { // If the name was found we'll camel case it // to run it through the compile method. $method = $prefix . ucfirst($name); // Make sure the compile method exists for the operator. if (method_exists($this, $method)) { return $this->{$method}($where->getField(), $where->getValue()); } } return; }