ulmus/src/Query/From.php
2020-02-05 16:19:57 -05:00

45 lines
854 B
PHP

<?php
namespace Ulmus\Query;
class From extends Fragment {
public int $order = -80;
public array $tables = [];
public function set(array $tables) : self
{
$this->tables = $tables;
return $this;
}
public function add(/* array|string */ $table) : self
{
foreach((array) $table as $alias => $name) {
$this->tables[$alias] = $name;
}
return $this;
}
public function render() : string
{
return $this->renderSegments([
'FROM', $this->renderTables(),
]);
}
protected function renderTables() : string
{
$list = [];
foreach((array) $this->tables as $alias => $table) {
$list[] = ! is_numeric($alias) ? "$table $alias" : $table;
}
return implode(", ", $list);
}
}