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