report = Report::createInfo(); $schema = $this->getOption(static::OPTION_SCHEMA); $this->buildMandatoryProperties($data, $schema); $this->buildOptionalProperties($data, $schema); return $this; } /** * @param array $extraProperties * @return array|mixed */ public function combine(array $extraProperties) { $this->propertiesMapped = array_merge($this->propertiesMapped, $extraProperties); return $this; } /** * @return bool */ public function isEmpty() { return empty($this->propertiesMapped); } /** * @return array */ public function getProperties() { return $this->propertiesMapped; } /** * @inheritdoc */ public function getReport() { return $this->report; } /** * @param array $data * @param array $schema * @throws MandatoryFieldException * @throws RdsResourceNotFoundException * @throws \common_exception_Error */ protected function buildMandatoryProperties(array $data, array $schema) { $mandatoryFields = isset($schema[static::OPTION_SCHEMA_MANDATORY]) ? $schema[static::OPTION_SCHEMA_MANDATORY] : []; foreach ($mandatoryFields as $key => $propertyKey) { if (!isset($data[$key])) { throw new MandatoryFieldException('Mandatory field "' . $key . '" should exists.'); } if (empty($data[$key])) { throw new MandatoryFieldException('Mandatory field "' . $key . '" should not be empty.'); } $this->addValue($propertyKey, $data[$key]); } } /** * @param array $data * @param array $schema * @throws RdsResourceNotFoundException * @throws \common_exception_Error */ protected function buildOptionalProperties(array $data, array $schema) { $optionalFields = isset($schema[static::OPTION_SCHEMA_OPTIONAL]) ? $schema[static::OPTION_SCHEMA_OPTIONAL] : []; foreach ($optionalFields as $key => $propertyKey) { if (!isset($data[$key]) || $data[$key] === '') { continue; } $this->addValue($propertyKey, $data[$key]); } } /** * @param string $propertyKey * @param string $value * @throws RdsResourceNotFoundException * @throws \common_exception_Error */ protected function addValue($propertyKey, $value) { if (is_array($propertyKey) && count($propertyKey) === 1) { $valueMapper = reset($propertyKey); if ($valueMapper instanceof ImportValueMapperInterface) { $propertyKey = key($propertyKey); $this->propagate($valueMapper); $this->propertiesMapped[$propertyKey] = $valueMapper->map($value); $this->report->add($valueMapper->getReport()); } } else { $this->propertiesMapped[$propertyKey] = $this->formatValue($propertyKey, $value); $successMessage = 'Property mapped with success: ' . $propertyKey . ':'; $successMessage .= is_array($value) ? implode(',', $value) : $value; $this->report->add(Report::createSuccess($successMessage)); } } }