1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: admin |
5
|
|
|
* Date: 08.05.2018 |
6
|
|
|
* Time: 15:25 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace sonrac\Arango\Query; |
10
|
|
|
|
11
|
|
|
use Closure; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* New JoinClause for other extend |
15
|
|
|
* Class JoinClause |
16
|
|
|
* @package sonrac\Arango\Query |
17
|
|
|
*/ |
18
|
|
|
class JoinClause extends QueryBuilder |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The type of join being performed. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
public $type; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The table the join clause is joining to. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
public $table; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The parent query builder instance. |
36
|
|
|
* |
37
|
|
|
* @var QueryBuilder |
38
|
|
|
*/ |
39
|
|
|
private $parentQuery; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create a new join clause instance. |
43
|
|
|
* |
44
|
|
|
* @param QueryBuilder $parentQuery |
45
|
|
|
* @param string $type |
46
|
|
|
* @param string $table |
47
|
|
|
* @return void |
|
|
|
|
48
|
|
|
*/ |
49
|
|
|
public function __construct(QueryBuilder $parentQuery, $type, $table) |
50
|
|
|
{ |
51
|
|
|
$this->type = $type; |
52
|
|
|
$this->table = $table; |
53
|
|
|
$this->parentQuery = $parentQuery; |
54
|
|
|
|
55
|
|
|
parent::__construct( |
56
|
|
|
$parentQuery->getConnection(), $parentQuery->getGrammar(), $parentQuery->getProcessor() |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Add an "on" clause to the join. |
62
|
|
|
* |
63
|
|
|
* On clauses can be chained, e.g. |
64
|
|
|
* |
65
|
|
|
* $join->on('contacts.user_id', '=', 'users.id') |
66
|
|
|
* ->on('contacts.info_id', '=', 'info.id') |
67
|
|
|
* |
68
|
|
|
* will produce the following SQL: |
69
|
|
|
* |
70
|
|
|
* on `contacts`.`user_id` = `users`.`id` and `contacts`.`info_id` = `info`.`id` |
71
|
|
|
* |
72
|
|
|
* @param \Closure|string $first |
73
|
|
|
* @param string|null $operator |
74
|
|
|
* @param string|null $second |
75
|
|
|
* @param string $boolean |
76
|
|
|
* @return $this |
77
|
|
|
* |
78
|
|
|
* @throws \InvalidArgumentException |
79
|
|
|
*/ |
80
|
|
|
public function on($first, $operator = null, $second = null, $boolean = 'and') |
81
|
|
|
{ |
82
|
|
|
if ($first instanceof Closure) { |
83
|
|
|
return $this->whereNested($first, $boolean); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $this->whereColumn($first, $operator, $second, $boolean); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Add an "or on" clause to the join. |
91
|
|
|
* |
92
|
|
|
* @param \Closure|string $first |
93
|
|
|
* @param string|null $operator |
94
|
|
|
* @param string|null $second |
95
|
|
|
* @return JoinClause |
96
|
|
|
*/ |
97
|
|
|
public function orOn($first, $operator = null, $second = null) |
98
|
|
|
{ |
99
|
|
|
return $this->on($first, $operator, $second, 'or'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get a new instance of the join clause builder. |
104
|
|
|
* |
105
|
|
|
* @return JoinClause |
106
|
|
|
*/ |
107
|
|
|
public function newQuery() |
108
|
|
|
{ |
109
|
|
|
return new static($this->parentQuery, $this->type, $this->table); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Create a new query instance for sub-query. |
114
|
|
|
* |
115
|
|
|
* @return QueryBuilder |
116
|
|
|
*/ |
117
|
|
|
protected function forSubQuery() |
118
|
|
|
{ |
119
|
|
|
return $this->parentQuery->newQuery(); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.