public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{
$xmlRoot = $this->getElement($className);
if ($xmlRoot->getName() == 'entity') {
if (isset($xmlRoot['root']) && $xmlRoot['root'] == "true") {
$metadata->isRoot = true;
$metadata->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
}
} else {
if ($xmlRoot->getName() == 'mapped-superclass') {
$metadata->isMappedSuperclass = true;
} else {
throw MappingException::classIsNotAValidXmlEntityOrXmlMappedSuperClass($className);
}
}
$metadata->setName($className);
// Evalute xml-name attribute
if (isset($xmlRoot['xml-name'])) {
$metadata->setXmlName((string) $xmlRoot['xml-name']);
} else {
$metadata->setXmlName(Inflector::xmlize($className));
}
// Evaluate change-tracking-policy attribute
if (isset($xmlRoot['change-tracking-policy'])) {
$metadata->setChangeTrackingPolicy(constant('Doctrine\\OXM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot['change-tracking-policy'])));
}
// Evaluate <namespaces...>
if (isset($xmlRoot->namespaces)) {
$namespaces = array();
foreach ($xmlRoot->namespaces->namespace as $namespace) {
$namespaces[] = array('url' => (string) $namespace['url'], 'prefix' => (string) $namespace['prefix']);
}
$metadata->setXmlNamespaces($namespaces);
}
// Evaluate <field ...> mappings
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $fieldMapping) {
$mapping = array('fieldName' => (string) $fieldMapping['name'], 'type' => (string) $fieldMapping['type'], 'node' => constant('Doctrine\\OXM\\Mapping\\ClassMetadata::XML_' . strtoupper((string) $fieldMapping['node'])));
if (isset($fieldMapping['xml-name'])) {
$mapping['name'] = (string) $fieldMapping['xml-name'];
}
if (isset($fieldMapping['identifier'])) {
$mapping['id'] = (bool) $fieldMapping['identifier'];
}
if (isset($fieldMapping['direct'])) {
$mapping['direct'] = (bool) $fieldMapping['direct'];
}
if (isset($fieldMapping['nulable'])) {
$mapping['nullable'] = (bool) $fieldMapping['nullable'];
}
if (isset($fieldMapping['required'])) {
$mapping['required'] = (bool) $fieldMapping['required'];
}
if (isset($fieldMapping['collection'])) {
$mapping['collection'] = (bool) $fieldMapping['collection'];
}
if (isset($fieldMapping['get-method'])) {
$mapping['getMethod'] = (string) $fieldMapping['get-method'];
}
if (isset($fieldMapping['set-method'])) {
$mapping['setMethod'] = (string) $fieldMapping['set-method'];
}
if (isset($fieldMapping['prefix'])) {
$mapping['prefix'] = (string) $fieldMapping['prefix'];
}
if (isset($fieldMapping['wrapper'])) {
$mapping['wrapper'] = (string) $fieldMapping['wrapper'];
}
$metadata->mapField($mapping);
}
}
// Evaluate <lifecycle-callbacks...>
if (isset($xmlRoot->{'lifecycle-callbacks'})) {
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
$metadata->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\OXM\\Events::' . (string) $lifecycleCallback['type']));
}
}
}