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\Budgets\Normalizer;
12:
13: use Jane\Component\JsonSchemaRuntime\Reference;
14: use NxSys\Library\Clients\Brex\API\Budgets\Runtime\Normalizer\CheckArray;
15: use NxSys\Library\Clients\Brex\API\Budgets\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 BudgetCurrentPeriodBalanceNormalizer 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\\Budgets\\Model\\BudgetCurrentPeriodBalance';
33: }
34:
35: public function supportsNormalization($data, $format = null): bool
36: {
37: return is_object($data) && get_class($data) === 'NxSys\\Library\\Clients\\Brex\\API\\Budgets\\Model\\BudgetCurrentPeriodBalance';
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\Budgets\Model\BudgetCurrentPeriodBalance();
52: if (null === $data || false === \is_array($data)) {
53: return $object;
54: }
55: if (\array_key_exists('start_date', $data) && $data['start_date'] !== null) {
56: $object->setStartDate(\DateTime::createFromFormat('Y-m-d', $data['start_date'])->setTime(0, 0, 0));
57: unset($data['start_date']);
58: } elseif (\array_key_exists('start_date', $data) && $data['start_date'] === null) {
59: $object->setStartDate(null);
60: }
61: if (\array_key_exists('end_date', $data) && $data['end_date'] !== null) {
62: $object->setEndDate(\DateTime::createFromFormat('Y-m-d', $data['end_date'])->setTime(0, 0, 0));
63: unset($data['end_date']);
64: } elseif (\array_key_exists('end_date', $data) && $data['end_date'] === null) {
65: $object->setEndDate(null);
66: }
67: if (\array_key_exists('balance', $data)) {
68: $object->setBalance($this->denormalizer->denormalize($data['balance'], 'NxSys\\Library\\Clients\\Brex\\API\\Budgets\\Model\\BudgetPeriodBalanceBalance', 'json', $context));
69: unset($data['balance']);
70: }
71: foreach ($data as $key => $value) {
72: if (preg_match('/.*/', (string) $key)) {
73: $object[$key] = $value;
74: }
75: }
76:
77: return $object;
78: }
79:
80: /**
81: * @return array|string|int|float|bool|\ArrayObject|null
82: */
83: public function normalize($object, $format = null, array $context = [])
84: {
85: $data = [];
86: if ($object->isInitialized('startDate') && null !== $object->getStartDate()) {
87: $data['start_date'] = $object->getStartDate()->format('Y-m-d');
88: }
89: if ($object->isInitialized('endDate') && null !== $object->getEndDate()) {
90: $data['end_date'] = $object->getEndDate()->format('Y-m-d');
91: }
92: if ($object->isInitialized('balance') && null !== $object->getBalance()) {
93: $data['balance'] = $this->normalizer->normalize($object->getBalance(), 'json', $context);
94: }
95: foreach ($object as $key => $value) {
96: if (preg_match('/.*/', (string) $key)) {
97: $data[$key] = $value;
98: }
99: }
100:
101: return $data;
102: }
103: }
104: