1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Implementation of PostgreSQL REGEXP_SUBSTR(). |
9
|
|
|
* |
10
|
|
|
* Returns the substring within string that matches the Nth occurrence of the POSIX regular expression pattern, |
11
|
|
|
* or NULL if there is no such match. |
12
|
|
|
* |
13
|
|
|
* @see https://www.postgresql.org/docs/15/functions-matching.html#FUNCTIONS-POSIX-REGEXP |
14
|
|
|
* @since 3.1 |
15
|
|
|
* |
16
|
|
|
* @author Martin Georgiev <[email protected]> |
17
|
|
|
* |
18
|
|
|
* @example Using it in DQL: "SELECT REGEXP_SUBSTR(e.text, 'c(.)(..)', 1, 1, 'i', 2) FROM Entity e" |
19
|
|
|
*/ |
20
|
|
|
class RegexpSubstr extends BaseVariadicFunction |
21
|
|
|
{ |
22
|
3 |
|
protected function getNodeMappingPattern(): array |
23
|
|
|
{ |
24
|
3 |
|
return [ |
25
|
3 |
|
'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,StringPrimary,ArithmeticPrimary', |
26
|
3 |
|
'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,StringPrimary', |
27
|
3 |
|
'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary', |
28
|
3 |
|
'StringPrimary,StringPrimary,ArithmeticPrimary', |
29
|
3 |
|
'StringPrimary,StringPrimary', |
30
|
3 |
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
3 |
|
protected function getFunctionName(): string |
34
|
|
|
{ |
35
|
3 |
|
return 'regexp_substr'; |
36
|
|
|
} |
37
|
|
|
|
38
|
3 |
|
protected function getMinArgumentCount(): int |
39
|
|
|
{ |
40
|
3 |
|
return 2; |
41
|
|
|
} |
42
|
|
|
|
43
|
3 |
|
protected function getMaxArgumentCount(): int |
44
|
|
|
{ |
45
|
3 |
|
return 6; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|