/
Relationship.class.php
50 lines (40 loc) · 1.11 KB
/
Relationship.class.php
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
44
45
46
47
48
49
50
<?php
abstract class Relationship {
const FOREIGN_KEY = 'foreignkey';
const FOREIGN_CLASS = 'class';
const THROUGH = 'through';
const ON_DELETE = 'ondelete';
const UNSPECIFIED = 'unspecified';
const CASCADE = 'cascade';
const DELETE = 'delete';
const NULLIFY = 'nullify';
public $name;
public $localClass;
public $foreignClass;
public $foreignKey;
public $onDelete;
public $through;
abstract function getType();
abstract function init($modelClassName, $relationshipName);
function getDefaultOnDeleteMode() { return Relationship::NULLIFY; }
function delete(Model $model) {
if($this->onDelete == Relationship::UNSPECIFIED) {
$this->onDelete = $this->getDefaultOnDeleteMode();
}
switch($this->onDelete) {
case Relationship::CASCADE:
$this->onDeleteCascade($model);
break;
case Relationship::DELETE:
$this->onDeleteDelete($model);
break;
case Relationship::NULLIFY:
$this->onDeleteNullify($model);
break;
}
}
abstract function onDeleteCascade(Model $model);
abstract function onDeleteDelete(Model $model);
abstract function onDeleteNullify(Model $model);
}
?>