1: <?php
2: namespace Worldline\Connect\Sdk\Domain;
3:
4: use Exception;
5: use stdClass;
6: use UnexpectedValueException;
7: use Worldline\Connect\Sdk\JSON\JSONUtil;
8:
9: /**
10: * Class DataObject
11: *
12: * @package Worldline\Connect\Sdk\Domain
13: */
14: abstract class DataObject
15: {
16: /**
17: * @return string
18: */
19: public function toJson(): string
20: {
21: return json_encode($this->toObject());
22: }
23:
24: /**
25: * @param string $value
26: *
27: * @return $this
28: * @throws UnexpectedValueException
29: */
30: public function fromJson(string $value): DataObject
31: {
32: $object = JSONUtil::decode($value);
33: return $this->fromObject($object);
34: }
35:
36: /**
37: * @return object
38: */
39: public function toObject(): object
40: {
41: return new stdClass();
42: }
43:
44: /**
45: * @param object $object
46: *
47: * @return $this
48: * @throws UnexpectedValueException
49: */
50: public function fromObject(object $object): DataObject
51: {
52: return $this;
53: }
54:
55: public function __set($name, $value)
56: {
57: throw new Exception('Cannot add new property ' . $name . ' to instances of class ' . get_class($this));
58: }
59: }
60: