/** * @param array $mapping * @param ClassMetadata $inherited same field of parent document, if any * @param bool $isField whether this is a field or an association * @param string $phpcrLabel the name for the phpcr thing. usually property, * except for child where this is name. referrers * use false to not set anything. * * @return mixed * * @throws MappingException */ 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; }
protected function validateAndCompleteFieldMapping($mapping, $isField = true) { if (!isset($mapping['fieldName'])) { throw new MappingException("Mapping a property requires to specify the fieldName."); } if ($isField && !isset($mapping['name'])) { $mapping['name'] = $mapping['fieldName']; } if (isset($this->fieldMappings[$mapping['fieldName']]) || $this->node == $mapping['fieldName'] || $this->nodename == $mapping['fieldName'] || $this->parentMapping == $mapping['fieldName'] || $this->versionNameField == $mapping['fieldName'] || $this->versionCreatedField == $mapping['fieldName'] || isset($this->associationsMappings[$mapping['fieldName']]) || isset($this->childMappings[$mapping['fieldName']]) || isset($this->childrenMappings[$mapping['fieldName']]) || isset($this->referrersMappings[$mapping['fieldName']])) { if (!$isField || empty($mapping['type']) || empty($this->fieldMappings[$mapping['fieldName']]) || $this->fieldMappings[$mapping['fieldName']]['type'] !== $mapping['type']) { throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']); } } if ($isField && !isset($mapping['type'])) { throw MappingException::missingTypeDefinition($this->name, $mapping['fieldName']); } $reflProp = $this->reflClass->getProperty($mapping['fieldName']); $reflProp->setAccessible(true); $this->reflFields[$mapping['fieldName']] = $reflProp; return $mapping; }