1: <?php
2:
3: declare(strict_types=1);
4:
5: /*
6: * This file has been auto generated by Jane,
7: *
8: * Do no edit it directly.
9: */
10:
11: namespace NxSys\Library\Clients\Brex\API\Team\Normalizer;
12:
13: use Jane\Component\JsonSchemaRuntime\Reference;
14: use NxSys\Library\Clients\Brex\API\Team\Runtime\Normalizer\CheckArray;
15: use NxSys\Library\Clients\Brex\API\Team\Runtime\Normalizer\ValidatorTrait;
16: use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
17: use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
18: use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
19: use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
20: use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
21: use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
22:
23: class SpendControlNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
24: {
25: use DenormalizerAwareTrait;
26: use NormalizerAwareTrait;
27: use CheckArray;
28: use ValidatorTrait;
29:
30: public function supportsDenormalization($data, $type, $format = null): bool
31: {
32: return $type === 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\SpendControl';
33: }
34:
35: public function supportsNormalization($data, $format = null): bool
36: {
37: return is_object($data) && get_class($data) === 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\SpendControl';
38: }
39:
40: /**
41: * @return mixed
42: */
43: public function denormalize($data, $class, $format = null, array $context = [])
44: {
45: if (isset($data['$ref'])) {
46: return new Reference($data['$ref'], $context['document-origin']);
47: }
48: if (isset($data['$recursiveRef'])) {
49: return new Reference($data['$recursiveRef'], $context['document-origin']);
50: }
51: $object = new \NxSys\Library\Clients\Brex\API\Team\Model\SpendControl();
52: if (null === $data || false === \is_array($data)) {
53: return $object;
54: }
55: if (\array_key_exists('spend_limit', $data)) {
56: $object->setSpendLimit($this->denormalizer->denormalize($data['spend_limit'], 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\Money', 'json', $context));
57: unset($data['spend_limit']);
58: }
59: if (\array_key_exists('spend_available', $data)) {
60: $object->setSpendAvailable($this->denormalizer->denormalize($data['spend_available'], 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\Money', 'json', $context));
61: unset($data['spend_available']);
62: }
63: if (\array_key_exists('spend_duration', $data)) {
64: $object->setSpendDuration($data['spend_duration']);
65: unset($data['spend_duration']);
66: }
67: if (\array_key_exists('reason', $data) && $data['reason'] !== null) {
68: $object->setReason($data['reason']);
69: unset($data['reason']);
70: } elseif (\array_key_exists('reason', $data) && $data['reason'] === null) {
71: $object->setReason(null);
72: }
73: if (\array_key_exists('lock_after_date', $data) && $data['lock_after_date'] !== null) {
74: $object->setLockAfterDate(\DateTime::createFromFormat('Y-m-d', $data['lock_after_date'])->setTime(0, 0, 0));
75: unset($data['lock_after_date']);
76: } elseif (\array_key_exists('lock_after_date', $data) && $data['lock_after_date'] === null) {
77: $object->setLockAfterDate(null);
78: }
79: foreach ($data as $key => $value) {
80: if (preg_match('/.*/', (string) $key)) {
81: $object[$key] = $value;
82: }
83: }
84:
85: return $object;
86: }
87:
88: /**
89: * @return array|string|int|float|bool|\ArrayObject|null
90: */
91: public function normalize($object, $format = null, array $context = [])
92: {
93: $data = [];
94: $data['spend_limit'] = $this->normalizer->normalize($object->getSpendLimit(), 'json', $context);
95: $data['spend_available'] = $this->normalizer->normalize($object->getSpendAvailable(), 'json', $context);
96: if ($object->isInitialized('spendDuration') && null !== $object->getSpendDuration()) {
97: $data['spend_duration'] = $object->getSpendDuration();
98: }
99: if ($object->isInitialized('reason') && null !== $object->getReason()) {
100: $data['reason'] = $object->getReason();
101: }
102: if ($object->isInitialized('lockAfterDate') && null !== $object->getLockAfterDate()) {
103: $data['lock_after_date'] = $object->getLockAfterDate()->format('Y-m-d');
104: }
105: foreach ($object as $key => $value) {
106: if (preg_match('/.*/', (string) $key)) {
107: $data[$key] = $value;
108: }
109: }
110:
111: return $data;
112: }
113: }
114: