public function convertValue($type, $value)
{
$result = null;
switch ($type) {
case 'nullValue':
$result = null;
break;
case 'booleanValue':
$result = (bool) $value;
break;
case 'integerValue':
$result = $this->returnInt64AsObject ? new Int64((string) $value) : (int) $value;
break;
case 'doubleValue':
$result = (double) $value;
break;
case 'timestampValue':
$result = \DateTimeImmutable::createFromFormat(self::DATE_FORMAT, $value);
if (!$result) {
$result = \DateTimeImmutable::createFromFormat(self::DATE_FORMAT_NO_MS, $value);
}
break;
case 'keyValue':
$namespaceId = isset($value['partitionId']['namespaceId']) ? $value['partitionId']['namespaceId'] : null;
$result = new Key($this->projectId, ['path' => $value['path'], 'namespaceId' => $namespaceId]);
break;
case 'stringValue':
$result = $value;
break;
case 'blobValue':
if ($this->isEncoded($value)) {
$value = base64_decode($value);
}
$result = new Blob($value);
break;
case 'geoPointValue':
$value += ['latitude' => null, 'longitude' => null];
$result = new GeoPoint($value['latitude'], $value['longitude']);
break;
case 'entityValue':
$props = $this->responseToEntityProperties($value['properties'])['properties'];
if (isset($value['key'])) {
$namespaceId = isset($value['key']['partitionId']['namespaceId']) ? $value['key']['partitionId']['namespaceId'] : null;
$key = new Key($this->projectId, ['path' => $value['key']['path'], 'namespaceId' => $namespaceId]);
$result = new Entity($key, $props, ['populatedByService' => true]);
} else {
$result = [];
foreach ($value['properties'] as $key => $property) {
$result[$key] = $this->getPropertyValue($property);
}
}
break;
case 'arrayValue':
$result = [];
if (array_key_exists('values', $value)) {
foreach ($value['values'] as $val) {
$result[] = $this->getPropertyValue($val);
}
}
break;
default:
throw new RuntimeException(sprintf('Unrecognized value type %s. Please ensure you are using the latest version of google/cloud.', $type));
break;
}
return $result;
}