/**
* @param array
* @return void
*/
public function mapField(array $mapping)
{
// Check mandatory fields
if (!isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) {
throw MappingException::missingFieldName($this->name);
}
if (isset($this->fieldMappings[$mapping['fieldName']])) {
$existingMapping = $this->fieldMappings[$mapping['fieldName']];
// only complain if one exists for this class, and not any parents
if (!isset($existingMapping['declared'])) {
throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']);
} elseif ($existingMapping['declared'] == $this->rootXmlEntityName) {
throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']);
}
}
if (!isset($mapping['type']) || strlen($mapping['type']) == 0) {
throw MappingException::missingFieldType($this->name, $mapping['fieldName']);
}
if (!isset($mapping['name'])) {
$mapping['name'] = Inflector::xmlize($mapping['fieldName']);
} else {
if ($mapping['name'][0] == '`') {
$mapping['name'] = trim($mapping['name'], '`');
$mapping['quoted'] = true;
}
}
if (isset($this->xmlFieldMap[$mapping['name']])) {
$existingMapping = $this->fieldMappings[$this->xmlFieldMap[$mapping['name']]];
if (!isset($existingMapping['declared'])) {
throw MappingException::duplicateXmlFieldName($this->name, $mapping['name']);
} elseif ($existingMapping['declared'] == $this->rootXmlEntityName) {
throw MappingException::duplicateXmlFieldName($this->name, $mapping['name']);
}
}
if (!isset($mapping['node'])) {
if (Type::hasType($mapping['type'])) {
// Map object and array to "text", everything else to "attribute"
if (in_array($mapping['type'], array(Type::OBJECT, Type::TARRAY))) {
$mapping['node'] = self::XML_TEXT;
} else {
$mapping['node'] = self::XML_ATTRIBUTE;
}
} else {
$mapping['node'] = self::XML_ELEMENT;
}
}
if (!in_array($mapping['node'], self::getXmlNodeTypes())) {
throw MappingException::xmlBindingTypeUnknown($mapping['fieldName'], $mapping['node']);
}
if (!isset($mapping['direct'])) {
$mapping['direct'] = true;
}
if (!isset($mapping['nullable'])) {
$mapping['nullable'] = false;
}
if (!isset($mapping['required'])) {
$mapping['required'] = false;
}
if (!isset($mapping['container'])) {
$mapping['container'] = false;
}
if (!isset($mapping['collection'])) {
$mapping['collection'] = false;
}
if (!isset($mapping['getMethod'])) {
$mapping['getMethod'] = $this->inferGetter($mapping['fieldName']);
}
if (!isset($mapping['setMethod'])) {
$mapping['setMethod'] = $this->inferSetter($mapping['fieldName']);
}
if (!isset($mapping['id'])) {
$mapping['id'] = false;
} else {
$this->identifier = $mapping['fieldName'];
}
$this->xmlFieldMap[$mapping['name']] = $mapping['fieldName'];
$this->fieldMappings[$mapping['fieldName']] = $mapping;
return $mapping;
}