1 | <?php |
||
17 | abstract class AbstractReference extends AbstractElement implements ReferenceInterface |
||
18 | { |
||
19 | /** |
||
20 | * Parent table isolation prefix. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $tablePrefix = ''; |
||
25 | |||
26 | /** |
||
27 | * Local column name (key name). |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $column = ''; |
||
32 | |||
33 | /** |
||
34 | * Referenced table name (including prefix). |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $foreignTable = ''; |
||
39 | |||
40 | /** |
||
41 | * Linked foreign key name (foreign column). |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $foreignKey = ''; |
||
46 | |||
47 | /** |
||
48 | * Action on foreign column value deletion. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $deleteRule = self::NO_ACTION; |
||
53 | |||
54 | /** |
||
55 | * Action on foreign column value update. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $updateRule = self::NO_ACTION; |
||
60 | |||
61 | /** |
||
62 | * @param string $table |
||
63 | * @param string $tablePrefix |
||
64 | * @param string $name |
||
65 | */ |
||
66 | public function __construct(string $table, string $tablePrefix, string $name) |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | * |
||
75 | * @param string $name |
||
76 | */ |
||
77 | public function setName(string $name): AbstractElement |
||
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | public function getColumn(): string |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function getForeignTable(): string |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public function getForeignKey(): string |
||
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | */ |
||
113 | public function getDeleteRule(): string |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function getUpdateRule(): string |
||
125 | |||
126 | /** |
||
127 | * Set local column name foreign key relates to. Make sure column type is the same as foreign |
||
128 | * column one. |
||
129 | * |
||
130 | * @param string $column |
||
131 | * |
||
132 | * @return self |
||
133 | */ |
||
134 | public function column(string $column): AbstractReference |
||
140 | |||
141 | /** |
||
142 | * Set foreign table name and key local column must reference to. Make sure local and foreign |
||
143 | * column types are identical. |
||
144 | * |
||
145 | * @param string $table Foreign table name with or without database prefix (see 3rd |
||
146 | * argument). |
||
147 | * @param string $column Foreign key name (id by default). |
||
148 | * @param bool $forcePrefix When true foreign table will get same prefix as table being |
||
149 | * modified. |
||
150 | * |
||
151 | * @return self |
||
152 | */ |
||
153 | public function references( |
||
154 | string $table, |
||
155 | string $column = 'id', |
||
156 | bool $forcePrefix = true |
||
157 | ): AbstractReference { |
||
158 | $this->foreignTable = ($forcePrefix ? $this->tablePrefix : '') . $table; |
||
159 | $this->foreignKey = $column; |
||
160 | |||
161 | return $this; |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Set foreign key delete behaviour. |
||
166 | * |
||
167 | * @param string $rule Possible values: NO ACTION, CASCADE, etc (driver specific). |
||
168 | * |
||
169 | * @return self |
||
170 | */ |
||
171 | public function onDelete(string $rule = self::NO_ACTION): AbstractReference |
||
177 | |||
178 | /** |
||
179 | * Set foreign key update behaviour. |
||
180 | * |
||
181 | * @param string $rule Possible values: NO ACTION, CASCADE, etc (driver specific). |
||
182 | * |
||
183 | * @return self |
||
184 | */ |
||
185 | public function onUpdate(string $rule = self::NO_ACTION): AbstractReference |
||
191 | |||
192 | /** |
||
193 | * Foreign key creation syntax. |
||
194 | * |
||
195 | * @param Driver $driver |
||
196 | * |
||
197 | * @return string |
||
198 | */ |
||
199 | public function sqlStatement(Driver $driver): string |
||
216 | |||
217 | /** |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | public function compare(ReferenceInterface $initial): bool |
||
224 | } |