PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 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 All 255 releases
give / src / ValueObjects / DonorInfo.php

DonorInfo.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/ValueObjects/DonorInfo.php

86 lines 1.8 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 class DonorInfo implements ValueObjects
8 {
9 /**
10 * WP user id.
11 * Donor can be connect to WP user. if connect and donating after login as WP user then it set to logged in user id.
12 *
13 * @var string
14 */
15 public $wpUserId;
16
17 /**
18 * Primary email.
19 *
20 * @var string
21 */
22 public $email;
23
24 /**
25 * Donor address.
26 *
27 * @var Address
28 */
29 public $address;
30
31 /**
32 * First name.
33 *
34 * @var string
35 */
36 public $firstName;
37
38 /**
39 * Last name.
40 *
41 * @var string
42 */
43 public $lastName;
44
45 /**
46 * Donor honorific.
47 *
48 * @var string
49 */
50 public $honorific;
51
52 /**
53 * Take array and return object.
54 *
55 * @since 2.19.6 - fix update key validation with new variable to prevent removing not required keys like lastName
56 *
57 * @param $array
58 *
59 * @return DonorInfo
60 */
61 public static function fromArray($array)
62 {
63 $expectedKeys = ['wpUserId', 'firstName', 'email', 'honorific', 'address'];
64
65 $requiredKeys = array_intersect_key($array, array_flip($expectedKeys));
66
67 if (empty($requiredKeys)) {
68 throw new InvalidArgumentException(
69 'Invalid DonorInfo object, must have the exact following keys: ' . implode(', ', $expectedKeys)
70 );
71 }
72
73 $donorInfo = new self();
74 foreach ($array as $key => $value) {
75 $donorInfo->{$key} = $value;
76 }
77
78 // Cast address to Give\ValueObjects\Address object.
79 if ( ! empty($array['address'])) {
80 $donorInfo->address = Address::fromArray($array['address']);
81 }
82
83 return $donorInfo;
84 }
85 }
86