28 public function table( $table, $alias =
null ) {
30 $alias ??= $table->getAlias();
31 $table = $table->getRawTables();
34 $table =
new Subquery( $table->getSQL() );
35 } elseif ( $table instanceof
Subquery ) {
36 if ( $alias ===
null ) {
37 throw new \InvalidArgumentException( __METHOD__ .
38 ': Subquery as table must provide an alias.' );
40 } elseif ( !is_string( $table ) ) {
41 throw new \InvalidArgumentException( __METHOD__ .
42 ': $table must be either string, JoinGroup or SelectQueryBuilder' );
44 if ( $alias ===
null ) {
45 $this->tables[] = $table;
46 $this->lastAlias = $table;
48 $this->tables[$alias] = $table;
49 $this->lastAlias = $alias;
65 public function leftJoin( $table, $alias =
null, $conds = [] ) {
66 $this->addJoin(
'LEFT JOIN', $table, $alias, $conds );
81 public function join( $table, $alias =
null, $conds = [] ) {
82 $this->addJoin(
'JOIN', $table, $alias, $conds );
97 public function straightJoin( $table, $alias =
null, $conds = [] ) {
98 $this->addJoin(
'STRAIGHT_JOIN', $table, $alias, $conds );
110 if ( !$this->tables ) {
111 throw new \LogicException( __METHOD__ .
112 ': cannot add a join unless a regular table is added first' );
114 if ( $alias ===
null ) {
115 if ( is_string( $table ) ) {
121 if ( isset( $this->joinConds[$alias] ) ) {
122 throw new \LogicException( __METHOD__ .
123 ": a join with alias \"$alias\" has already been added" );
125 if ( $table instanceof JoinGroup ) {
126 $conflicts = array_intersect_key( $this->joinConds, $table->getRawJoinConds() );
128 $conflict = reset( $conflicts );
129 throw new \LogicException( __METHOD__ .
130 ": a join with alias \"$conflict\" has already been added" );
132 $this->tables[$alias] = $table->getRawTables();
133 $this->joinConds += $table->getRawJoinConds();
134 } elseif ( $table instanceof SelectQueryBuilder ) {
135 $this->tables[$alias] =
new Subquery( $table->getSQL() );
136 } elseif ( is_string( $table ) ) {
137 $this->tables[$alias] = $table;
139 throw new \InvalidArgumentException( __METHOD__ .
140 ': $table must be either string, JoinGroup or SelectQueryBuilder' );
143 $this->lastAlias = $alias;