1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace miBadger\ActiveRecord\Traits; |
4
|
|
|
|
5
|
|
|
use miBadger\ActiveRecord\ColumnProperty; |
6
|
|
|
|
7
|
|
|
const TRAIT_ADDRESS_FIELD_ADDRESS = "address_address"; |
8
|
|
|
const TRAIT_ADDRESS_FIELD_ZIPCODE = "address_zipcode"; |
9
|
|
|
const TRAIT_ADDRESS_FIELD_CITY = "address_city"; |
10
|
|
|
const TRAIT_ADDRESS_FIELD_COUNTRY = "address_country"; |
11
|
|
|
const TRAIT_ADDRESS_FIELD_STATE = "address_state"; |
12
|
|
|
|
13
|
|
|
trait Address |
14
|
|
|
{ |
15
|
|
|
/** @var string the address line */ |
16
|
|
|
protected $address; |
17
|
|
|
|
18
|
|
|
/** @var string the zipcode */ |
19
|
|
|
protected $zipcode; |
20
|
|
|
|
21
|
|
|
/** @var string the city */ |
22
|
|
|
protected $city; |
23
|
|
|
|
24
|
|
|
/** @var string the country */ |
25
|
|
|
protected $country; |
26
|
|
|
|
27
|
|
|
/** @var string the state */ |
28
|
|
|
protected $state; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Registers the Address trait on the including class |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
2 |
|
protected function initAddress() |
35
|
|
|
{ |
36
|
2 |
|
$this->extendTableDefinition(TRAIT_ADDRESS_FIELD_ADDRESS, [ |
37
|
2 |
|
'value' => &$this->address, |
38
|
|
|
'validate' => null, |
39
|
2 |
|
'type' => 'VARCHAR', |
40
|
2 |
|
'length' => 1024, |
41
|
|
|
'properties' => null |
42
|
|
|
]); |
43
|
|
|
|
44
|
2 |
|
$this->extendTableDefinition(TRAIT_ADDRESS_FIELD_ZIPCODE, [ |
45
|
2 |
|
'value' => &$this->zipcode, |
46
|
|
|
'validate' => null, |
47
|
2 |
|
'type' => 'VARCHAR', |
48
|
2 |
|
'length' => 1024, |
49
|
|
|
'properties' => null |
50
|
|
|
]); |
51
|
|
|
|
52
|
2 |
|
$this->extendTableDefinition(TRAIT_ADDRESS_FIELD_CITY, [ |
53
|
2 |
|
'value' => &$this->city, |
54
|
|
|
'validate' => null, |
55
|
2 |
|
'type' => 'VARCHAR', |
56
|
2 |
|
'length' => 1024, |
57
|
|
|
'properties' => null |
58
|
|
|
]); |
59
|
|
|
|
60
|
2 |
|
$this->extendTableDefinition(TRAIT_ADDRESS_FIELD_COUNTRY, [ |
61
|
2 |
|
'value' => &$this->country, |
62
|
|
|
'validate' => null, |
63
|
2 |
|
'type' => 'VARCHAR', |
64
|
2 |
|
'length' => 1024, |
65
|
|
|
'properties' => null |
66
|
|
|
]); |
67
|
|
|
|
68
|
2 |
|
$this->extendTableDefinition(TRAIT_ADDRESS_FIELD_STATE, [ |
69
|
2 |
|
'value' => &$this->state, |
70
|
|
|
'validate' => null, |
71
|
2 |
|
'type' => 'VARCHAR', |
72
|
2 |
|
'length' => 1024, |
73
|
|
|
'properties' => null |
74
|
|
|
]); |
75
|
|
|
|
76
|
2 |
|
$this->address = null; |
77
|
2 |
|
$this->zipcode = null; |
78
|
2 |
|
$this->city = null; |
79
|
2 |
|
$this->country = null; |
80
|
2 |
|
$this->state = null; |
81
|
2 |
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
1 |
|
public function getAddress() |
87
|
|
|
{ |
88
|
1 |
|
return $this->address; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $address |
93
|
|
|
*/ |
94
|
1 |
|
public function setAddress($address) |
95
|
|
|
{ |
96
|
1 |
|
$this->address = $address; |
97
|
1 |
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
1 |
|
public function getZipcode() |
104
|
|
|
{ |
105
|
1 |
|
return $this->zipcode; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param string $zipcode |
110
|
|
|
*/ |
111
|
1 |
|
public function setZipcode($zipcode) |
112
|
|
|
{ |
113
|
1 |
|
$this->zipcode = $zipcode; |
114
|
1 |
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
1 |
|
public function getCity() |
121
|
|
|
{ |
122
|
1 |
|
return $this->city; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param string $city |
127
|
|
|
*/ |
128
|
1 |
|
public function setCity($city) |
129
|
|
|
{ |
130
|
1 |
|
$this->city = $city; |
131
|
1 |
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
1 |
|
public function getCountry() |
138
|
|
|
{ |
139
|
1 |
|
return $this->country; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param string $country |
144
|
|
|
*/ |
145
|
1 |
|
public function setCountry($country) |
146
|
|
|
{ |
147
|
1 |
|
$this->country = $country; |
148
|
1 |
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function getState() |
152
|
|
|
{ |
153
|
|
|
return $this->state; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function setState($state) |
157
|
|
|
{ |
158
|
|
|
$this->state = $state; |
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return void |
164
|
|
|
*/ |
165
|
|
|
abstract protected function extendTableDefinition(string $columnName, $definition); |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return void |
169
|
|
|
*/ |
170
|
|
|
abstract protected function registerSearchHook(string $columnName, $fn); |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return void |
174
|
|
|
*/ |
175
|
|
|
abstract protected function registerDeleteHook(string $columnName, $fn); |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return void |
179
|
|
|
*/ |
180
|
|
|
abstract protected function registerUpdateHook(string $columnName, $fn); |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return void |
184
|
|
|
*/ |
185
|
|
|
abstract protected function registerReadHook(string $columnName, $fn); |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return void |
189
|
|
|
*/ |
190
|
|
|
abstract protected function registerCreateHook(string $columnName, $fn); |
191
|
|
|
|
192
|
|
|
} |