Example #1
0
 /**
  * Gets the metadata for a relationship.
  *
  * @param   RelationshipMetadata    $relMeta    The relationship metadata.
  * @return  EntityMetadata
  */
 public function getMetadataForRelationship(RelationshipMetadata $relMeta)
 {
     return $this->getMetadataForType($relMeta->getEntityType());
 }
Example #2
0
 /**
  * Extracts a standard relationship array that the store expects from a raw MongoDB reference value.
  *
  * @param   RelationshipMetadata    $relMeta
  * @param   mixed                   $reference
  * @return  array
  * @throws  \RuntimeException   If the relationship could not be extracted.
  */
 protected function extractRelationship(RelationshipMetadata $relMeta, $reference)
 {
     $simple = false === $relMeta->isPolymorphic();
     $idKey = $this->getIdentifierKey();
     $typeKey = $this->getPolymorphicKey();
     if (true === $simple && is_array($reference) && isset($reference[$idKey])) {
         return ['id' => $reference[$idKey], 'type' => $relMeta->getEntityType()];
     } elseif (true === $simple && !is_array($reference)) {
         return ['id' => $reference, 'type' => $relMeta->getEntityType()];
     } elseif (false === $simple && is_array($reference) && isset($reference[$idKey]) && isset($reference[$typeKey])) {
         return ['id' => $reference[$idKey], 'type' => $reference[$typeKey]];
     } else {
         throw new RuntimeException('Unable to extract a reference id.');
     }
 }