/** * Loads the metadata for the specified class into the provided container. * * @param string $className * @param BaseClassMetadata $metadata * * @throws MappingException */ public function loadMetadataForClass($className, BaseClassMetadata $metadata) { /** @var ClassMetadata $metadata */ $classAnnotations = $this->reader->getClassAnnotations($metadata->getReflectionClass()); if (count($classAnnotations) === 0) { throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); } $documentAnnot = null; foreach ($classAnnotations as $annot) { if ($annot instanceof AbstractDocument) { if ($documentAnnot !== null) { throw MappingException::duplicateDocumentAnnotation($className); } $documentAnnot = $annot; continue; } switch (true) { case $annot instanceof ChangeTrackingPolicy: $metadata->setChangeTrackingPolicy(constant('Doctrine\\ODM\\OrientDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . $annot->value)); continue; case $annot instanceof DocumentListeners: // handle listeners $this->mapDocumentListeners($className, $metadata, $annot); continue; } } $isDocument = false; switch (true) { case $documentAnnot instanceof Document: $isDocument = true; $metadata->setIsDocument(); break; case $documentAnnot instanceof Vertex: $isDocument = true; $metadata->setIsDocument(); $metadata->setIsVertex(); break; case $documentAnnot instanceof Relationship: $isDocument = true; $metadata->setIsDocument(); $metadata->setIsEdge(); break; case $documentAnnot instanceof EmbeddedDocument: $isDocument = true; $metadata->setIsEmbeddedDocument(); break; case $documentAnnot instanceof MappedSuperclass: $metadata->setIsMappedSuperclass(); break; } if ($documentAnnot instanceof Annotations\AbstractPersistentDocument) { $metadata->setCustomRepositoryClass($documentAnnot->repositoryClass); } if ($isDocument) { if ($documentAnnot->abstract === true) { $metadata->setIsAbstract(); } $metadata->setOrientClass($documentAnnot->oclass); } foreach ($metadata->reflClass->getProperties() as $property) { if ($metadata->isMappedSuperclass() && !$property->isPrivate() || $metadata->isInheritedField($property->name)) { continue; } $pas = $this->reader->getPropertyAnnotations($property); foreach ($pas as $ann) { $mapping = ['fieldName' => $property->getName(), 'nullable' => true]; if ($ann instanceof PropertyBase) { if (!$ann->name) { $ann->name = $property->getName(); } $mapping['name'] = $ann->name; } switch (true) { case $ann instanceof Property: $mapping = $this->propertyToArray($property->getName(), $ann); $metadata->mapField($mapping); continue; case $ann instanceof RID: $metadata->mapRid($property->getName()); continue; case $ann instanceof Version: $metadata->mapVersion($property->getName()); continue; case $ann instanceof Link: $this->mergeLink($ann, $mapping); $mapping['nullable'] = $ann->nullable; $metadata->mapLink($mapping); continue; case $ann instanceof LinkList: $this->mergeLink($ann, $mapping); $metadata->mapLinkList($mapping); continue; case $ann instanceof LinkSet: $this->mergeLink($ann, $mapping); $metadata->mapLinkSet($mapping); continue; case $ann instanceof LinkMap: $this->mergeLink($ann, $mapping); $metadata->mapLinkMap($mapping); continue; case $ann instanceof Embedded: $this->mergeEmbedded($ann, $mapping); $mapping['nullable'] = $ann->nullable; $metadata->mapEmbedded($mapping); continue; case $ann instanceof EmbeddedList: $this->mergeEmbedded($ann, $mapping); $metadata->mapEmbeddedList($mapping); continue; case $ann instanceof EmbeddedSet: $this->mergeEmbedded($ann, $mapping); $metadata->mapEmbeddedSet($mapping); continue; case $ann instanceof EmbeddedMap: $this->mergeEmbedded($ann, $mapping); $metadata->mapEmbeddedMap($mapping); continue; case $ann instanceof RelatedToBase: $this->mergeRelatedToBase($ann, $mapping); $mapping['indirect'] = $ann instanceof RelatedTo; $metadata->mapRelatedToLinkBag($mapping); continue; case $ann instanceof VertexLink: if (isset($ann->targetDoc)) { $mapping['targetDoc'] = $ann->targetDoc; } $dir = $ann instanceof In ? 'in' : 'out'; $metadata->mapVertexLink($mapping, $dir); continue; } } } }
/** * @inheritdoc */ public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata) { /* @var $metadata ClassMetadata */ /* @var $xmlRoot SimpleXMLElement */ $xmlRoot = $this->getElement($className); switch ($xmlRoot->getName()) { case 'document': $metadata->setIsDocument(); break; case 'vertex': $metadata->setIsDocument(); $metadata->setIsVertex(); break; case 'relationship': $metadata->setIsDocument(); $metadata->setIsEdge(); break; case 'embedded-document': $metadata->setIsEmbeddedDocument(); break; case 'mapped-superclass': $metadata->setIsMappedSuperclass(); break; default: throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); } if (isset($xmlRoot['repository-class'])) { $metadata->setCustomRepositoryClass((string) $xmlRoot['repository-class']); } if (isset($xmlRoot['oclass'])) { $metadata->setOrientClass((string) $xmlRoot['oclass']); } if (isset($xmlRoot['abstract']) && (string) $xmlRoot['abstract'] === 'true') { $metadata->setIsAbstract(); } if (isset($xmlRoot->{'rid'})) { $field = $xmlRoot->{'rid'}; $metadata->mapRid((string) $field['fieldName']); } if (isset($xmlRoot->{'version'})) { $field = $xmlRoot->{'version'}; $metadata->mapVersion((string) $field['fieldName']); } if ($metadata->isEdge()) { if (isset($xmlRoot->{'in'})) { $mapping = []; $this->_copyCommonPropertyAttributesToMapping($xmlRoot->{'in'}->attributes(), $mapping); $metadata->mapVertexLink($mapping, 'in'); } if (isset($xmlRoot->{'out'})) { $mapping = []; $this->_copyCommonPropertyAttributesToMapping($xmlRoot->{'out'}->attributes(), $mapping); $metadata->mapVertexLink($mapping, 'out'); } } // Evaluate <change-tracking-policy...> if (isset($xmlRoot['change-tracking-policy'])) { $metadata->setChangeTrackingPolicy(constant(sprintf('%s::CHANGETRACKING_%s', ClassMetadata::class, strtoupper((string) $xmlRoot['change-tracking-policy'])))); } if (isset($xmlRoot->field)) { $this->readFields($metadata, $xmlRoot); } if (isset($xmlRoot->{'embed-one'})) { foreach ($xmlRoot->{'embed-one'} as $node) { $this->addEmbedMapping($metadata, $node, 'one'); } } if (isset($xmlRoot->{'embed-many'})) { foreach ($xmlRoot->{'embed-many'} as $node) { $type = isset($node['collection']) ? (string) $node['collection'] : 'list'; $this->addEmbedMapping($metadata, $node, $type); } } if (isset($xmlRoot->{'link-one'})) { foreach ($xmlRoot->{'link-one'} as $node) { $this->addLinkMapping($metadata, $node, 'one'); } } if (isset($xmlRoot->{'link-many'})) { foreach ($xmlRoot->{'link-many'} as $node) { $type = isset($node['collection']) ? (string) $node['collection'] : 'list'; $this->addLinkMapping($metadata, $node, $type); } } if (isset($xmlRoot->{'related-to'})) { foreach ($xmlRoot->{'related-to'} as $node) { $this->addRelatedToMapping($metadata, $node); } } if (isset($xmlRoot->{'related-to-via'})) { foreach ($xmlRoot->{'related-to-via'} as $node) { $this->addRelatedToMapping($metadata, $node, false); } } // Evaluate entity listener if (isset($xmlRoot->{'document-listeners'})) { /** @var SimpleXMLElement $listenerElement */ foreach ($xmlRoot->{'document-listeners'}->{'document-listener'} as $listenerElement) { $className = (string) $listenerElement['class']; // Evaluate the listener using naming convention. if ($listenerElement->count() === 0) { DocumentListenerBuilder::bindDocumentListener($metadata, $className); continue; } foreach ($listenerElement as $callbackElement) { $eventName = (string) $callbackElement['type']; $methodName = (string) $callbackElement['method']; $metadata->addDocumentListener($eventName, $className, $methodName); } } } }