28 public function table( $table, $alias =
null ) {
30 if ( $alias ===
null ) {
31 $alias = $table->getAlias();
33 $table = $table->getRawTables();
35 if ( $alias ===
null ) {
38 $table =
new Subquery( $table->getSQL() );
39 } elseif ( !is_string( $table ) ) {
40 throw new \InvalidArgumentException( __METHOD__ .
41 ': $table must be either string, JoinGroup or SelectQueryBuilder' );
43 if ( $alias ===
null ) {
44 $this->tables[] = $table;
45 $this->lastAlias = $table;
47 $this->tables[$alias] = $table;
48 $this->lastAlias = $alias;
64 public function leftJoin( $table, $alias =
null, $conds = [] ) {
65 $this->addJoin(
'LEFT JOIN', $table, $alias, $conds );
80 public function join( $table, $alias =
null, $conds = [] ) {
81 $this->addJoin(
'JOIN', $table, $alias, $conds );
96 public function straightJoin( $table, $alias =
null, $conds = [] ) {
97 $this->addJoin(
'STRAIGHT_JOIN', $table, $alias, $conds );
109 if ( !$this->tables ) {
110 throw new \LogicException( __METHOD__ .
111 ': cannot add a join unless a regular table is added first' );
113 if ( $alias ===
null ) {
114 if ( is_string( $table ) ) {
120 if ( isset( $this->joinConds[$alias] ) ) {
121 throw new \LogicException( __METHOD__ .
122 ": a join with alias \"$alias\" has already been added" );
124 if ( $table instanceof JoinGroup ) {
125 $conflicts = array_intersect_key( $this->joinConds, $table->getRawJoinConds() );
127 $conflict = reset( $conflicts );
128 throw new \LogicException( __METHOD__ .
129 ": a join with alias \"$conflict\" has already been added" );
131 $this->tables[$alias] = $table->getRawTables();
132 $this->joinConds += $table->getRawJoinConds();
133 } elseif ( $table instanceof SelectQueryBuilder ) {
134 $this->tables[$alias] =
new Subquery( $table->getSQL() );
135 } elseif ( is_string( $table ) ) {
136 $this->tables[$alias] = $table;
138 throw new \InvalidArgumentException( __METHOD__ .
139 ': $table must be either string, JoinGroup or SelectQueryBuilder' );
142 $this->lastAlias = $alias;