PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.17.0
GiveWP – Donation Plugin and Fundraising Platform v2.17.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / ValueObjects / Address.php
Address.php
70 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\ValueObjects;
4
5 use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
6
7 /**
8 * Class Address.
9 */
10 class Address implements ValueObjects {
11
12 /**
13 * @var string
14 */
15 public $line1;
16
17 /**
18 * @var string
19 */
20 public $line2;
21
22 /**
23 * @var string
24 */
25 public $city;
26
27 /**
28 * @var string
29 */
30 public $state;
31
32 /**
33 * @var string
34 */
35 public $postalCode;
36
37 /**
38 * @var string
39 */
40 public $country;
41
42
43 /**
44 * Take array and return object.
45 *
46 * @param array $array
47 *
48 * @return Address
49 * @since 2.7.0
50 */
51 public static function fromArray( $array ) {
52 $expectedKeys = [ 'line1', 'line2', 'city', 'state', 'postalCode', 'country' ];
53
54 $array = array_intersect_key( $array, array_flip( $expectedKeys ) );
55
56 if ( empty( $array ) ) {
57 throw new InvalidArgumentException(
58 'Invalid Address object, must have the exact following keys: ' . implode( ', ', $expectedKeys )
59 );
60 }
61
62 $address = new self();
63 foreach ( $array as $key => $value ) {
64 $address->$key = $value;
65 }
66
67 return $address;
68 }
69 }
70