1
|
|
|
<?php |
2
|
|
|
namespace EventEspresso\core\entities; |
3
|
|
|
|
4
|
|
|
if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
5
|
|
|
exit( 'No direct script access allowed' ); |
6
|
|
|
} |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class GenericAddress |
12
|
|
|
* |
13
|
|
|
* @package Event Espresso |
14
|
|
|
* @subpackage core\entities\ |
15
|
|
|
* @author Brent Christensen |
16
|
|
|
* @since 4.8 |
17
|
|
|
*/ |
18
|
|
|
class GenericAddress implements \EEI_Address { |
19
|
|
|
|
20
|
|
|
private $_address = ''; |
21
|
|
|
|
22
|
|
|
private $_address2 = ''; |
23
|
|
|
|
24
|
|
|
private $_city = ''; |
25
|
|
|
|
26
|
|
|
private $_state_ID = ''; |
27
|
|
|
|
28
|
|
|
private $_state_obj = ''; |
29
|
|
|
|
30
|
|
|
private $_zip = ''; |
31
|
|
|
|
32
|
|
|
private $_country_ID = ''; |
33
|
|
|
|
34
|
|
|
private $_country_obj = ''; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $address |
40
|
|
|
* @param string $address2 |
41
|
|
|
* @param string $city |
42
|
|
|
* @param \EE_State | string $state |
43
|
|
|
* @param string $zip |
44
|
|
|
* @param \EE_Country | string $country |
45
|
|
|
* @return GenericAddress |
|
|
|
|
46
|
|
|
*/ |
47
|
|
|
public function __construct( $address, $address2, $city, $state, $zip, $country ) { |
48
|
|
|
$this->_address = $address; |
49
|
|
|
$this->_address2 = $address2; |
50
|
|
|
$this->_city = $city; |
51
|
|
|
if ( $state instanceof \EE_State ) { |
52
|
|
|
$this->_state_obj = $state; |
|
|
|
|
53
|
|
|
} else { |
54
|
|
|
$this->_state_ID = $state; |
55
|
|
|
$this->_state_obj = $this->_get_state_obj(); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
$this->_zip = $zip; |
58
|
|
|
if ( $country instanceof \EE_Country ) { |
59
|
|
|
$this->_country_obj = $country; |
|
|
|
|
60
|
|
|
} else { |
61
|
|
|
$this->_country_ID = $country; |
62
|
|
|
$this->_country_obj = $this->_get_country_obj(); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function address() { |
72
|
|
|
return $this->_address; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function address2() { |
81
|
|
|
return $this->_address2; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function city() { |
90
|
|
|
return $this->_city; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return \EE_State |
97
|
|
|
*/ |
98
|
|
|
private function _get_state_obj() { |
99
|
|
|
return $this->_state_obj instanceof \EE_State |
100
|
|
|
? $this->_state_obj |
101
|
|
|
: \EE_Registry::instance()->load_model( 'State' )->get_one_by_ID( $this->_state_ID ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function state_ID() { |
110
|
|
|
return $this->_state_ID; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function state_abbrev() { |
119
|
|
|
return $this->state_obj() instanceof \EE_State |
120
|
|
|
? $this->state_obj()->abbrev() |
121
|
|
|
: ''; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function state_name() { |
130
|
|
|
return $this->state_obj() instanceof \EE_State |
131
|
|
|
? $this->state_obj()->name() |
132
|
|
|
: ''; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return \EE_State |
139
|
|
|
*/ |
140
|
|
|
public function state_obj() { |
141
|
|
|
return $this->_state_obj; |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return string |
148
|
|
|
*/ |
149
|
|
|
public function state() { |
150
|
|
|
if ( apply_filters( 'FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj() ) ) { |
151
|
|
|
return $this->state_obj()->abbrev(); |
|
|
|
|
152
|
|
|
} else { |
153
|
|
|
return $this->state_name(); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return \EE_Country |
161
|
|
|
*/ |
162
|
|
|
private function _get_country_obj() { |
163
|
|
|
return $this->_country_obj instanceof \EE_Country |
164
|
|
|
? $this->_country_obj |
165
|
|
|
: \EE_Registry::instance()->load_model( 'Country' )->get_one_by_ID( $this->_country_ID ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
|
|
public function country_ID() { |
174
|
|
|
return $this->_country_ID; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return string |
181
|
|
|
*/ |
182
|
|
|
public function country_name() { |
183
|
|
|
return $this->country_obj() instanceof \EE_Country |
184
|
|
|
? $this->country_obj()->name() |
185
|
|
|
: ''; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
|
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return \EE_Country |
192
|
|
|
*/ |
193
|
|
|
public function country_obj() { |
194
|
|
|
return $this->_country_obj; |
|
|
|
|
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return string |
201
|
|
|
*/ |
202
|
|
|
public function country() { |
203
|
|
|
if ( apply_filters( 'FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj() ) ) { |
204
|
|
|
return $this->country_ID(); |
205
|
|
|
} else { |
206
|
|
|
return $this->country_name(); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return string |
214
|
|
|
*/ |
215
|
|
|
public function zip() { |
216
|
|
|
return $this->_zip; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
} |
220
|
|
|
// End of file GenericAddress.php |
221
|
|
|
// Location: core/entities/GenericAddress.php |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.