1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\FluentAQL\Clauses; |
6
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\Expression; |
8
|
|
|
use LaravelFreelancerNL\FluentAQL\QueryBuilder; |
9
|
|
|
|
10
|
|
|
class ReplaceClause extends Clause |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array<mixed>|string|object |
14
|
|
|
*/ |
15
|
|
|
protected array|string|object $document; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array<mixed>|string|object |
19
|
|
|
*/ |
20
|
|
|
protected array|string|object $with; |
21
|
|
|
|
22
|
|
|
protected string|QueryBuilder|Expression $collection; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param array<mixed>|string|object $document |
26
|
|
|
* @param array<mixed>|string|object $with |
27
|
|
|
*/ |
28
|
1 |
|
public function __construct( |
29
|
|
|
array|string|object $document, |
30
|
|
|
array|string|object $with, |
31
|
|
|
string|QueryBuilder|Expression $collection |
32
|
|
|
) { |
33
|
1 |
|
parent::__construct(); |
34
|
|
|
|
35
|
1 |
|
$this->document = $document; |
36
|
1 |
|
$this->with = $with; |
37
|
1 |
|
$this->collection = $collection; |
38
|
|
|
} |
39
|
|
|
|
40
|
1 |
|
public function compile(QueryBuilder $queryBuilder): string |
41
|
|
|
{ |
42
|
1 |
|
$this->document = $queryBuilder->normalizeArgument( |
43
|
1 |
|
$this->document, |
44
|
1 |
|
['RegisteredVariable', 'Key', 'Object', 'Bind'] |
45
|
|
|
); |
46
|
|
|
|
47
|
1 |
|
$this->with = $queryBuilder->normalizeArgument($this->with, ['Object', 'Bind']); |
48
|
|
|
|
49
|
1 |
|
$this->collection = $queryBuilder->normalizeArgument($this->collection, ['Collection', 'Bind']); |
50
|
1 |
|
$queryBuilder->registerCollections($this->collection->compile($queryBuilder)); |
51
|
|
|
|
52
|
|
|
|
53
|
1 |
|
return "REPLACE {$this->document->compile($queryBuilder)} " . |
54
|
1 |
|
"WITH {$this->with->compile($queryBuilder)} " . |
55
|
1 |
|
"IN {$this->collection->compile($queryBuilder)}"; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|