|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Level23\Druid\DataSources; |
|
5
|
|
|
|
|
6
|
|
|
use Level23\Druid\Types\JoinType; |
|
7
|
|
|
|
|
8
|
|
|
class JoinDataSource implements DataSourceInterface |
|
9
|
|
|
{ |
|
10
|
|
|
protected DataSourceInterface $left; |
|
11
|
|
|
|
|
12
|
|
|
protected DataSourceInterface $right; |
|
13
|
|
|
|
|
14
|
|
|
protected string $rightPrefix; |
|
15
|
|
|
|
|
16
|
|
|
protected string $condition; |
|
17
|
|
|
|
|
18
|
|
|
protected string $joinType; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param \Level23\Druid\DataSources\DataSourceInterface $left |
|
22
|
|
|
* @param \Level23\Druid\DataSources\DataSourceInterface $right |
|
23
|
|
|
* @param string $rightPrefix |
|
24
|
|
|
* @param string $condition |
|
25
|
|
|
* @param string $joinType |
|
26
|
|
|
*/ |
|
27
|
4 |
|
public function __construct( |
|
28
|
|
|
DataSourceInterface $left, |
|
29
|
|
|
DataSourceInterface $right, |
|
30
|
|
|
string $rightPrefix, |
|
31
|
|
|
string $condition, |
|
32
|
|
|
string $joinType |
|
33
|
|
|
) { |
|
34
|
4 |
|
$this->left = $left; |
|
35
|
4 |
|
$this->right = $right; |
|
36
|
4 |
|
$this->rightPrefix = $rightPrefix; |
|
37
|
4 |
|
$this->condition = $condition; |
|
38
|
4 |
|
$this->joinType = JoinType::validate($joinType); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Return the TableDataSource so that it can be used in a druid query. |
|
43
|
|
|
* |
|
44
|
|
|
* @return array<string,string|array<string,string|string[]|array<mixed>>> |
|
45
|
|
|
*/ |
|
46
|
3 |
|
public function toArray(): array |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
3 |
|
'type' => 'join', |
|
50
|
3 |
|
'left' => $this->left->toArray(), |
|
51
|
3 |
|
'right' => $this->right->toArray(), |
|
52
|
3 |
|
'rightPrefix' => $this->rightPrefix, |
|
53
|
3 |
|
'condition' => $this->condition, |
|
54
|
3 |
|
'joinType' => $this->joinType, |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
} |