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