/** * @param array $mapping * @param ClassMetadata $inherited same field of parent object, 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. * * @throws \Doctrine\ORM\ODMAdapter\Exception\MappingException * @throws MappingException * @return mixed */ protected function validateAndCompleteFieldMapping(array $mapping, ClassMetadata $inherited = null, $isField = true, $phpcrLabel = 'property') { if (empty($mapping['fieldName'])) { throw new MappingException("Mapping a property requires to specify the name in '{$this->className}'."); } if (!is_string($mapping['fieldName'])) { throw new MappingException("Attribute name must be of type string in '{$this->className}'."); } if (!$this->reflectionClass->hasProperty($mapping['fieldName'])) { throw MappingException::classHasNoField($this->className, $mapping['fieldName']); } if (empty($mapping['property'])) { $mapping['property'] = $mapping['fieldName']; } if ($phpcrLabel && (!isset($mapping[$phpcrLabel]) || empty($mapping[$phpcrLabel]))) { $mapping[$phpcrLabel] = $mapping['fieldName']; } 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->className, $mapping['fieldName']); } } if (!isset($mapping['type'])) { throw MappingException::missingTypeDefinition($this->className, $mapping['fieldName']); } if ($mapping['type'] === 'int') { $mapping['type'] = 'long'; } elseif ($mapping['type'] === 'float') { $mapping['type'] = 'double'; } $reflProp = $this->reflectionClass->getProperty($mapping['fieldName']); $reflProp->setAccessible(true); $this->reflectionFields[$mapping['fieldName']] = $reflProp; $this->mappings[$mapping['fieldName']] = $mapping; return $mapping; }