Ejemplo n.º 1
0
 /**
  * Executes command from GET-filter.
  * Command must be represented as method of this class named as "command".$commandName
  * This method MUST return String WHERE-clause for passed arguments
  * @param $command
  * @param $field
  * @param $arguments
  * @return string
  * @throws \Exception
  */
 protected function exec($command, $field, $arguments)
 {
     $method = 'command' . ucfirst($command);
     if (method_exists($this, $method)) {
         if (is_array($field)) {
             $field = implode(self::CMD_SEPARATOR, $field);
         }
         $field = $this->escaper->field($field);
         if (is_array($arguments)) {
             for ($i = 0; $i < count($arguments); $i++) {
                 $arguments[$i] = $this->escaper->value($arguments[$i]);
             }
         } else {
             $arguments = $this->escaper->value($arguments);
         }
         return '(' . $this->{$method}($this->table . '.' . $field, $arguments) . ')';
     } else {
         // TODO: throw valid Exception
         throw new \Exception("Filter " . $command . " not supported");
     }
 }