* @package Mammut\DB\Sql */ class Table extends StrictObject implements iSql { protected $root = NULL; protected $database = NULL; protected $schema = NULL; protected $table = NULL; /** * Creates a new SQL table model object. * @param string $table the name of the table * @param string $schema the schema/namespace of the object * @param string $database the database * @param string $root the server element in linked server environments */ public function __construct($table, $schema = NULL, $database = NULL, $root = NULL) { if (is_array($table)) { if (is_string(key($table)) && count($table) == 1) $this->setTable(current($table)); else { $i = count($table) - 1; $this->setTable($table[$i--]); $this->setSchema($i >=0 ? $table[$i--] : NULL); $this->setDatabase($i >=0 ? $table[$i--] : NULL); $this->setRoot($i >=0 ? $table[$i--] : NULL); } } else { $this->setRoot($root); $this->setDatabase($database); $this->setSchema($schema); $this->setTable($table); } } /** * * @param string $root * the database root, possibly the name of the linked server */ public function setRoot($root) { $this->root = $root; } /** * * @return string */ public function getRoot() { return $this->root; } /** * * @param string $schema * the schema of the table */ public function setDatabase($database) { $this->database = $database; } /** * * @return string */ public function getDatabase() { return $this->database; } /** * * @param string $schema * the schema of the table */ public function setSchema($schema) { $this->schema = $schema; } /** * * @return string */ public function getSchema() { return $this->schema; } /** * * @param string $table */ public function setTable($table) { if (!is_string($table)) throw new \InvalidArgumentException('$table has to be a string'); $this->table = $table; } /** * * @return string */ public function getTable() { return $this->table; } public function getSql(iDialect $dialect = NULL) { $tbl = array(); if($this->root) $tbl[] = $this->root; if($this->database) $tbl[] = $this->database; if($this->schema) $tbl[] = $this->schema; $tbl[] = $this->table; return $dialect->quoteIdent($tbl); } }