Return singleton for a given family

@param FamilyInterface $family

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

@return DataInterface
506314
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;
    }
853835
public function findOneBy(FamilyInterface $family, array $filterBy)
    {
        $qb = $this->getQb($family, $filterBy);
        $pager = new Paginator($qb);
        $pager->getQuery()->setMaxResults(1);

        $result = $pager->getIterator()->current();
        $this->dataLoader->loadSingle($result);

        return $result;
    }
18767
private function significant(Family $family): stdClass
    {
        $significant = (object) [
            'family'     => $family,
            'individual' => null,
            'surname'    => '',
        ];

        foreach ($family->spouses()->merge($family->children()) as $individual) {
            $significant->individual = $individual;
            [$significant->surname] = explode(',', $individual->sortName());
            break;
        }

        return $significant;
    }
684840
public function getChildFamilyLabel(Family $family): string
    {
        if (preg_match('/\n1 FAMC @' . $family->xref() . '@(?:\n[2-9].*)*\n2 PEDI (.+)/', $this->gedcom(), $match)) {
            // A specified pedigree
            return GedcomCodePedi::getChildFamilyLabel($match[1]);
        }

        // Default (birth) pedigree
        return GedcomCodePedi::getChildFamilyLabel('');
    }
55956
protected final Person getMother(final Family family) {
        final FamilyNavigator navigator = new FamilyNavigator(family);
        return navigator.getMother();
    }
233610
public function getAncestor(ConnectionInterface $con = null)
    {
        if ($this->aAncestor === null && ($this->ancestor_id !== null)) {
            $this->aAncestor = ChildSkillQuery::create()->findPk($this->ancestor_id, $con);
            /* The following can be used additionally to
                guarantee the related object contains a reference
                to this object.  This level of coupling may, however, be
                undesirable since it could result in an only partially populated collection
                in the referenced object.
                $this->aAncestor->addLineagesRelatedByAncestorId($this);
             */
        }

        return $this->aAncestor;
    }
688822
public function getAInitializer($family)
    {
        if(!array_key_exists($family, $this->initializersA))
        {
            throw new CoreException('Инициализатор агрегатных(A) типов пакета '.$family.' не найдена в медиаторе!');
        }

        return $this->initializersA[$family];
    }
11764
public function getBDestructor($family)
    {
        if(!array_key_exists($family, $this->destructorsB))
        {
            throw new CoreException('Деструктор агрегатных(B) типов пакета '.$family.' не найдена в медиаторе!');
        }

        return $this->destructorsB[$family];
    }
1194860
public function singleton($className) {
        $closure = function(ContainerInterface $container) use($className) {
            static $instance;
            
            if (is_null($instance)) {
                $instance = $container->make($className);
            }

            return $instance;
        };

        $this->bind($className, $closure);
    }
671904
public function getCUpdateExecutor($family)
    {
        if(!array_key_exists($family, $this->updateExecutorsC))
        {
            throw new CoreException('Исполнитель изменений (update executor) простых(C) типов пакета '.$family.' не найдена в медиаторе!');
        }

        return $this->updateExecutorsC[$family];
    }
753830
protected function getTargetClass(
        FamilyInterface $parentFamily,
        AttributeInterface $attribute,
        $forceSingle = false
    ) {
        $classMetadata = $this->manager->getClassMetadata($parentFamily->getValueClass());
        try {
            $mapping = $classMetadata->getAssociationMapping($attribute->getType()->getDatabaseType());
        } catch (MappingException $e) {
            return null;
        }
        if (empty($mapping['targetEntity'])) {
            return null;
        }

        $type = $mapping['targetEntity'];
        if (!$forceSingle && $attribute->isCollection()) {
            $type .= '[]|Collection';
        }

        return '\\'.$type;
    }
478269
public function readAction(Request $request, DataInterface $data, FamilyInterface $family = null)
    {
        $this->initDataFamily($data, $family);
        $form = $this->getForm($request, $data, ['disabled' => true]);

        return $this->renderAction($this->getViewParameters($request, $form, $data));
    }
885320
protected function isAttributeInherited(FamilyInterface $family, AttributeInterface $attribute)
    {
        if (!$family->getParent()) {
            return false;
        }
        if ($family->getParent()->hasAttribute($attribute->getCode())) {
            return true;
        }

        return $this->isAttributeInherited($family->getParent(), $attribute);
    }
582141
public function getBMapper($family)
    {
        if(!array_key_exists($family, $this->mappersB))
        {
            throw new ExtractorException('Маппер агрегатных(B) типов пакета '.$family.' не найдена в медиаторе!');
        }

        return $this->mappersB[$family];
    }
336769
public function getFamily($family)
    {
        if(array_key_exists($family, $this->familyTypes))
        {
            return $this->familyTypes[$family];
        }
        else
        {
            throw new TaxonomyException('Не найдена коллекция типов пакета '.$family);
        }
    }
904295
public function getFamilyVariant($familyCode, $code): array
    {
        return $this->getFactory()
            ->createAkeneoPimAdapterFactory()
            ->createFamilyVariantApiAdapter()
            ->get($familyCode, $code);
    }
934587
public function getByAncestor(AncestorCriteriaInterface $ancestor)
    {
        $this->model = $ancestor->apply($this->model, $this);
        $results = $this->model->get();
        $this->resetModel();

        return $this->parserResult($results);
    }