| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 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 BudgetNormalizer 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\\Budget'; |
| 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\\Budget'; |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 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\Budget(); |
| 52: | if (null === $data || false === \is_array($data)) { |
| 53: | return $object; |
| 54: | } |
| 55: | if (\array_key_exists('budget_id', $data)) { |
| 56: | $object->setBudgetId($data['budget_id']); |
| 57: | unset($data['budget_id']); |
| 58: | } |
| 59: | if (\array_key_exists('account_id', $data)) { |
| 60: | $object->setAccountId($data['account_id']); |
| 61: | unset($data['account_id']); |
| 62: | } |
| 63: | if (\array_key_exists('creator_user_id', $data) && $data['creator_user_id'] !== null) { |
| 64: | $object->setCreatorUserId($data['creator_user_id']); |
| 65: | unset($data['creator_user_id']); |
| 66: | } elseif (\array_key_exists('creator_user_id', $data) && $data['creator_user_id'] === null) { |
| 67: | $object->setCreatorUserId(null); |
| 68: | } |
| 69: | if (\array_key_exists('name', $data)) { |
| 70: | $object->setName($data['name']); |
| 71: | unset($data['name']); |
| 72: | } |
| 73: | if (\array_key_exists('description', $data) && $data['description'] !== null) { |
| 74: | $object->setDescription($data['description']); |
| 75: | unset($data['description']); |
| 76: | } elseif (\array_key_exists('description', $data) && $data['description'] === null) { |
| 77: | $object->setDescription(null); |
| 78: | } |
| 79: | if (\array_key_exists('parent_budget_id', $data) && $data['parent_budget_id'] !== null) { |
| 80: | $object->setParentBudgetId($data['parent_budget_id']); |
| 81: | unset($data['parent_budget_id']); |
| 82: | } elseif (\array_key_exists('parent_budget_id', $data) && $data['parent_budget_id'] === null) { |
| 83: | $object->setParentBudgetId(null); |
| 84: | } |
| 85: | if (\array_key_exists('owner_user_ids', $data)) { |
| 86: | $values = []; |
| 87: | foreach ($data['owner_user_ids'] as $value) { |
| 88: | $values[] = $value; |
| 89: | } |
| 90: | $object->setOwnerUserIds($values); |
| 91: | unset($data['owner_user_ids']); |
| 92: | } |
| 93: | if (\array_key_exists('member_user_ids', $data)) { |
| 94: | $values_1 = []; |
| 95: | foreach ($data['member_user_ids'] as $value_1) { |
| 96: | $values_1[] = $value_1; |
| 97: | } |
| 98: | $object->setMemberUserIds($values_1); |
| 99: | unset($data['member_user_ids']); |
| 100: | } |
| 101: | if (\array_key_exists('period_type', $data)) { |
| 102: | $object->setPeriodType($data['period_type']); |
| 103: | unset($data['period_type']); |
| 104: | } |
| 105: | if (\array_key_exists('start_date', $data) && $data['start_date'] !== null) { |
| 106: | $object->setStartDate(\DateTime::createFromFormat('Y-m-d', $data['start_date'])->setTime(0, 0, 0)); |
| 107: | unset($data['start_date']); |
| 108: | } elseif (\array_key_exists('start_date', $data) && $data['start_date'] === null) { |
| 109: | $object->setStartDate(null); |
| 110: | } |
| 111: | if (\array_key_exists('end_date', $data) && $data['end_date'] !== null) { |
| 112: | $object->setEndDate(\DateTime::createFromFormat('Y-m-d', $data['end_date'])->setTime(0, 0, 0)); |
| 113: | unset($data['end_date']); |
| 114: | } elseif (\array_key_exists('end_date', $data) && $data['end_date'] === null) { |
| 115: | $object->setEndDate(null); |
| 116: | } |
| 117: | if (\array_key_exists('limit', $data)) { |
| 118: | $object->setLimit($this->denormalizer->denormalize($data['limit'], 'NxSys\\Library\\Clients\\Brex\\API\\Budgets\\Model\\BudgetLimit', 'json', $context)); |
| 119: | unset($data['limit']); |
| 120: | } |
| 121: | if (\array_key_exists('budget_status', $data)) { |
| 122: | $object->setBudgetStatus($data['budget_status']); |
| 123: | unset($data['budget_status']); |
| 124: | } |
| 125: | if (\array_key_exists('limit_type', $data)) { |
| 126: | $object->setLimitType($data['limit_type']); |
| 127: | unset($data['limit_type']); |
| 128: | } |
| 129: | if (\array_key_exists('spend_type', $data)) { |
| 130: | $object->setSpendType($data['spend_type']); |
| 131: | unset($data['spend_type']); |
| 132: | } |
| 133: | if (\array_key_exists('current_period_balance', $data)) { |
| 134: | $object->setCurrentPeriodBalance($this->denormalizer->denormalize($data['current_period_balance'], 'NxSys\\Library\\Clients\\Brex\\API\\Budgets\\Model\\BudgetCurrentPeriodBalance', 'json', $context)); |
| 135: | unset($data['current_period_balance']); |
| 136: | } |
| 137: | foreach ($data as $key => $value_2) { |
| 138: | if (preg_match('/.*/', (string) $key)) { |
| 139: | $object[$key] = $value_2; |
| 140: | } |
| 141: | } |
| 142: | |
| 143: | return $object; |
| 144: | } |
| 145: | |
| 146: | |
| 147: | |
| 148: | |
| 149: | public function normalize($object, $format = null, array $context = []) |
| 150: | { |
| 151: | $data = []; |
| 152: | if ($object->isInitialized('budgetId') && null !== $object->getBudgetId()) { |
| 153: | $data['budget_id'] = $object->getBudgetId(); |
| 154: | } |
| 155: | if ($object->isInitialized('accountId') && null !== $object->getAccountId()) { |
| 156: | $data['account_id'] = $object->getAccountId(); |
| 157: | } |
| 158: | if ($object->isInitialized('creatorUserId') && null !== $object->getCreatorUserId()) { |
| 159: | $data['creator_user_id'] = $object->getCreatorUserId(); |
| 160: | } |
| 161: | if ($object->isInitialized('name') && null !== $object->getName()) { |
| 162: | $data['name'] = $object->getName(); |
| 163: | } |
| 164: | if ($object->isInitialized('description') && null !== $object->getDescription()) { |
| 165: | $data['description'] = $object->getDescription(); |
| 166: | } |
| 167: | if ($object->isInitialized('parentBudgetId') && null !== $object->getParentBudgetId()) { |
| 168: | $data['parent_budget_id'] = $object->getParentBudgetId(); |
| 169: | } |
| 170: | if ($object->isInitialized('ownerUserIds') && null !== $object->getOwnerUserIds()) { |
| 171: | $values = []; |
| 172: | foreach ($object->getOwnerUserIds() as $value) { |
| 173: | $values[] = $value; |
| 174: | } |
| 175: | $data['owner_user_ids'] = $values; |
| 176: | } |
| 177: | if ($object->isInitialized('memberUserIds') && null !== $object->getMemberUserIds()) { |
| 178: | $values_1 = []; |
| 179: | foreach ($object->getMemberUserIds() as $value_1) { |
| 180: | $values_1[] = $value_1; |
| 181: | } |
| 182: | $data['member_user_ids'] = $values_1; |
| 183: | } |
| 184: | $data['period_type'] = $object->getPeriodType(); |
| 185: | if ($object->isInitialized('startDate') && null !== $object->getStartDate()) { |
| 186: | $data['start_date'] = $object->getStartDate()->format('Y-m-d'); |
| 187: | } |
| 188: | if ($object->isInitialized('endDate') && null !== $object->getEndDate()) { |
| 189: | $data['end_date'] = $object->getEndDate()->format('Y-m-d'); |
| 190: | } |
| 191: | if ($object->isInitialized('limit') && null !== $object->getLimit()) { |
| 192: | $data['limit'] = $this->normalizer->normalize($object->getLimit(), 'json', $context); |
| 193: | } |
| 194: | $data['budget_status'] = $object->getBudgetStatus(); |
| 195: | if ($object->isInitialized('limitType') && null !== $object->getLimitType()) { |
| 196: | $data['limit_type'] = $object->getLimitType(); |
| 197: | } |
| 198: | $data['spend_type'] = $object->getSpendType(); |
| 199: | if ($object->isInitialized('currentPeriodBalance') && null !== $object->getCurrentPeriodBalance()) { |
| 200: | $data['current_period_balance'] = $this->normalizer->normalize($object->getCurrentPeriodBalance(), 'json', $context); |
| 201: | } |
| 202: | foreach ($object as $key => $value_2) { |
| 203: | if (preg_match('/.*/', (string) $key)) { |
| 204: | $data[$key] = $value_2; |
| 205: | } |
| 206: | } |
| 207: | |
| 208: | return $data; |
| 209: | } |
| 210: | } |
| 211: | |