-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathARSerializedReference.php
More file actions
47 lines (39 loc) · 961 Bytes
/
ARSerializedReference.php
File metadata and controls
47 lines (39 loc) · 961 Bytes
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
<?php
/**
*
* @package activerecord
* @author Integry Systems
*/
class ARSerializedReference implements Serializable
{
protected $instanceClassName;
protected $instanceId;
public function __construct(ActiveRecord $instance)
{
$this->instanceClassName = get_class($instance);
$this->instanceId = $instance->getID();
}
public function restoreInstance()
{
$instance = ActiveRecord::getInstanceById($this->instanceClassName, $this->instanceId);
return $instance;
}
public function getClassName()
{
return $this->instanceClassName;
}
public function serialize()
{
$serialized = array();
$serialized['class'] = $this->instanceClassName;
$serialized['ID'] = $this->instanceId;
return serialize($serialized);
}
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->instanceClassName = $data['class'];
$this->instanceId = $data['ID'];
}
}
?>