JoinClause.php
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace Illuminate\Database\Query;
use Closure;
class JoinClause extends Builder
{
/**
* The type of join being performed.
*
* @var string
*/
public $type;
/**
* The table the join clause is joining to.
*
* @var string
*/
public $table;
/**
* The connection of the parent query builder.
*
* @var \Illuminate\Database\ConnectionInterface
*/
protected $parentConnection;
/**
* The grammar of the parent query builder.
*
* @var \Illuminate\Database\Query\Grammars\Grammar
*/
protected $parentGrammar;
/**
* The processor of the parent query builder.
*
* @var \Illuminate\Database\Query\Processors\Processor
*/
protected $parentProcessor;
/**
* The class name of the parent query builder.
*
* @var string
*/
protected $parentClass;
/**
* Create a new join clause instance.
*
* @param \Illuminate\Database\Query\Builder $parentQuery
* @param string $type
* @param string $table
* @return void
*/
public function __construct(Builder $parentQuery, $type, $table)
{
$this->type = $type;
$this->table = $table;
$this->parentClass = get_class($parentQuery);
$this->parentGrammar = $parentQuery->getGrammar();
$this->parentProcessor = $parentQuery->getProcessor();
$this->parentConnection = $parentQuery->getConnection();
parent::__construct(
$this->parentConnection, $this->parentGrammar, $this->parentProcessor
);
}
/**
* Add an "on" clause to the join.
*
* On clauses can be chained, e.g.
*
* $join->on('contacts.user_id', '=', 'users.id')
* ->on('contacts.info_id', '=', 'info.id')
*
* will produce the following SQL:
*
* on `contacts`.`user_id` = `users`.`id` and `contacts`.`info_id` = `info`.`id`
*
* @param \Closure|string $first
* @param string|null $operator
* @param \Illuminate\Database\Query\Expression|string|null $second
* @param string $boolean
* @return $this
*
* @throws \InvalidArgumentException
*/
public function on($first, $operator = null, $second = null, $boolean = 'and')
{
if ($first instanceof Closure) {
return $this->whereNested($first, $boolean);
}
return $this->whereColumn($first, $operator, $second, $boolean);
}
/**
* Add an "or on" clause to the join.
*
* @param \Closure|string $first
* @param string|null $operator
* @param \Illuminate\Database\Query\Expression|string|null $second
* @return \Illuminate\Database\Query\JoinClause
*/
public function orOn($first, $operator = null, $second = null)
{
return $this->on($first, $operator, $second, 'or');
}
/**
* Get a new instance of the join clause builder.
*
* @return \Illuminate\Database\Query\JoinClause
*/
public function newQuery()
{
return new static($this->newParentQuery(), $this->type, $this->table);
}
/**
* Create a new query instance for sub-query.
*
* @return \Illuminate\Database\Query\Builder
*/
protected function forSubQuery()
{
return $this->newParentQuery()->newQuery();
}
/**
* Create a new parent query instance.
*
* @return \Illuminate\Database\Query\Builder
*/
protected function newParentQuery()
{
$class = $this->parentClass;
return new $class($this->parentConnection, $this->parentGrammar, $this->parentProcessor);
}
}