-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAddress.php
60 lines (54 loc) · 1.29 KB
/
Address.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
<?php
namespace flydreamers\shipwire;
class Address
{
public $address1='';
public $address2='';
public $address3='';
public $city='';
public $postalCode='';
public $region='';
public $country='';
public $isCommercial=0;
public $isPoBox=0;
/**
* Serialize this info as array
* @return array
*/
public function asArray()
{
return [
'address1' => $this->address1,
'address2' => $this->address2,
'address3' => $this->address3,
'city' => $this->city,
'postalCode' => $this->postalCode,
'region' => $this->region,
'country' => $this->country,
'isCommercial' => $this->isCommercial,
'isPoBox' => $this->isPoBox,
];
}
/**
* Serialize this info as json
* @return string
*/
public function asJson(){
return json_encode($this->asArray());
}
/**
* Creates an address from an array
* @param $arr
* @return Address
*/
public static function createFromArray($arr)
{
$ret = new Address();
foreach ($arr as $key => $value) {
if (property_exists($ret, $key)){
$ret->$key = $value;
}
}
return $ret;
}
}