public function getInstance(FamilyInterface $family)
    {
        if (!$family->isSingleton()) {
            throw new \LogicException("Family {$family->getCode()} is not a singleton");
        }
        $qb = $this->createQueryBuilder('e')
            ->andWhere('e.family = :familyCode')
            ->join('e.values', 'values')
            ->setParameters(
                [
                    'familyCode' => $family->getCode(),
                ]
            );

        $instance = $qb->getQuery()->getOneOrNullResult();
        if (!$instance) {
            $dataClass = $family->getDataClass();
            $instance = new $dataClass($family);
        }

        return $instance;
    }
public function getInstance(FamilyInterface $family)
    {
        if (!$family->isSingleton()) {
            throw new \LogicException("Family {$family->getCode()} is not a singleton");
        }
        $qb = $this->createQueryBuilder('e')
            ->andWhere('e.family = :familyCode')
            ->join('e.values', 'values')
            ->setParameters(
                [
                    'familyCode' => $family->getCode(),
                ]
            );

        $instance = $qb->getQuery()->getOneOrNullResult();
        if (!$instance) {
            $dataClass = $family->getDataClass();
            $instance = new $dataClass($family);
        }

        return $instance;
    }
public function getInstance ( FamilyInterface $ family ) { if ( ! $ family -> isSingleton ( ) ) { throw new \ LogicException ( "Family {$family->getCode()} is not a singleton" ) ; } $ qb = $ this -> createQueryBuilder ( 'e' ) -> andWhere ( 'e.family = :familyCode' ) -> join ( 'e.values' , 'values' ) -> setParameters ( [ 'familyCode' => $ family -> getCode ( ) , ] ) ; $ instance = $ qb -> getQuery ( ) -> getOneOrNullResult ( ) ; if ( ! $ instance ) { $ dataClass = $ family -> getDataClass ( ) ; $ instance = new $ dataClass ( $ family ) ; } return $ instance ; }
Return singleton for a given family

@param FamilyInterface $family

@throws \LogicException
@throws \Doctrine\ORM\NonUniqueResultException

@return DataInterface
Return singleton for a given family