codeTemplates/src/Entity/Savers/TemplateEntityUpserter.php
public function getUpsertDtoByCriteria(
        array $criteria,
        NewUpsertDtoDataModifierInterface $modifier
    ): TemplateEntityDto {
        $entity = $this->repository->findOneBy($criteria);
        if ($entity === null) {
            $dto = $this->dtoFactory->create();
            $modifier->addDataToNewlyCreatedDto($dto);

            return $dto;
        }

        return $this->dtoFactory->createDtoFromTemplateEntity($entity);
    }
public function getUpsertDtoByCriteria(
        array $criteria,
        NewUpsertDtoDataModifierInterface $modifier
    ): TemplateEntityDto {
        $entity = $this->repository->findOneBy($criteria);
        if ($entity === null) {
            $dto = $this->dtoFactory->create();
            $modifier->addDataToNewlyCreatedDto($dto);

            return $dto;
        }

        return $this->dtoFactory->createDtoFromTemplateEntity($entity);
    }
public function getUpsertDtoByCriteria ( array $ criteria , NewUpsertDtoDataModifierInterface $ modifier ) : TemplateEntityDto { $ entity = $ this -> repository -> findOneBy ( $ criteria ) ; if ( $ entity === null ) { $ dto = $ this -> dtoFactory -> create ( ) ; $ modifier -> addDataToNewlyCreatedDto ( $ dto ) ; return $ dto ; } return $ this -> dtoFactory -> createDtoFromTemplateEntity ( $ entity ) ; }
This method is used to get a DTO using search criteria, when you are not certain if the entity exists or not.
The criteria is passed through to the repository findOneBy method, if an entity is found then a DTO will be
created from it and returned.

If an entity is not found then a new empty DTO will be created and returned instead.

@param array                             $criteria
@param NewUpsertDtoDataModifierInterface $modifier

@return TemplateEntityDto
@see \Doctrine\ORM\EntityRepository::findOneBy for how to use the crietia
This method is used to get a DTO using search criteria when you are not certain if the entity exists or not . The criteria is passed through to the repository findOneBy method if an entity is found then a DTO will be created from it and returned .