/**
  * @param EntityMetadata  $entityMetadata
  * @param array           $config
  * @param MetadataContext $context
  */
 protected function loadMetadataForRelatedEntities(EntityMetadata $entityMetadata, array $config, MetadataContext $context)
 {
     $associations = $entityMetadata->getAssociations();
     foreach ($associations as $associationName => $association) {
         if (null !== $association->getTargetMetadata()) {
             // metadata for an associated entity is already loaded
             continue;
         }
         if (!isset($config[ConfigUtil::FIELDS][$associationName][ConfigUtil::FIELDS])) {
             // a configuration of an association fields does not exist
             continue;
         }
         $relatedEntityMetadata = $this->metadataProvider->getMetadata($association->getTargetClassName(), $context->getVersion(), $context->getRequestType(), $context->getExtras(), $config[ConfigUtil::FIELDS][$associationName]);
         if (null !== $relatedEntityMetadata) {
             $association->setTargetMetadata($relatedEntityMetadata);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Loads an entity metadata.
  */
 protected function loadMetadata()
 {
     $entityClass = $this->getClassName();
     if (empty($entityClass)) {
         throw new \RuntimeException('A class name must be set in the context before metadata are loaded.');
     }
     // load metadata by a metadata provider
     $metadata = $this->metadataProvider->getMetadata($entityClass, $this->getVersion(), $this->getRequestType(), $this->getMetadataExtras(), $this->getConfig());
     // add loaded metadata to the context
     $this->set(self::METADATA, $metadata);
 }