protected function groupByPrimaryHash() { $entityWrapper = $this->wrappedEntity->getEntityWrapper(); $byPrimary = []; $value = $this->wrappedEntity->getValue($this->component->name); foreach (is_array($value) || $value instanceof \Traversable ? $value : [] as $subEntity) { $wrappedSubEntity = $entityWrapper->wrap($subEntity); $identifierValue = $wrappedSubEntity->getFlattenIdentifier(); $keyHash = $this->createKeyHash($this->getIdentifierValues($identifierValue)); $byPrimary[$keyHash] = $subEntity; } return $byPrimary; }
/** * @param WrappedEntity $wrappedEntity * @param Container $component * @param array $association * @return null|object */ protected function getRelatedEntity(WrappedEntity $wrappedEntity, Container $component, $association) { $relatedEntity = $wrappedEntity->getValue($component->name); if ($relatedEntity === NULL) { $className = $association['targetEntity']; $entityManager = $wrappedEntity->getEntityManager(); $metadata = $entityManager->getClassMetadata($className); $identifierFields = $metadata->identifier; $data = $component->getValues(TRUE); $relatedEntityIdentifier = $this->getIdentifierFromArray($identifierFields, $data); if ($relatedEntityIdentifier) { $repository = $entityManager->getRepository($className); $relatedEntity = $repository->find($relatedEntityIdentifier); } if (!$relatedEntity) { $relatedEntity = $metadata->newInstance(); } } return $relatedEntity; }