1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Constraint; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Represents a foreign key constraint in a database. |
9
|
|
|
* |
10
|
|
|
* A foreign key constraint is a constraint that enforces referential integrity between two tables. |
11
|
|
|
* |
12
|
|
|
* It has information about the table and column(s) that the constraint applies to, as well as any actions that |
13
|
|
|
* should be taken when a referenced record is deleted or updated. |
14
|
|
|
*/ |
15
|
|
|
final class ForeignKeyConstraint extends Constraint |
16
|
|
|
{ |
17
|
|
|
private string|null $foreignSchemaName = null; |
18
|
|
|
private string|null $foreignTableName = null; |
19
|
|
|
private array $foreignColumnNames = []; |
20
|
|
|
private string|null $onUpdate = null; |
21
|
|
|
private string|null $onDelete = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return string|null The foreign table schema name. |
25
|
|
|
*/ |
26
|
|
|
public function getForeignSchemaName(): string|null |
27
|
|
|
{ |
28
|
5 |
|
return $this->foreignSchemaName; |
29
|
|
|
} |
30
|
5 |
|
|
31
|
|
|
/** |
32
|
|
|
* @return string|null The foreign table name. |
33
|
|
|
*/ |
34
|
|
|
public function getForeignTableName(): string|null |
35
|
|
|
{ |
36
|
|
|
return $this->foreignTableName; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return array The list of foreign table column names. |
41
|
|
|
*/ |
42
|
|
|
public function getForeignColumnNames(): array |
43
|
|
|
{ |
44
|
|
|
return $this->foreignColumnNames; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
52 |
|
* @return string|null The referential action if rows in a referenced table are to be updated. |
49
|
|
|
*/ |
50
|
52 |
|
public function getOnUpdate(): string|null |
51
|
|
|
{ |
52
|
52 |
|
return $this->onUpdate; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string|null The referential action if rows in a referenced table are to be deleted. |
57
|
|
|
*/ |
58
|
|
|
public function getOnDelete(): string|null |
59
|
|
|
{ |
60
|
56 |
|
return $this->onDelete; |
61
|
|
|
} |
62
|
56 |
|
|
63
|
|
|
/** |
64
|
56 |
|
* Set the foreign table schema name. |
65
|
|
|
* |
66
|
|
|
* @param string|null $value the referenced table schema name. |
67
|
|
|
*/ |
68
|
|
|
public function foreignSchemaName(string|null $value): self |
69
|
|
|
{ |
70
|
|
|
$this->foreignSchemaName = $value; |
71
|
|
|
return $this; |
72
|
56 |
|
} |
73
|
|
|
|
74
|
56 |
|
/** |
75
|
|
|
* Set the foreign table name. |
76
|
56 |
|
* |
77
|
|
|
* @param string|null $value The referenced table name. |
78
|
|
|
*/ |
79
|
|
|
public function foreignTableName(string|null $value): self |
80
|
|
|
{ |
81
|
|
|
$this->foreignTableName = $value; |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
56 |
|
|
85
|
|
|
/** |
86
|
56 |
|
* Set the list of foreign table column names. |
87
|
|
|
* |
88
|
56 |
|
* @param array $value The list of referenced table column names. |
89
|
|
|
*/ |
90
|
|
|
public function foreignColumnNames(array $value): self |
91
|
|
|
{ |
92
|
|
|
$this->foreignColumnNames = $value; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
56 |
|
/** |
97
|
|
|
* Set the referential action if rows in a referenced table are to be updated. |
98
|
56 |
|
* |
99
|
|
|
* @param string|null $value The referential action if rows in a referenced table are to be updated. |
100
|
56 |
|
*/ |
101
|
|
|
public function onUpdate(string|null $value): self |
102
|
|
|
{ |
103
|
|
|
$this->onUpdate = $value; |
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Set the referential action if rows in a referenced table are to be deleted. |
109
|
|
|
* |
110
|
|
|
* @param string|null $value The referential action if rows in a referenced table are to be deleted. |
111
|
|
|
*/ |
112
|
|
|
public function onDelete(string|null $value): self |
113
|
|
|
{ |
114
|
|
|
$this->onDelete = $value; |
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|