/** * Validates that the payload type key matches the endpoint type key. * Also handles proper type keys for polymorphic endpoints. * * @param string $payloadTypeKey * @param string $endpointTypeKey * @throws AdpaterException */ protected function validatePayloadType($payloadTypeKey, $endpointTypeKey) { $metadata = $this->getStore()->getMetadataForType($endpointTypeKey); if (false === $metadata->isPolymorphic() && $payloadTypeKey === $endpointTypeKey) { return; } if (true === $metadata->isPolymorphic() && in_array($payloadTypeKey, $metadata->ownedTypes)) { return; } $expected = true === $metadata->isPolymorphic() ? implode(', ', $metadata->ownedTypes) : $endpointTypeKey; throw AdapterException::badRequest(sprintf('The payload "type" member does not match the API endpoint. Expected one of "%s" but received "%s"', $expected, $payloadTypeKey)); }
/** * Validates that the serialized value is support by a RestPayload. * * @param mixed $serialized * @return bool * @throws AdapterException On invalid serialized value. */ protected function validateSerialization($serialized) { if (!is_string($serialized)) { throw AdapterException::badRequest('Unable to create an API response payload. Invalid serialization occurred.'); } return true; }