/** * @param object[] $entities * @param string $entityClass * * @return array */ protected function getEntityIds($entities, $entityClass) { $ids = []; $idFieldName = $this->getEntityIdFieldName($entityClass); foreach ($entities as $entity) { $id = $this->dataAccessor->getValue($entity, $idFieldName); if (!isset($ids[$id])) { $ids[$id] = $id; } } return array_values($ids); }
/** * @param mixed $entity * @param string $entityClass * @param array $config * * @return array */ protected function serializeItem($entity, $entityClass, $config) { if (!$entity) { return []; } $result = []; $entityMetadata = $this->doctrineHelper->getEntityMetadata($entityClass); $resultFields = $this->getFieldsToSerialize($entityClass, $config); foreach ($resultFields as $field) { $value = null; if ($this->dataAccessor->tryGetValue($entity, $field, $value)) { $targetConfig = $this->getFieldConfig($config, $field); if ($entityMetadata->isAssociation($field)) { if ($value !== null) { if (!empty($targetConfig['fields'])) { if (is_string($targetConfig['fields'])) { $value = $this->dataAccessor->getValue($value, $targetConfig['fields']); $value = $this->dataTransformer->transform($entityClass, $field, $value, $targetConfig); } else { $value = $this->serializeItem($value, $entityMetadata->getAssociationTargetClass($field), $targetConfig); } } else { $value = $this->dataTransformer->transform($entityClass, $field, $value, $targetConfig); } } } else { $value = $this->dataTransformer->transform($entityClass, $field, $value, $targetConfig); } $result[$this->getResultFieldName($field, $targetConfig)] = $value; } } return $result; }