-
Notifications
You must be signed in to change notification settings - Fork 15
/
Lookup.php
206 lines (163 loc) · 5.33 KB
/
Lookup.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
namespace SmartyStreets\PhpSdk\US_Autocomplete_Pro;
/**
* In addition to holding all of the input data for this lookup, this class also<br>
* will contain the result of the lookup after it comes back from the API.
* @see "https://smartystreets.com/docs/cloud/us-autocomplete-api#http-request-input-fields"
*/
class Lookup {
//region [ Fields ]
const MAX_RESULTS_DEFAULT = 10;
const PREFER_RATIO_DEFAULT = 100;
private $result,
$search,
$maxResults,
$cityFilter,
$stateFilter,
$zipFilter,
$excludeStates,
$preferCities,
$preferStates,
$preferZIPCodes,
$preferRatio,
$preferGeolocation,
$selected;
//endregion
/**
* If you use this constructor, don't forget to set the <b>prefix</b>. It is required.
* @param $search string The beginning of an address
*/
public function __construct($search = null) {
$this->search = $search;
$this->maxResults = Lookup::MAX_RESULTS_DEFAULT;
$this->cityFilter = array();
$this->stateFilter = array();
$this->zipFilter = array();
$this->excludeStates = array();
$this->preferCities = array();
$this->preferStates = array();
$this->preferZIPCodes = array();
$this->preferRatio = Lookup::PREFER_RATIO_DEFAULT;
$this->preferGeolocation = new GeolocateType(GEOLOCATE_TYPE_CITY);
}
public function addCityFilter($city) {
$this->cityFilter[] = $city;
}
public function addStateFilter($stateAbbreviation) {
$this->stateFilter[] = $stateAbbreviation;
}
public function addZIPFilter($zipcode) {
$this->geolocateType = new GeolocateType(GEOLOCATE_TYPE_NONE);
$this->zipFilter = $zipcode;
}
public function addStateExclusion($stateAbbreviation) {
$this->excludeStates[] = $stateAbbreviation;
}
public function addPreferCity($city) {
$this->preferCities[] = $city;
}
public function addPreferState($stateAbbreviation) {
$this->preferStates[] = $stateAbbreviation;
}
public function addPreferZIPCode($zipcode) {
$this->geolocateType = new GeolocateType(GEOLOCATE_TYPE_NONE);
$this->preferZIPCodes = $zipcode;
}
//region [ Getters ]
public function getResult() {
return $this->result;
}
public function getResultAtIndex($index) {
return $this->result[$index];
}
public function getSearch() {
return $this->search;
}
public function getMaxResults() {
return $this->maxResults;
}
public function getCityFilter() {
return $this->cityFilter;
}
public function getStateFilter() {
return $this->stateFilter;
}
public function getZIPFilter() {
return $this->zipFilter;
}
public function getStateExclusions() {
return $this->excludeStates;
}
public function getPreferCities() {
return $this->preferCities;
}
public function getPreferStates() {
return $this->preferStates;
}
public function getPreferZIPCodes() {
return $this->preferZIPCodes;
}
public function getPreferRatio() {
return $this->preferRatio;
}
public function getGeolocateType() {
return $this->preferGeolocation;
}
public function getSelected() {
return $this->selected;
}
function getMaxResultsStringIfSet() {
if ($this->maxResults == Lookup::MAX_RESULTS_DEFAULT)
return null;
return strval($this->maxResults);
}
function getPreferRatioStringIfSet() {
if ($this->preferRatio == Lookup::PREFER_RATIO_DEFAULT)
return null;
return strval($this->preferRatio);
}
//endregion
//region [ Setter ]
public function setResult($result) {
$this->result = $result;
}
public function setSearch($search) {
$this->search = $search;
}
public function setMaxResults($maxResults) {
if ($maxResults > 0 && $this->maxResults <= 10)
$this->maxResults = $maxResults;
else
throw new \InvalidArgumentException("Max suggestions must be a positive integer no larger than 10.");
}
public function setCityFilter($cityFilter) {
$this->cityFilter = $cityFilter;
}
public function setStateFilter($stateFilter) {
$this->stateFilter = $stateFilter;
}
public function setZIPFilter($zipFilter) {
$this->geolocateType = new GeolocateType(GEOLOCATE_TYPE_NONE);
$this->zipFilter = $zipFilter;
}
public function setPreferCities($cities) {
$this->preferCities = $cities;
}
public function setPreferStates($stateAbbreviations) {
$this->preferStates = $stateAbbreviations;
}
public function setPreferZIPCodes($zipcodes) {
$this->geolocateType = new GeolocateType(GEOLOCATE_TYPE_NONE);
$this->$this->preferZIPCodes = $zipcodes;
}
public function setPreferRatio($preferRatio) {
$this->preferRatio = $preferRatio;
}
public function setGeolocateType(GeolocateType $geolocateType) {
$this->geolocateType = $geolocateType;
}
public function setSelected($selected) {
$this->selected = $selected;
}
//endregion
}