public function setSource($source, $fields = null)
{
// Set DSQL
if ($source instanceof DB_dsql) {
$this->dq = $source;
return $this;
}
// SimpleXML and other objects
if (is_object($source)) {
if ($source instanceof Model) {
throw $this->exception('Use setModel() for Models');
} elseif ($source instanceof Controller) {
throw $this->exception('Use setController() for Controllers');
} elseif ($source instanceof Iterator || $source instanceof Closure) {
$this->iter = $source;
return $this;
}
// Cast non-iterable objects into array
$source = (array) $source;
}
// Set Array as a data source
if (is_array($source)) {
$m = $this->setModel('Model', $fields);
$m->setSource('Array', $source);
return $this;
}
// Set manually
$this->dq = $this->app->db->dsql();
$this->dq->table($source)->field($fields ?: '*');
return $this;
}