protected function validateAndCompleteFieldMapping(array $mapping, ClassMetadata $inherited = null, $isField = true, $phpcrLabel = 'property')
{
if ($inherited) {
if (!isset($mapping['inherited'])) {
$this->inheritedFields[$mapping['fieldName']] = $inherited->name;
}
if (!isset($mapping['declared'])) {
$mapping['declared'] = $inherited->name;
}
$this->reflFields[$mapping['fieldName']] = $inherited->getReflectionProperty($mapping['fieldName']);
$this->mappings[$mapping['fieldName']] = $mapping;
return $mapping;
}
if (empty($mapping['fieldName'])) {
throw new MappingException("Mapping a property requires to specify the field name in '{$this->name}'.");
}
if (!is_string($mapping['fieldName'])) {
throw new MappingException("Field name must be of type string in '{$this->name}'.");
}
if (!$this->reflClass->hasProperty($mapping['fieldName'])) {
throw MappingException::classHasNoField($this->name, $mapping['fieldName']);
}
if (empty($mapping['property'])) {
$mapping['property'] = $mapping['fieldName'];
}
if ($phpcrLabel && (!isset($mapping[$phpcrLabel]) || empty($mapping[$phpcrLabel]))) {
$mapping[$phpcrLabel] = $mapping['fieldName'];
}
if ($isField && isset($mapping['assoc'])) {
$mapping['multivalue'] = true;
if (empty($mapping['assoc'])) {
$mapping['assoc'] = $mapping['property'] . 'Keys';
}
$mapping['assocNulls'] = $mapping['property'] . 'Nulls';
}
if (isset($this->mappings[$mapping['fieldName']])) {
if (!$isField || empty($mapping['type']) || empty($this->mappings[$mapping['fieldName']]) || $this->mappings[$mapping['fieldName']]['type'] !== $mapping['type']) {
throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']);
}
}
if (!isset($mapping['type'])) {
throw MappingException::missingTypeDefinition($this->name, $mapping['fieldName']);
}
if ($mapping['type'] === 'int') {
$mapping['type'] = 'long';
} elseif ($mapping['type'] === 'float') {
$mapping['type'] = 'double';
}
$reflProp = $this->reflClass->getProperty($mapping['fieldName']);
$reflProp->setAccessible(true);
$this->reflFields[$mapping['fieldName']] = $reflProp;
$this->mappings[$mapping['fieldName']] = $mapping;
return $mapping;
}