forked from phpmyadmin/sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexHint.php
More file actions
43 lines (36 loc) · 1.09 KB
/
Copy pathIndexHint.php
File metadata and controls
43 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Components;
use PhpMyAdmin\SqlParser\Component;
use PhpMyAdmin\SqlParser\Parsers\Expressions;
/**
* Parses an Index hint.
*/
final class IndexHint implements Component
{
/**
* @param string $type The type of hint (USE/FORCE/IGNORE)
* @param string $indexOrKey What the hint is for (INDEX/KEY)
* @param string|null $for The clause for which this hint is (JOIN/ORDER BY/GROUP BY)
* @param Expression[] $indexes List of indexes in this hint
*/
public function __construct(
public string $type = '',
public string $indexOrKey = '',
public string|null $for = null,
public array $indexes = [],
) {
}
public function build(): string
{
$ret = $this->type . ' ' . $this->indexOrKey . ' ';
if ($this->for !== null) {
$ret .= 'FOR ' . $this->for . ' ';
}
return $ret . Expressions::buildAll($this->indexes);
}
public function __toString(): string
{
return $this->build();
}
}