29 public function table( $table, $alias =
null ) {
31 $alias ??= $table->getAlias();
32 $table = $table->getRawTables();
35 $table =
new Subquery( $table->getSQL() );
36 } elseif ( $table instanceof
Subquery ) {
37 if ( $alias ===
null ) {
38 throw new \InvalidArgumentException( __METHOD__ .
39 ': Subquery as table must provide an alias.' );
41 } elseif ( !is_string( $table ) ) {
42 throw new \InvalidArgumentException( __METHOD__ .
43 ': $table must be either string, JoinGroup or SelectQueryBuilder' );
45 if ( $alias ===
null ) {
46 $this->tables[] = $table;
47 $this->lastAlias = $table;
49 $this->tables[$alias] = $table;
50 $this->lastAlias = $alias;
66 public function leftJoin( $table, $alias =
null, $conds = [] ) {
67 $this->addJoin(
'LEFT JOIN', $table, $alias, $conds );
82 public function join( $table, $alias =
null, $conds = [] ) {
83 $this->addJoin(
'JOIN', $table, $alias, $conds );
98 public function straightJoin( $table, $alias =
null, $conds = [] ) {
99 $this->addJoin(
'STRAIGHT_JOIN', $table, $alias, $conds );
111 if ( !$this->tables ) {
112 throw new \LogicException( __METHOD__ .
113 ': cannot add a join unless a regular table is added first' );
115 if ( $alias ===
null ) {
116 if ( is_string( $table ) ) {
122 if ( isset( $this->joinConds[$alias] ) ) {
123 throw new \LogicException( __METHOD__ .
124 ": a join with alias \"$alias\" has already been added" );
126 if ( $table instanceof JoinGroup ) {
127 $conflicts = array_intersect_key( $this->joinConds, $table->getRawJoinConds() );
129 $conflict = reset( $conflicts );
130 throw new \LogicException( __METHOD__ .
131 ": a join with alias \"$conflict\" has already been added" );
133 $this->tables[$alias] = $table->getRawTables();
134 $this->joinConds += $table->getRawJoinConds();
135 } elseif ( $table instanceof SelectQueryBuilder ) {
136 $this->tables[$alias] =
new Subquery( $table->getSQL() );
137 } elseif ( is_string( $table ) ) {
138 $this->tables[$alias] = $table;
140 throw new \InvalidArgumentException( __METHOD__ .
141 ': $table must be either string, JoinGroup or SelectQueryBuilder' );
144 $this->lastAlias = $alias;