/** * @param mixed $value * @param string Field $field * @param string $message */ public function __construct($value, Field $field, $message = null) { $this->value = $value; $this->field = $field; $message = sprintf('Failed to decode [%s] for field [%s] to a [%s]. Detail: %s', is_scalar($this->value) ? $this->value : StringUtils::varToString($this->value), $this->field->getName(), $this->field->getType()->getTypeValue(), $message); parent::__construct($message); }
/** * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html * * @param Field $field * @param \stdClass $rootObject * @param string $path * @return array */ protected function mapDynamicField(Field $field, \stdClass $rootObject, $path = null) { $mapping = $this->types[$field->getType()->getTypeValue()]; if ($field->isAList()) { $mapping['type'] = 'nested'; } $mapping['properties']['string_val'] = $this->applyAnalyzer($mapping['properties']['string_val'], $field, $rootObject, $path); $mapping['properties']['text_val'] = $this->applyAnalyzer($mapping['properties']['text_val'], $field, $rootObject, $path); return $mapping; }
/** * @param array $value * @param Field $field * @return mixed * * @throws EncodeValueFailed */ private function encodeASetValue(array $value, Field $field) { $type = $field->getType(); /* * A MessageRefType is the only object/map value that can be * used in a set. In this case of DynamoDb, we can store it as * a list of maps. */ if ($type->getTypeName() === TypeName::MESSAGE_REF()) { $list = []; foreach ($value as $v) { $list[] = $type->encode($v, $field, $this); } return ['L' => $list]; } if ($type->isString()) { $dynamoType = self::TYPE_STRING_SET; } elseif ($type->isNumeric()) { $dynamoType = self::TYPE_NUMBER_SET; } elseif ($type->isBinary()) { $dynamoType = self::TYPE_BINARY_SET; } else { throw new EncodeValueFailed($value, $field, sprintf('%s::%s has no handling for this value.', get_called_class(), __FUNCTION__)); } $result = []; foreach ($value as $v) { if ($type->encodesToScalar()) { $result[] = (string) $type->encode($v, $field, $this); } else { $result[] = (string) $v; } } return [$dynamoType => $result]; }