This repository has been archived by the owner on Mar 23, 2021. It is now read-only.
/
model.php
98 lines (87 loc) · 1.57 KB
/
model.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
<?php
/**
* Gateway model class.
*/
abstract class Gateway_Model extends Gateway_Core
{
/**
* Data for the current instance.
*
* @var array
*/
protected $data = array();
/**
* Sets the data for the current instance.
*
* @param array $data The data to use.
*
* @return void
*/
public function set(array $data)
{
$this->data = $data;
}
/**
* Resets the data for the current instance.
*
* @return void
*/
public function reset()
{
$this->data = null;
}
/**
* Gets the ID of the current instance.
*
* @return string
*/
public function id()
{
return $this->data('id');
}
/**
* Gets a property from instance data.
*
* @param string $key The key to get from data.
* @param mixed $default The default value to use if key not found.
*
* @return mixed
*/
public function data($key = null, $default = null)
{
if (!empty($key)) {
return Arr::get($this->data, $key, $default);
}
return $this->data;
}
/**
* Finds a single instance.
*
* @param int|array $options Instance identifier or filter data.
*
* @return array|null
*/
abstract public function find_one($options = array());
/**
* Creates a new instance.
*
* @param $data New instance data.
*
* @return bool
*/
abstract public function create(array $data);
/**
* Updates an existing instance.
*
* @param array $data Updated instance data.
*
* @return bool
*/
abstract public function update(array $data);
/**
* Deletes an existing instance.
*
* @return bool
*/
abstract public function delete();
}