/** * {@inheritdoc} */ public function loadMetadataForClass($className, ClassMetadata $class) { $element = $this->getElement($className); if (!$element) { return; } $element['type'] = isset($element['type']) ? $element['type'] : 'document'; if ($element['type'] == 'document') { if (isset($element['repositoryClass'])) { $class->setCustomRepositoryClassName($element['repositoryClass']); } if (isset($element['versionable']) && $element['versionable']) { $class->setVersioned($element['versionable']); } $class->setNodeType(isset($element['nodeType']) ? $element['nodeType'] : 'nt:unstructured'); } elseif ($element['type'] === 'mappedSuperclass') { $class->isMappedSuperclass = true; } if (isset($element['fields'])) { foreach ($element['fields'] as $fieldName => $mapping) { if (is_string($mapping)) { $type = $mapping; $mapping = array(); $mapping['type'] = $type; } if (!isset($mapping['fieldName'])) { $mapping['fieldName'] = $fieldName; } $class->mapField($mapping); } } if (isset($element['id'])) { $mapping = array('fieldName' => $element['id'], 'id' => true); if (isset($element['id']['generator']['strategy'])) { $mapping['strategy'] = $element['id']['generator']['strategy']; } $class->mapId($mapping); } if (isset($element['node'])) { $class->mapNode(array('fieldName' => $element['node'])); } if (isset($element['nodename'])) { $class->mapNodename(array('fieldName' => $element['nodename'])); } if (isset($element['parentdocument'])) { $class->mapParentDocument(array('fieldName' => $element['parentdocument'])); } if (isset($element['child'])) { foreach ($element['child'] as $fieldName => $mapping) { if (is_string($mapping)) { $name = $mapping; $mapping = array(); $mapping['name'] = $name; } if (!isset($mapping['fieldName'])) { $mapping['fieldName'] = $fieldName; } $class->mapChild($mapping); } } if (isset($element['children'])) { foreach ($element['children'] as $fieldName => $mapping) { if (is_string($mapping)) { $filter = $mapping; $mapping = array(); $mapping['filter'] = $filter; } if (!isset($mapping['fieldName'])) { $mapping['fieldName'] = $fieldName; } $class->mapChildren($mapping); } } if (isset($element['referenceOne'])) { foreach ($element['referenceOne'] as $fieldName => $reference) { $this->addMappingFromReference($class, $fieldName, $reference, 'one'); } } if (isset($element['referenceMany'])) { foreach ($element['referenceMany'] as $fieldName => $reference) { $this->addMappingFromReference($class, $fieldName, $reference, 'many'); } } // TODO: referrers, locale if (isset($element['versionName'])) { $class->mapVersionName(array('fieldName' => $element['versionName'])); } if (isset($element['versionCreated'])) { $class->mapVersionCreated(array('fieldName' => $element['versionCreated'])); } if (isset($element['lifecycleCallbacks'])) { foreach ($element['lifecycleCallbacks'] as $type => $methods) { foreach ($methods as $method) { $class->addLifecycleCallback($method, constant('Doctrine\\ODM\\PHPCR\\Event::' . $type)); } } } }
/** * {@inheritdoc} */ public function loadMetadataForClass($className, ClassMetadata $metadata) { /** @var $metadata \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */ $reflClass = $metadata->getReflectionClass(); $documentAnnots = array(); foreach ($this->reader->getClassAnnotations($reflClass) as $annot) { foreach ($this->entityAnnotationClasses as $annotClass => $i) { if ($annot instanceof $annotClass) { $documentAnnots[$i] = $annot; } } } if (!$documentAnnots) { throw MappingException::classIsNotAValidDocument($className); } // find the winning document annotation ksort($documentAnnots); $documentAnnot = reset($documentAnnots); if ($documentAnnot instanceof ODM\MappedSuperclass) { $metadata->isMappedSuperclass = true; } if (null !== $documentAnnot->referenceable) { $metadata->setReferenceable($documentAnnot->referenceable); } if (null !== $documentAnnot->versionable) { $metadata->setVersioned($documentAnnot->versionable); } if (null !== $documentAnnot->mixins) { $metadata->setMixins($documentAnnot->mixins); } if (null !== $documentAnnot->inheritMixins) { $metadata->setInheritMixins($documentAnnot->inheritMixins); } if (null !== $documentAnnot->nodeType) { $metadata->setNodeType($documentAnnot->nodeType); } if (null !== $documentAnnot->repositoryClass) { $metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass); } if (null !== $documentAnnot->translator) { $metadata->setTranslator($documentAnnot->translator); } foreach ($reflClass->getProperties() as $property) { if ($metadata->isInheritedField($property->name) && $metadata->name !== $property->getDeclaringClass()->getName()) { continue; } $mapping = array(); $mapping['fieldName'] = $property->getName(); foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) { if ($fieldAnnot instanceof ODM\Property) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapField($mapping); } elseif ($fieldAnnot instanceof ODM\Id) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapId($mapping); } elseif ($fieldAnnot instanceof ODM\Node) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapNode($mapping); } elseif ($fieldAnnot instanceof ODM\Nodename) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapNodename($mapping); } elseif ($fieldAnnot instanceof ODM\ParentDocument) { $mapping = array_merge($mapping, (array) $fieldAnnot); $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade); $metadata->mapParentDocument($mapping); } elseif ($fieldAnnot instanceof ODM\Child) { $mapping = array_merge($mapping, (array) $fieldAnnot); $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade); $metadata->mapChild($mapping); } elseif ($fieldAnnot instanceof ODM\Children) { $mapping = array_merge($mapping, (array) $fieldAnnot); $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade); $metadata->mapChildren($mapping); } elseif ($fieldAnnot instanceof ODM\ReferenceOne) { $mapping = array_merge($mapping, (array) $fieldAnnot); $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade); $metadata->mapManyToOne($mapping); } elseif ($fieldAnnot instanceof ODM\ReferenceMany) { $mapping = array_merge($mapping, (array) $fieldAnnot); $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade); $metadata->mapManyToMany($mapping); } elseif ($fieldAnnot instanceof ODM\Referrers) { $mapping = array_merge($mapping, (array) $fieldAnnot); $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade); $metadata->mapReferrers($mapping); } elseif ($fieldAnnot instanceof ODM\MixedReferrers) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapMixedReferrers($mapping); } elseif ($fieldAnnot instanceof ODM\Locale) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapLocale($mapping); } elseif ($fieldAnnot instanceof ODM\Depth) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapDepth($mapping); } elseif ($fieldAnnot instanceof ODM\VersionName) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapVersionName($mapping); } elseif ($fieldAnnot instanceof ODM\VersionCreated) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapVersionCreated($mapping); } } } foreach ($reflClass->getMethods() as $method) { if ($method->isPublic() && $method->getDeclaringClass()->getName() == $metadata->name) { foreach ($this->reader->getMethodAnnotations($method) as $annot) { if ($annot instanceof ODM\PrePersist) { $metadata->addLifecycleCallback($method->getName(), Event::prePersist); } elseif ($annot instanceof ODM\PostPersist) { $metadata->addLifecycleCallback($method->getName(), Event::postPersist); } elseif ($annot instanceof ODM\PreUpdate) { $metadata->addLifecycleCallback($method->getName(), Event::preUpdate); } elseif ($annot instanceof ODM\PostUpdate) { $metadata->addLifecycleCallback($method->getName(), Event::postUpdate); } elseif ($annot instanceof ODM\PreRemove) { $metadata->addLifecycleCallback($method->getName(), Event::preRemove); } elseif ($annot instanceof ODM\PostRemove) { $metadata->addLifecycleCallback($method->getName(), Event::postRemove); } elseif ($annot instanceof ODM\PostLoad) { $metadata->addLifecycleCallback($method->getName(), Event::postLoad); } } } } $metadata->validateClassMapping(); }
/** * {@inheritdoc} */ public function loadMetadataForClass($className, ClassMetadata $class) { /** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */ try { $element = $this->getElement($className); } catch (DoctrineMappingException $e) { // Convert Exception type for consistency with other drivers throw new MappingException($e->getMessage(), $e->getCode(), $e); } if (!$element) { return; } $element['type'] = isset($element['type']) ? $element['type'] : 'document'; if (isset($element['repositoryClass'])) { $class->setCustomRepositoryClassName($element['repositoryClass']); } if (isset($element['translator'])) { $class->setTranslator($element['translator']); } if (isset($element['versionable']) && $element['versionable']) { $class->setVersioned($element['versionable']); } if (isset($element['referenceable']) && $element['referenceable']) { $class->setReferenceable($element['referenceable']); } if (isset($element['uniqueNodeType']) && $element['uniqueNodeType']) { $class->setUniqueNodeType($element['uniqueNodeType']); } if (isset($element['mixins'])) { $mixins = array(); foreach ($element['mixins'] as $mixin) { $mixins[] = $mixin; } $class->setMixins($mixins); } if (isset($element['inheritMixins'])) { $class->setInheritMixins($element['inheritMixins']); } if (isset($element['nodeType'])) { $class->setNodeType($element['nodeType']); } if ($element['type'] === 'mappedSuperclass') { $class->isMappedSuperclass = true; } if (isset($element['fields'])) { foreach ($element['fields'] as $fieldName => $mapping) { if (is_string($mapping)) { $type = $mapping; $mapping = array(); $mapping['type'] = $type; } if (!isset($mapping['fieldName'])) { $mapping['fieldName'] = $fieldName; } $class->mapField($mapping); } } if (isset($element['uuid'])) { $mapping = array('fieldName' => $element['uuid'], 'uuid' => true); $class->mapField($mapping); } if (isset($element['id'])) { if (is_array($element['id'])) { if (!isset($element['id']['fieldName'])) { throw new MappingException("Missing fieldName property for id field"); } $fieldName = $element['id']['fieldName']; } else { $fieldName = $element['id']; } $mapping = array('fieldName' => $fieldName, 'id' => true); if (isset($element['id']['generator']['strategy'])) { $mapping['strategy'] = $element['id']['generator']['strategy']; } $class->mapId($mapping); } if (isset($element['node'])) { $class->mapNode(array('fieldName' => $element['node'])); } if (isset($element['nodename'])) { $class->mapNodename(array('fieldName' => $element['nodename'])); } if (isset($element['parentdocument'])) { $mapping = array('fieldName' => $element['parentdocument'], 'cascade' => isset($element['cascade']) ? $this->getCascadeMode($element['cascade']) : 0); $class->mapParentDocument($mapping); } if (isset($element['child'])) { foreach ($element['child'] as $fieldName => $mapping) { if (is_string($mapping)) { $name = $mapping; $mapping = array(); $mapping['nodeName'] = $name; } if (!isset($mapping['fieldName'])) { $mapping['fieldName'] = $fieldName; } $mapping['cascade'] = isset($mapping['cascade']) ? $this->getCascadeMode($mapping['cascade']) : 0; $class->mapChild($mapping); } } if (isset($element['children'])) { foreach ($element['children'] as $fieldName => $mapping) { // TODO should we really support this syntax? if (is_string($mapping)) { $filter = $mapping; $mapping = array(); $mapping['filter'] = $filter; } if (!isset($mapping['fieldName'])) { $mapping['fieldName'] = $fieldName; } if (!isset($mapping['filter'])) { $mapping['filter'] = null; } elseif (is_string($mapping['filter'])) { $mapping['filter'] = (array) $mapping['filter']; } if (!isset($mapping['fetchDepth'])) { $mapping['fetchDepth'] = -1; } if (!isset($mapping['ignoreUntranslated'])) { $mapping['ignoreUntranslated'] = false; } $mapping['cascade'] = isset($mapping['cascade']) ? $this->getCascadeMode($mapping['cascade']) : 0; $class->mapChildren($mapping); } } if (isset($element['referenceOne'])) { foreach ($element['referenceOne'] as $fieldName => $reference) { $this->addMappingFromReference($class, $fieldName, $reference, 'one'); } } if (isset($element['referenceMany'])) { foreach ($element['referenceMany'] as $fieldName => $reference) { $this->addMappingFromReference($class, $fieldName, $reference, 'many'); } } if (isset($element['locale'])) { $class->mapLocale(array('fieldName' => $element['locale'])); } if (isset($element['depth'])) { $class->mapDepth(array('fieldName' => $element['depth'])); } if (isset($element['mixedReferrers'])) { foreach ($element['mixedReferrers'] as $name => $attributes) { $mapping = array('fieldName' => $name, 'referenceType' => isset($attributes['referenceType']) ? $attributes['referenceType'] : null); $class->mapMixedReferrers($mapping); } } if (isset($element['referrers'])) { foreach ($element['referrers'] as $name => $attributes) { if (!isset($attributes['referencedBy'])) { throw new MappingException("{$className} is missing the referencedBy attribute for the referrer field {$name}"); } if (!isset($attributes['referringDocument'])) { throw new MappingException("{$className} is missing the referringDocument attribute for the referrer field {$name}"); } $mapping = array('fieldName' => $name, 'referencedBy' => $attributes['referencedBy'], 'referringDocument' => $attributes['referringDocument'], 'cascade' => isset($attributes['cascade']) ? $this->getCascadeMode($attributes['cascade']) : 0); $class->mapReferrers($mapping); } } if (isset($element['versionName'])) { $class->mapVersionName(array('fieldName' => $element['versionName'])); } if (isset($element['versionCreated'])) { $class->mapVersionCreated(array('fieldName' => $element['versionCreated'])); } if (isset($element['lifecycleCallbacks'])) { foreach ($element['lifecycleCallbacks'] as $type => $methods) { foreach ($methods as $method) { $class->addLifecycleCallback($method, constant('Doctrine\\ODM\\PHPCR\\Event::' . $type)); } } } $class->validateClassMapping(); }
/** * {@inheritdoc} */ public function loadMetadataForClass($className, ClassMetadata $class) { $xmlRoot = $this->getElement($className); if (!$xmlRoot) { return; } if ($xmlRoot->getName() == 'document') { if (isset($xmlRoot['repository-class'])) { $class->setCustomRepositoryClassName((string) $xmlRoot['repository-class']); } if (isset($xmlRoot['versionable']) && $xmlRoot['versionable'] !== 'false') { $class->setVersioned($xmlRoot['versionable']); } $class->setNodeType(isset($xmlRoot['nodeType']) ? (string) $xmlRoot['nodeType'] : 'nt:unstructured'); } elseif ($xmlRoot->getName() === 'mapped-superclass') { $class->isMappedSuperclass = true; } if (isset($xmlRoot->field)) { foreach ($xmlRoot->field as $field) { $mapping = array(); $attributes = $field->attributes(); foreach ($attributes as $key => $value) { $mapping[$key] = (string) $value; // convert bool fields if ($key === 'id' || $key === 'multivalue') { $mapping[$key] = 'true' === $mapping[$key] ? true : false; } } $class->mapField($mapping); } } if (isset($xmlRoot->id)) { $class->mapId(array('fieldName' => (string) $xmlRoot->id->attributes()->name, 'id' => true)); } if (isset($xmlRoot->node)) { $class->mapNode(array('fieldName' => (string) $xmlRoot->node->attributes()->name)); } if (isset($xmlRoot->nodename)) { $class->mapNodename(array('fieldName' => (string) $xmlRoot->nodename->attributes()->name)); } if (isset($xmlRoot->parentdocument)) { $class->mapParentDocument(array('fieldName' => (string) $xmlRoot->parentdocument->attributes()->name)); } if (isset($xmlRoot->child)) { foreach ($xmlRoot->child as $child) { $attributes = $child->attributes(); $mapping = array('fieldName' => (string) $attributes->fieldName); if (isset($attributes['name'])) { $mapping['name'] = (string) $attributes->name; } $class->mapChild($mapping); } } if (isset($xmlRoot->children)) { foreach ($xmlRoot->children as $children) { $attributes = $children->attributes(); $mapping = array('fieldName' => (string) $attributes->fieldName); if (isset($attributes['filter'])) { $mapping['filter'] = (string) $attributes->filter; } $class->mapChildren($mapping); } } if (isset($xmlRoot->{'reference-many'})) { foreach ($xmlRoot->{'reference-many'} as $reference) { $this->addReferenceMapping($class, $reference, 'many'); } } if (isset($xmlRoot->{'reference-one'})) { foreach ($xmlRoot->{'reference-one'} as $reference) { $this->addReferenceMapping($class, $reference, 'one'); } } // TODO: referrers, locale if (isset($xmlRoot->versionname)) { $class->mapVersionName(array('fieldName' => (string) $xmlRoot->versionname->attributes()->name)); } if (isset($xmlRoot->versioncreated)) { $class->mapVersionCreated(array('fieldName' => (string) $xmlRoot->versionname->attributes()->name)); } if (isset($xmlRoot->{'lifecycle-callbacks'})) { foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) { $class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ODM\\PHPCR\\Event::' . (string) $lifecycleCallback['type'])); } } }
/** * {@inheritdoc} */ public function loadMetadataForClass($className, ClassMetadata $metadata) { $reflClass = $metadata->getReflectionClass(); $documentAnnots = array(); foreach ($this->reader->getClassAnnotations($reflClass) as $annot) { foreach ($this->entityAnnotationClasses as $annotClass => $i) { if ($annot instanceof $annotClass) { $documentAnnots[$i] = $annot; } } } if (!$documentAnnots) { throw MappingException::classIsNotAValidDocument($className); } // find the winning document annotation ksort($documentAnnots); $documentAnnot = reset($documentAnnots); if (isset($documentAnnot->versionable) && $documentAnnot->versionable) { $metadata->setVersioned($documentAnnot->versionable); } $metadata->setNodeType($documentAnnot->nodeType); if (isset($documentAnnot->referenceable) && $documentAnnot->referenceable) { $metadata->setReferenceable(true); } if ($documentAnnot->repositoryClass) { $metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass); } if ($documentAnnot->translator) { $metadata->setTranslator($documentAnnot->translator); } foreach ($reflClass->getProperties() as $property) { if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) && $metadata->name !== $property->getDeclaringClass()->getName()) { continue; } $mapping = array(); $mapping['fieldName'] = $property->getName(); foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) { if ($fieldAnnot instanceof ODM\Property) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapField($mapping); } elseif ($fieldAnnot instanceof ODM\Id) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapId($mapping); } elseif ($fieldAnnot instanceof ODM\Node) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapNode($mapping); } elseif ($fieldAnnot instanceof ODM\Nodename) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapNodename($mapping); } elseif ($fieldAnnot instanceof ODM\ParentDocument) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapParentDocument($mapping); } elseif ($fieldAnnot instanceof ODM\Child) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapChild($mapping); } elseif ($fieldAnnot instanceof ODM\Children) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapChildren($mapping); } elseif ($fieldAnnot instanceof ODM\ReferenceOne) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapManyToOne($mapping); } elseif ($fieldAnnot instanceof ODM\ReferenceMany) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapManyToMany($mapping); } elseif ($fieldAnnot instanceof ODM\Referrers) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapReferrers($mapping); } elseif ($fieldAnnot instanceof ODM\Locale) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapLocale($mapping); } elseif ($fieldAnnot instanceof ODM\VersionName) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapVersionName($mapping); } elseif ($fieldAnnot instanceof ODM\VersionCreated) { $mapping = array_merge($mapping, (array) $fieldAnnot); $metadata->mapVersionCreated($mapping); } if (!isset($mapping['name'])) { $mapping['name'] = $property->getName(); } } } foreach ($reflClass->getMethods() as $method) { if ($method->isPublic() && $method->getDeclaringClass()->getName() == $metadata->name) { foreach ($this->reader->getMethodAnnotations($method) as $annot) { if ($annot instanceof ODM\PrePersist) { $metadata->addLifecycleCallback($method->getName(), Event::prePersist); } elseif ($annot instanceof ODM\PostPersist) { $metadata->addLifecycleCallback($method->getName(), Event::postPersist); } elseif ($annot instanceof ODM\PreUpdate) { $metadata->addLifecycleCallback($method->getName(), Event::preUpdate); } elseif ($annot instanceof ODM\PostUpdate) { $metadata->addLifecycleCallback($method->getName(), Event::postUpdate); } elseif ($annot instanceof ODM\PreRemove) { $metadata->addLifecycleCallback($method->getName(), Event::preRemove); } elseif ($annot instanceof ODM\PostRemove) { $metadata->addLifecycleCallback($method->getName(), Event::postRemove); } elseif ($annot instanceof ODM\PreLoad) { $metadata->addLifecycleCallback($method->getName(), Event::preLoad); } elseif ($annot instanceof ODM\PostLoad) { $metadata->addLifecycleCallback($method->getName(), Event::postLoad); } } } } // Check there is a @Locale annotation for translatable documents if (count($metadata->translatableFields)) { if (!isset($metadata->localeMapping)) { throw new MappingException("You must define a @Locale field for translatable document '{$className}'"); } } }
/** * {@inheritdoc} */ public function loadMetadataForClass($className, ClassMetadata $class) { /** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */ try { $xmlRoot = $this->getElement($className); } catch (DoctrineMappingException $e) { // Convert Exception type for consistency with other drivers throw new MappingException($e->getMessage(), $e->getCode(), $e); } if (!$xmlRoot) { return; } if (isset($xmlRoot['repository-class'])) { $class->setCustomRepositoryClassName((string) $xmlRoot['repository-class']); } if (isset($xmlRoot['translator'])) { $class->setTranslator((string) $xmlRoot['translator']); } if (isset($xmlRoot['versionable']) && $xmlRoot['versionable'] !== 'false') { $class->setVersioned(strtolower($xmlRoot['versionable'])); } if (isset($xmlRoot['referenceable']) && $xmlRoot['referenceable'] !== 'false') { $class->setReferenceable((bool) $xmlRoot['referenceable']); } if (isset($xmlRoot->mixins)) { $mixins = array(); foreach ($xmlRoot->mixins->mixin as $mixin) { $attributes = $mixin->attributes(); if (!isset($attributes['type'])) { throw new MappingException('<mixin> missing mandatory type attribute'); } $mixins[] = (string) $attributes['type']; } $class->setMixins($mixins); } if (isset($xmlRoot['node-type'])) { $class->setNodeType((string) $xmlRoot['node-type']); } if ($xmlRoot->getName() === 'mapped-superclass') { $class->isMappedSuperclass = true; } if (isset($xmlRoot->field)) { foreach ($xmlRoot->field as $field) { $mapping = array(); $attributes = $field->attributes(); foreach ($attributes as $key => $value) { $mapping[$key] = (string) $value; // convert bool fields if (in_array($key, array('id', 'multivalue', 'assoc', 'translated', 'nullable'))) { $mapping[$key] = 'true' === $mapping[$key] ? true : false; } } if (!isset($mapping['name'])) { throw new MappingException(sprintf('Missing name attribute for field of %s', $className)); } $mapping['fieldName'] = $mapping['name']; unset($mapping['name']); $class->mapField($mapping); } } if (isset($xmlRoot->id)) { $mapping = array('fieldName' => (string) $xmlRoot->id->attributes()->name, 'id' => true); if (isset($xmlRoot->id->generator) && isset($xmlRoot->id->generator->attributes()->strategy)) { $mapping['strategy'] = (string) $xmlRoot->id->generator->attributes()->strategy; } $class->mapId($mapping); } if (isset($xmlRoot->node)) { $class->mapNode(array('fieldName' => (string) $xmlRoot->node->attributes()->name)); } if (isset($xmlRoot->nodename)) { $class->mapNodename(array('fieldName' => (string) $xmlRoot->nodename->attributes()->name)); } if (isset($xmlRoot->{'parent-document'})) { $mapping = array('fieldName' => (string) $xmlRoot->{'parent-document'}->attributes()->name, 'cascade' => isset($xmlRoot->{'parent-document'}->cascade) ? $this->getCascadeMode($xmlRoot->{'parent-document'}->cascade) : 0); $class->mapParentDocument($mapping); } if (isset($xmlRoot->child)) { foreach ($xmlRoot->child as $child) { $attributes = $child->attributes(); $mapping = array('fieldName' => (string) $attributes->name, 'cascade' => isset($child->cascade) ? $this->getCascadeMode($child->cascade) : 0); if (isset($attributes['node-name'])) { $mapping['nodeName'] = (string) $attributes->{'node-name'}; } $class->mapChild($mapping); } } if (isset($xmlRoot->children)) { foreach ($xmlRoot->children as $children) { $attributes = $children->attributes(); $mapping = array('fieldName' => (string) $attributes->name, 'cascade' => isset($children->cascade) ? $this->getCascadeMode($children->cascade) : 0, 'filter' => isset($attributes['filter']) ? (array) $attributes->filter : null, 'fetchDepth' => isset($attributes['fetch-depth']) ? (int) $attributes->{'fetch-depth'} : -1, 'ignoreUntranslated' => !empty($attributes['ignore-untranslated'])); $class->mapChildren($mapping); } } if (isset($xmlRoot->{'reference-many'})) { foreach ($xmlRoot->{'reference-many'} as $reference) { $attributes = $reference->attributes(); $reference['cascade'] = isset($reference->cascade) ? $this->getCascadeMode($reference->cascade) : 0; $reference['fieldName'] = (string) $attributes->name ?: null; $this->addReferenceMapping($class, $reference, 'many'); } } if (isset($xmlRoot->{'reference-one'})) { foreach ($xmlRoot->{'reference-one'} as $reference) { $attributes = $reference->attributes(); $reference['cascade'] = isset($reference->cascade) ? $this->getCascadeMode($reference->cascade) : 0; $reference['fieldName'] = (string) $attributes->name ?: null; $this->addReferenceMapping($class, $reference, 'one'); } } if (isset($xmlRoot->locale)) { $class->mapLocale(array('fieldName' => (string) $xmlRoot->locale->attributes()->name)); } if (isset($xmlRoot->{'mixed-referrers'})) { foreach ($xmlRoot->{'mixed-referrers'} as $mixedReferrers) { $attributes = $mixedReferrers->attributes(); $mapping = array('fieldName' => (string) $attributes->name, 'referenceType' => isset($attributes['reference-type']) ? strtolower((string) $attributes->{'reference-type'}) : null); $class->mapMixedReferrers($mapping); } } if (isset($xmlRoot->referrers)) { foreach ($xmlRoot->referrers as $referrers) { $attributes = $referrers->attributes(); if (!isset($attributes['referenced-by'])) { throw new MappingException("{$className} is missing the referenced-by attribute for the referrer field " . $attributes->name); } if (!isset($attributes['referring-document'])) { throw new MappingException("{$className} is missing the referring-document attribute for the referrer field " . $attributes->name); } // referenceType is determined from the referencedBy field of referringDocument $mapping = array('fieldName' => (string) $attributes->name, 'cascade' => isset($referrers->cascade) ? $this->getCascadeMode($referrers->cascade) : 0, 'referencedBy' => (string) $attributes->{'referenced-by'}, 'referringDocument' => (string) $attributes->{'referring-document'}); $class->mapReferrers($mapping); } } if (isset($xmlRoot->{'version-name'})) { $class->mapVersionName(array('fieldName' => (string) $xmlRoot->{'version-name'}->attributes()->name)); } if (isset($xmlRoot->{'version-created'})) { $class->mapVersionCreated(array('fieldName' => (string) $xmlRoot->{'version-created'}->attributes()->name)); } if (isset($xmlRoot->{'lifecycle-callbacks'})) { foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) { $class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ODM\\PHPCR\\Event::' . (string) $lifecycleCallback['type'])); } } if (isset($xmlRoot->uuid)) { $mapping = array(); $attributes = $xmlRoot->uuid->attributes(); foreach ($attributes as $key => $value) { $mapping[$key] = (string) $value; } if (!array_key_exists('name', $mapping)) { throw new MappingException(sprintf('Missing name attribute for field of %s', $className)); } $mapping['uuid'] = true; $mapping['fieldName'] = $mapping['name']; $class->mapField($mapping); } $class->validateClassMapping(); }