1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\FluentAQL\Clauses; |
6
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\FluentAQL\Exceptions\ExpressionTypeException; |
8
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\Expression; |
9
|
|
|
use LaravelFreelancerNL\FluentAQL\QueryBuilder; |
10
|
|
|
|
11
|
|
|
class WindowClause extends Clause |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var array<array-key, string>|object $offsets |
|
|
|
|
15
|
|
|
*/ |
16
|
|
|
protected array|object $offsets; |
17
|
|
|
|
18
|
|
|
protected null|string|QueryBuilder|Expression $rangeValue; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* CollectClause constructor. |
22
|
|
|
* @param array<array-key, string>|object $offsets |
|
|
|
|
23
|
|
|
*/ |
24
|
4 |
|
public function __construct( |
25
|
|
|
array|object $offsets, |
26
|
|
|
null|string|QueryBuilder|Expression $rangeValue = null |
27
|
|
|
) { |
28
|
4 |
|
parent::__construct(); |
29
|
|
|
|
30
|
4 |
|
$this->offsets = $offsets; |
31
|
4 |
|
$this->rangeValue = $rangeValue; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @throws ExpressionTypeException |
36
|
|
|
*/ |
37
|
4 |
|
public function compile(QueryBuilder $queryBuilder): string |
38
|
|
|
{ |
39
|
4 |
|
$this->offsets = $queryBuilder->normalizeArgument( |
40
|
4 |
|
$this->offsets, |
41
|
4 |
|
['List', 'Reference', 'Function', 'Query', 'Bind'], |
42
|
|
|
); |
43
|
|
|
|
44
|
4 |
|
if (isset($this->rangeValue)) { |
45
|
3 |
|
$this->rangeValue = $queryBuilder->normalizeArgument( |
46
|
3 |
|
$this->rangeValue, |
47
|
3 |
|
['Reference', 'Function', 'Query', 'Bind'], |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
4 |
|
$output = 'WINDOW'; |
52
|
4 |
|
if (isset($this->rangeValue)) { |
53
|
|
|
/** @phpstan-ignore-next-line */ |
54
|
3 |
|
$output .= ' ' . $this->rangeValue->compile($queryBuilder); |
|
|
|
|
55
|
3 |
|
$output .= ' WITH'; |
56
|
|
|
} |
57
|
4 |
|
$output .= ' ' . $this->offsets->compile($queryBuilder); |
58
|
|
|
|
59
|
4 |
|
return $output; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|