public function setOrder($field, $desc = null)
{
if (is_string($field) && strpos($field, ',') !== false) {
$field = explode(',', $field);
}
if (is_array($field)) {
if (!is_null($desc)) {
throw new Exception(['If first argument is array, second argument must not be used', 'arg1' => $field, 'arg2' => $desc]);
}
foreach (array_reverse($field) as $o) {
$this->setOrder($o);
}
return $this;
}
if (is_null($desc) && is_string($field)) {
// no realistic workaround in PHP for 2nd argument being null
$field = trim($field);
if (strpos($field, ' ') !== false) {
list($field, $desc) = array_map('trim', explode(' ', $field, 2));
}
}
$this->order[] = [$field, $desc];
return $this;
}