1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omatech\Enigma\Database\Query; |
4
|
|
|
|
5
|
|
|
use Omatech\Enigma\CipherSweet\Index; |
6
|
|
|
use Omatech\Enigma\Enigma; |
7
|
|
|
|
8
|
|
|
class Builder extends \Illuminate\Database\Query\Builder |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param string $column |
12
|
|
|
* @param string $value |
13
|
|
|
* @param Index $index |
14
|
|
|
* @param string $boolean |
15
|
|
|
* @return $this |
16
|
|
|
* @throws \ParagonIE\CipherSweet\Exception\BlindIndexNameCollisionException |
17
|
|
|
* @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException |
18
|
|
|
*/ |
19
|
8 |
|
public function whereEnigma(string $column, string $value, Index $index, string $boolean = 'and'): self |
20
|
|
|
{ |
21
|
8 |
|
$this->findByHash($column, $value, $index, $boolean); |
22
|
|
|
|
23
|
8 |
|
return $this; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $column |
28
|
|
|
* @param string $value |
29
|
|
|
* @param Index $index |
30
|
|
|
* @return $this |
31
|
|
|
* @throws \ParagonIE\CipherSweet\Exception\BlindIndexNameCollisionException |
32
|
|
|
* @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException |
33
|
|
|
*/ |
34
|
4 |
|
public function orWhereEnigma(string $column, string $value, Index $index): self |
35
|
|
|
{ |
36
|
4 |
|
return $this->whereEnigma($column, $value, $index, 'or'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $column |
41
|
|
|
* @param string $value |
42
|
|
|
* @param Index $index |
43
|
|
|
* @param string $boolean |
44
|
|
|
* @return Builder |
45
|
|
|
* @throws \ParagonIE\CipherSweet\Exception\BlindIndexNameCollisionException |
46
|
|
|
* @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException |
47
|
|
|
*/ |
48
|
8 |
|
private function findByHash(string $column, string $value, Index $index, string $boolean): self |
49
|
|
|
{ |
50
|
8 |
|
$ids = (new Enigma)->search($this->from, $column, $value, $index); |
51
|
|
|
|
52
|
8 |
|
if ($ids !== null) { |
|
|
|
|
53
|
|
|
$closure = static function (self $query) use ($ids) { |
54
|
8 |
|
$query->whereRaw("id IN ($ids)"); |
55
|
8 |
|
}; |
56
|
|
|
|
57
|
8 |
|
$boolean === 'and' |
58
|
8 |
|
? $this->where($closure) |
59
|
4 |
|
: $this->orWhere($closure); |
60
|
|
|
} |
61
|
|
|
|
62
|
8 |
|
return $this; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|