public function join($join, $condition = null, $type = 'INNER')
{
if (empty($condition)) {
// 如果为组数,则循环调用join
foreach ($join as $key => $value) {
if (is_array($value) && 2 <= count($value)) {
$this->join($value[0], $value[1], isset($value[2]) ? $value[2] : $type);
}
}
} else {
// 传入的表名为数组
if (is_array($join)) {
if (0 !== ($key = key($join))) {
// 设置了键名则键名为表名,键值作为表的别名
$table = [$key => array_shift($join)];
$this->alias($table);
} else {
$table = array_shift($join);
}
} else {
$table = trim($join);
if (strpos($table, ' ') && !strpos($table, ')')) {
list($table, $alias) = explode(' ', $table);
$table = [$table => $alias];
$this->alias($table);
}
}
$this->options['join'][] = [$table, strtoupper($type), $condition];
}
return $this;
}