protected function findEntityByConditions($entity, array
$conditions) { $repo =
$this->
getManager()->
getRepository($entity);
if (!
$repo instanceof ModelRepository
) { throw new RuntimeException(sprintf('Passed entity has no configured repository: %s',
$entity));
} foreach ($conditions as $condition) { $instance =
$repo->
findOneBy($condition);
if ($instance) { return $instance;
} } return null;
} /**
* Helper function to resolve one to many associations for an entity.
* The function do the following thinks:
* It iterates all conditions which passed. The conditions contains the property names
* which can be used as identifier like array("id", "name", "number", ...).
* If the property isn't set in the passed data array the function continue with the next condition.
* If the property is set, the function looks into the passed collection element if
* the item is already exist in the entity collection.
* In case that the collection don't contains the entity, the function throws an exception.
* If no property is set, the function creates a new entity and adds the instance into the
* passed collection and persist the entity.
*
* @template TEntity of ModelEntity
*
* @param ArrayCollection<array-key, TEntity> $collection
* @param array<string, mixed> $data
* @param class-string<TEntity> $entityType
* @param array<string> $conditions
*
* @throws CustomValidationException
*
* @return TEntity
*/