This repository has been archived by the owner on Dec 10, 2020. It is now read-only.
/
BaseRelation.php
executable file
·142 lines (111 loc) · 2.54 KB
/
BaseRelation.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
namespace vtvz\relations;
use yii\base\Component;
use yii\db\ActiveRecord;
use yii\db\ActiveRecordInterface;
/**
*
*/
abstract class BaseRelation extends Component
{
public $name;
/** @var ActiveRecord */
public $owner;
public $relationsClass;
public $model;
public $getCallable = null;
public $addCallable = null;
protected $populations = [];
protected $link;
protected $inverseOf;
protected $via;
protected $viaTable;
protected $viaLink;
protected $delete = null;
protected $unlink = null;
protected $type = null;
protected $types = [];
abstract public function get();
abstract public function add($value);
abstract public function create();
abstract public function unlink();
abstract public function save();
public function init()
{
parent::init();
$this->owner->on(ActiveRecord::EVENT_AFTER_INSERT, [$this, 'save']);
$this->owner->on(ActiveRecord::EVENT_AFTER_UPDATE, [$this, 'save']);
$this->owner->on(ActiveRecord::EVENT_BEFORE_DELETE, [$this, 'unlink']);
}
public function getLink()
{
return $this->link;
}
public function setLink($link)
{
$this->link = $link;
}
public function getInverseOf()
{
return $this->inverseOf;
}
public function setInverseOf($inverseOf)
{
$this->inverseOf = $inverseOf;
}
public function getVia()
{
return $this->via;
}
public function setVia($via)
{
$this->via = $via;
}
public function getViaTable()
{
return $this->viaTable;
}
public function setViaTable($viaTable)
{
$this->viaTable = $viaTable;
}
public function getViaLink()
{
return $this->viaLink;
}
public function setViaLink($viaLink)
{
$this->viaLink = $viaLink;
}
public function getDelete()
{
return $this->delete;
}
public function setDelete($delete)
{
$this->delete = $delete;
}
public function getUnlink()
{
return $this->unlink;
}
public function setUnlink($unlink)
{
$this->unlink = $unlink;
}
public function getType()
{
return $this->type;
}
public function setType($type)
{
if (!key_exists($type, $this->types)) {
throw new InvalidParamException('Param "type" is invalid');
}
$this->type = $type;
}
public function getTypes()
{
return $this->types;
}
}