Address.php
283 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Plugin Framework |
| 4 | * |
| 5 | * This source file is subject to the GNU General Public License v3.0 |
| 6 | * that is bundled with this package in the file license.txt. |
| 7 | * It is also available through the world-wide-web at this URL: |
| 8 | * http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later |
| 9 | * If you did not receive a copy of the license and are unable to |
| 10 | * obtain it through the world-wide-web, please send an email |
| 11 | * to license@skyverge.com so we can send you a copy immediately. |
| 12 | * |
| 13 | * @since 3.0.0 |
| 14 | * @author WooCommerce / SkyVerge |
| 15 | * @copyright Copyright (c) 2013-2019, SkyVerge, Inc. |
| 16 | * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later |
| 17 | * |
| 18 | * Modified by WooCommerce on 01 December 2021. |
| 19 | */ |
| 20 | |
| 21 | namespace WooCommerce\Square\Framework\Addresses; |
| 22 | |
| 23 | defined( 'ABSPATH' ) or exit; |
| 24 | |
| 25 | /** |
| 26 | * The base address data class. |
| 27 | * |
| 28 | * This serves as a standard address object to be passed around by plugins whenever dealing with address data, and |
| 29 | * eliminates the need to rely on WooCommerce's address arrays. |
| 30 | * |
| 31 | * @since 3.0.0 |
| 32 | */ |
| 33 | class Address { |
| 34 | |
| 35 | |
| 36 | /** @var string line 1 of the street address */ |
| 37 | protected $line_1 = ''; |
| 38 | |
| 39 | /** @var string line 2 of the street address */ |
| 40 | protected $line_2 = ''; |
| 41 | |
| 42 | /** @var string line 3 of the street address */ |
| 43 | protected $line_3 = ''; |
| 44 | |
| 45 | /** @var string address locality (city) */ |
| 46 | protected $locality = ''; |
| 47 | |
| 48 | /** @var string address region (state) */ |
| 49 | protected $region = ''; |
| 50 | |
| 51 | /** @var string address country */ |
| 52 | protected $country = ''; |
| 53 | |
| 54 | /** @var string address postcode */ |
| 55 | protected $postcode = ''; |
| 56 | |
| 57 | |
| 58 | /** Getter methods ************************************************************************************************/ |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * Gets line 1 of the street address. |
| 63 | * |
| 64 | * @since 3.0.0 |
| 65 | * |
| 66 | * @return string |
| 67 | */ |
| 68 | public function get_line_1() { |
| 69 | |
| 70 | return $this->line_1; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | /** |
| 75 | * Gets line 2 of the street address. |
| 76 | * |
| 77 | * @since 3.0.0 |
| 78 | * |
| 79 | * @return string |
| 80 | */ |
| 81 | public function get_line_2() { |
| 82 | |
| 83 | return $this->line_2; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /** |
| 88 | * Gets line 3 of the street address. |
| 89 | * |
| 90 | * @since 3.0.0 |
| 91 | * |
| 92 | * @return string |
| 93 | */ |
| 94 | public function get_line_3() { |
| 95 | |
| 96 | return $this->line_3; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | /** |
| 101 | * Gets the locality or city. |
| 102 | * |
| 103 | * @since 3.0.0 |
| 104 | * |
| 105 | * @return string |
| 106 | */ |
| 107 | public function get_locality() { |
| 108 | |
| 109 | return $this->locality; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | /** |
| 114 | * Gets the region or state. |
| 115 | * |
| 116 | * @since 3.0.0 |
| 117 | * |
| 118 | * @return string |
| 119 | */ |
| 120 | public function get_region() { |
| 121 | |
| 122 | return $this->region; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /** |
| 127 | * Gets the country. |
| 128 | * |
| 129 | * @since 3.0.0 |
| 130 | * |
| 131 | * @return string |
| 132 | */ |
| 133 | public function get_country() { |
| 134 | |
| 135 | return $this->country; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /** |
| 140 | * Gets the postcode. |
| 141 | * |
| 142 | * @since 3.0.0 |
| 143 | * |
| 144 | * @return string |
| 145 | */ |
| 146 | public function get_postcode() { |
| 147 | |
| 148 | return $this->postcode; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | /** |
| 153 | * Gets the hash representation of this address. |
| 154 | * |
| 155 | * @see Address::get_hash_data() |
| 156 | * |
| 157 | * @since 3.0.0 |
| 158 | * |
| 159 | * @return string |
| 160 | */ |
| 161 | public function get_hash() { |
| 162 | |
| 163 | return md5( wp_json_encode( $this->get_hash_data() ) ); |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /** |
| 168 | * Gets the data used to generate a hash for the address. |
| 169 | * |
| 170 | * @since 3.0.0 |
| 171 | * |
| 172 | * @return string[] |
| 173 | */ |
| 174 | protected function get_hash_data() { |
| 175 | |
| 176 | return array( |
| 177 | $this->get_line_1(), |
| 178 | $this->get_line_2(), |
| 179 | $this->get_line_3(), |
| 180 | $this->get_locality(), |
| 181 | $this->get_region(), |
| 182 | $this->get_country(), |
| 183 | $this->get_postcode(), |
| 184 | ); |
| 185 | } |
| 186 | |
| 187 | |
| 188 | /** Setter methods ************************************************************************************************/ |
| 189 | |
| 190 | |
| 191 | /** |
| 192 | * Sets line 1 of the street address. |
| 193 | * |
| 194 | * @since 3.0.0 |
| 195 | * |
| 196 | * @param string $value line 1 value |
| 197 | */ |
| 198 | public function set_line_1( $value ) { |
| 199 | |
| 200 | $this->line_1 = $value; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | /** |
| 205 | * Sets line 2 of the street address. |
| 206 | * |
| 207 | * @since 3.0.0 |
| 208 | * |
| 209 | * @param string $value line 2 value |
| 210 | */ |
| 211 | public function set_line_2( $value ) { |
| 212 | |
| 213 | $this->line_2 = $value; |
| 214 | } |
| 215 | |
| 216 | |
| 217 | /** |
| 218 | * Gets line 3 of the street address. |
| 219 | * |
| 220 | * @since 3.0.0 |
| 221 | * |
| 222 | * @param string $value line 3 value |
| 223 | */ |
| 224 | public function set_line_3( $value ) { |
| 225 | |
| 226 | $this->line_3 = $value; |
| 227 | } |
| 228 | |
| 229 | |
| 230 | /** |
| 231 | * Gets the locality or city. |
| 232 | * |
| 233 | * @since 3.0.0 |
| 234 | * |
| 235 | * @param string $value locality value |
| 236 | */ |
| 237 | public function set_locality( $value ) { |
| 238 | |
| 239 | $this->locality = $value; |
| 240 | } |
| 241 | |
| 242 | |
| 243 | /** |
| 244 | * Gets the region or state. |
| 245 | * |
| 246 | * @since 3.0.0 |
| 247 | * |
| 248 | * @param string $value region value |
| 249 | */ |
| 250 | public function set_region( $value ) { |
| 251 | |
| 252 | $this->region = $value; |
| 253 | } |
| 254 | |
| 255 | |
| 256 | /** |
| 257 | * Sets the country. |
| 258 | * |
| 259 | * @since 3.0.0 |
| 260 | * |
| 261 | * @param string $value country value |
| 262 | */ |
| 263 | public function set_country( $value ) { |
| 264 | |
| 265 | $this->country = $value; |
| 266 | } |
| 267 | |
| 268 | |
| 269 | /** |
| 270 | * Sets the postcode. |
| 271 | * |
| 272 | * @since 3.0.0 |
| 273 | * |
| 274 | * @param string $value postcode value |
| 275 | */ |
| 276 | public function set_postcode( $value ) { |
| 277 | |
| 278 | $this->postcode = $value; |
| 279 | } |
| 280 | |
| 281 | |
| 282 | } |
| 283 |