This repository has been archived by the owner on Oct 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathObject.php
188 lines (153 loc) · 4.3 KB
/
Object.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
namespace ext\activedocument;
use \Yii,
\CComponent;
/**
* @property mixed|null $key
*/
abstract class Object extends \CComponent {
/**
* @var \ext\activedocument\Adapter
*/
protected $_adapter;
/**
* @var \ext\activedocument\Connection
*/
protected $_connection;
/**
* @var \ext\activedocument\Container
*/
protected $_container;
/**
* @var mixed
*/
private $_key;
/**
* @var mixed
*/
public $data;
protected $_objectInstance;
abstract protected function loadObjectInstance($new=true);
/**
* @abstract
* @return bool
*/
abstract protected function storeInternal();
/**
* @abstract
* @return bool
*/
abstract protected function deleteInternal();
/**
* @abstract
* @return bool
*/
abstract protected function reloadInternal();
/**
* @abstract
* @return mixed
*/
abstract protected function getObjectData();
/**
* @abstract
* @param mixed $data
*/
abstract protected function setObjectData($data);
/**
* @param \ext\activedocument\Container $container
* @param string|null $key optional
* @param mixed|null $data optional
* @param bool $new optional
*/
public function __construct(Container $container, $key=null, $data=null, $new=true) {
$this->_container = $container;
$this->_adapter = $container->getAdapter();
$this->_connection = $container->getConnection();
$this->_key = $key;
$this->_objectInstance = $this->loadObjectInstance($new);
/**
* Sync data
*/
$this->syncData($data);
}
/**
* @param mixed $data
*/
protected function syncData($data) {
if ($data !== null)
$this->setObjectData($data);
$this->data = $this->getObjectData();
}
/**
* @return \ext\activedocument\Container
*/
public function getContainer() {
return $this->_container;
}
/**
* @return \ext\activedocument\Connection
*/
public function getConnection() {
return $this->_connection;
}
/**
* @return \ext\activedocument\Adapter
*/
public function getAdapter() {
return $this->_adapter;
}
public function getObjectInstance() {
return $this->_objectInstance;
}
/**
* @return null|mixed
*/
public function getKey() {
return $this->_key;
}
/**
* @param mixed $value
*/
public function setKey($value) {
$this->_key = $value;
}
/**
* @return bool
*/
public function store() {
if ($this->getConnection()->enableProfiling) {
$profileToken = 'ext.activedocument.execute.storeObject(Storing object with key: '.\CVarDumper::dumpAsString($this->getKey()).')';
Yii::beginProfile($profileToken, 'ext.activedocument.execute.storeObject');
}
$result = $this->storeInternal();
if ($this->getConnection()->enableProfiling)
Yii::endProfile($profileToken, 'ext.activedocument.execute.storeObject');
return $result;
}
/**
* @return bool
*/
public function delete() {
if ($this->getConnection()->enableProfiling) {
$profileToken = 'ext.activedocument.execute.deleteObject(Deleting object with key: '.\CVarDumper::dumpAsString($this->getKey()).')';
Yii::beginProfile($profileToken, 'ext.activedocument.execute.deleteObject');
}
$result = $this->deleteInternal();
if ($this->getConnection()->enableProfiling)
Yii::endProfile($profileToken, 'ext.activedocument.execute.deleteObject');
return $result;
}
/**
* @return bool
*/
public function reload() {
if ($this->getConnection()->enableProfiling) {
$profileToken = 'ext.activedocument.query.reloadObject(Reloading object with key: '.\CVarDumper::dumpAsString($this->getKey()).')';
Yii::beginProfile($profileToken, 'ext.activedocument.query.reloadObject');
}
$result = $this->reloadInternal();
if ($this->getConnection()->enableProfiling)
Yii::endProfile($profileToken, 'ext.activedocument.query.reloadObject');
return $result;
}
}