/** * Creates a Table object. * * @param string[] $table * * @return Table */ public static function createTable($table) { $tableName = $table; if (\is_array($table)) { $tableName = \current($table); $tableAlias = \key($table); } $newTable = new Table($tableName); if (isset($tableAlias) && !is_numeric($tableAlias)) { $newTable->setAlias($tableAlias); } return $newTable; }
/** * @static * @param $arg * @return Table * @throws Exception */ public static function prepareTable($arg) { if (is_string($arg)) { $arg = new Table($arg); } else { if (is_array($arg)) { $v = array_values($arg); $k = array_keys($arg); $arg = new Table($v[0]); $arg->setAlias($k[0]); } else { if (!is_a($arg, '\\RBM\\SqlQuery\\Table')) { throw new Exception('Invalid table provided, string or \\RBM\\SqlQuery\\Table expected : ' . gettype($arg) . ' given\\n'); } } } return $arg; }
/** * Joins table to SQL query * @param Table $table * @param string $relName name of the relation * @return Table provides a fluent interface */ public function join(Table $table, $relName = NULL) { if ($relName === NULL) { $relName = $this->reflection->getRelationWith($table->reflection) or function () { throw new Exception("No relation exists between table '" . $this->getName() . "' and '" . $table->getName() . "'."); }; } if (isset($this->joined[$relName])) { throw new Exception("Tables '" . $this->getName() . "' and '" . $table->getName() . "' are already joined."); } if (\in_array($this, $table->joined)) { throw new Exception("Circular reference between tables '" . $this->getName() . "' and '" . $table->getName() . "'."); } $table->setAlias(\implode('', array($this->alias, self::ALIAS_DELIM, $relName))); $this->joined[$relName] = $table; $this->invalidateQuery(); return $this; }