/** * @param mixed $object * @param string $targetClassName * @param EntityMetadata|null $targetMetadata * * @return array */ protected function prepareRelatedValue($object, $targetClassName, EntityMetadata $targetMetadata = null) { $idOnly = false; $targetEntityType = null; if (is_array($object) || is_object($object)) { if (null !== $targetMetadata && $targetMetadata->isInheritedType()) { $targetEntityType = $this->getEntityType($this->objectAccessor->getClassName($object), $targetClassName); $data = $this->objectAccessor->toArray($object); if ($this->isIdentity($data, $targetMetadata)) { $idOnly = true; $object = count($data) === 1 ? reset($data) : $data; } } } else { $idOnly = true; } if (!$targetEntityType) { $targetEntityType = $this->getEntityType($targetClassName); } return ['value' => $object, 'entityType' => $targetEntityType, 'idOnly' => $idOnly]; }