1 | <?php |
||
16 | abstract class AbstractIndex extends AbstractElement implements IndexInterface |
||
17 | { |
||
18 | /** |
||
19 | * Index types. |
||
20 | */ |
||
21 | const NORMAL = 'INDEX'; |
||
22 | const UNIQUE = 'UNIQUE'; |
||
23 | |||
24 | /** |
||
25 | * Index type, by default NORMAL and UNIQUE indexes supported, additional types can be |
||
26 | * implemented on database driver level. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $type = self::NORMAL; |
||
31 | |||
32 | /** |
||
33 | * Columns used to form index. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $columns = []; |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function isUnique(): bool |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | public function getColumns(): array |
||
54 | |||
55 | /** |
||
56 | * Declare index type and behaviour to unique/non-unique state. |
||
57 | * |
||
58 | * @param bool $unique |
||
59 | * |
||
60 | * @return self |
||
61 | */ |
||
62 | public function unique(bool $unique = true): AbstractIndex |
||
68 | |||
69 | /** |
||
70 | * Change set of index forming columns. Method must support both array and string parameters. |
||
71 | * |
||
72 | * Example: |
||
73 | * $index->columns('key'); |
||
74 | * $index->columns('key', 'key2'); |
||
75 | * $index->columns(['key', 'key2']); |
||
76 | * |
||
77 | * @param string|array $columns Columns array or comma separated list of parameters. |
||
78 | * |
||
79 | * @return self |
||
80 | */ |
||
81 | public function columns($columns): AbstractIndex |
||
91 | |||
92 | /** |
||
93 | * Index sql creation syntax. |
||
94 | * |
||
95 | * @param Driver $driver |
||
96 | * @param bool $includeTable Include table ON statement (not required for inline index |
||
97 | * creation). |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function sqlStatement(Driver $driver, bool $includeTable = true): string |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | public function compare(IndexInterface $initial): bool |
||
126 | } |