This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
ZoneMemberCountry.php
228 lines (200 loc) · 4.9 KB
/
ZoneMemberCountry.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
namespace CommerceGuys\Zone\Model;
use CommerceGuys\Addressing\AddressInterface;
use CommerceGuys\Addressing\PostalCodeHelper;
/**
* Matches a country, its subdivisions and postal codes.
*/
class ZoneMemberCountry extends ZoneMember
{
/**
* The country code.
*
* @var string
*/
protected $countryCode;
/**
* The administrative area.
*
* @var string
*/
protected $administrativeArea;
/**
* The locality.
*
* @var string
*/
protected $locality;
/**
* The dependent locality.
*
* @var string
*/
protected $dependentLocality;
/**
* The included postal codes.
*
* Can be a regular expression ("/(35|38)[0-9]{3}/") or a comma-separated
* list of postal codes, including ranges ("98, 100:200, 250").
*
* @var string
*/
protected $includedPostalCodes;
/**
* The excluded postal codes.
*
* Can be a regular expression ("/(35|38)[0-9]{3}/") or a comma-separated
* list of postal codes, including ranges ("98, 100:200, 250").
*
* @var string
*/
protected $excludedPostalCodes;
/**
* Gets the country code.
*
* @return string The country code.
*/
public function getCountryCode()
{
return $this->countryCode;
}
/**
* Sets the country code.
*
* @param string $countryCode The country code.
*
* @return self
*/
public function setCountryCode($countryCode)
{
$this->countryCode = $countryCode;
return $this;
}
/**
* Gets the administrative area.
*
* @return string|null The administrative area, or null if all should match.
*/
public function getAdministrativeArea()
{
return $this->administrativeArea;
}
/**
* Sets the administrative area.
*
* @param string|null $administrativeArea The administrative area.
*
* @return self
*/
public function setAdministrativeArea($administrativeArea = null)
{
$this->administrativeArea = $administrativeArea;
return $this;
}
/**
* Gets the locality.
*
* @return string|null The locality, or null if all should match.
*/
public function getLocality()
{
return $this->locality;
}
/**
* Sets the locality.
*
* @param string|null $locality The locality.
*
* @return self
*/
public function setLocality($locality = null)
{
$this->locality = $locality;
return $this;
}
/**
* Gets the dependent locality.
*
* @return string|null The dependent locality, or null if all should match.
*/
public function getDependentLocality()
{
return $this->dependentLocality;
}
/**
* Sets the dependent locality.
*
* @param string|null $dependentLocality The dependent locality.
*
* @return self
*/
public function setDependentLocality($dependentLocality = null)
{
$this->dependentLocality = $dependentLocality;
return $this;
}
/**
* Gets the included postal codes.
*
* @return string The included postal codes.
*/
public function getIncludedPostalCodes()
{
return $this->includedPostalCodes;
}
/**
* Sets the included postal codes.
*
* @param string $includedPostalCodes The included postal codes.
*
* @return self
*/
public function setIncludedPostalCodes($includedPostalCodes)
{
$this->includedPostalCodes = $includedPostalCodes;
return $this;
}
/**
* Gets the excluded postal codes.
*
* @return string The excluded postal codes.
*/
public function getExcludedPostalCodes()
{
return $this->excludedPostalCodes;
}
/**
* Sets the excluded postal codes.
*
* @param string $excludedPostalCodes The excluded postal codes.
*
* @return self
*/
public function setExcludedPostalCodes($excludedPostalCodes)
{
$this->excludedPostalCodes = $excludedPostalCodes;
return $this;
}
/**
* {@inheritdoc}
*/
public function match(AddressInterface $address)
{
if ($address->getCountryCode() != $this->countryCode) {
return false;
}
if ($this->administrativeArea && $this->administrativeArea != $address->getAdministrativeArea()) {
return false;
}
if ($this->locality && $this->locality != $address->getLocality()) {
return false;
}
if ($this->dependentLocality && $this->dependentLocality != $address->getDependentLocality()) {
return false;
}
if (!PostalCodeHelper::match($address->getPostalCode(), $this->includedPostalCodes, $this->excludedPostalCodes)) {
return false;
}
return true;
}
}