1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | namespace Worldline\Connect\Sdk\V1\Domain; |
7: | |
8: | use UnexpectedValueException; |
9: | use Worldline\Connect\Sdk\Domain\DataObject; |
10: | |
11: | |
12: | |
13: | |
14: | class ValueMappingElement extends DataObject |
15: | { |
16: | |
17: | |
18: | |
19: | public $displayElements = null; |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | public $displayName = null; |
26: | |
27: | |
28: | |
29: | |
30: | public $value = null; |
31: | |
32: | |
33: | |
34: | |
35: | public function toObject() |
36: | { |
37: | $object = parent::toObject(); |
38: | if (!is_null($this->displayElements)) { |
39: | $object->displayElements = []; |
40: | foreach ($this->displayElements as $element) { |
41: | if (!is_null($element)) { |
42: | $object->displayElements[] = $element->toObject(); |
43: | } |
44: | } |
45: | } |
46: | if (!is_null($this->displayName)) { |
47: | $object->displayName = $this->displayName; |
48: | } |
49: | if (!is_null($this->value)) { |
50: | $object->value = $this->value; |
51: | } |
52: | return $object; |
53: | } |
54: | |
55: | |
56: | |
57: | |
58: | |
59: | |
60: | public function fromObject($object) |
61: | { |
62: | parent::fromObject($object); |
63: | if (property_exists($object, 'displayElements')) { |
64: | if (!is_array($object->displayElements) && !is_object($object->displayElements)) { |
65: | throw new UnexpectedValueException('value \'' . print_r($object->displayElements, true) . '\' is not an array or object'); |
66: | } |
67: | $this->displayElements = []; |
68: | foreach ($object->displayElements as $element) { |
69: | $value = new PaymentProductFieldDisplayElement(); |
70: | $this->displayElements[] = $value->fromObject($element); |
71: | } |
72: | } |
73: | if (property_exists($object, 'displayName')) { |
74: | $this->displayName = $object->displayName; |
75: | } |
76: | if (property_exists($object, 'value')) { |
77: | $this->value = $object->value; |
78: | } |
79: | return $this; |
80: | } |
81: | } |
82: | |