getDefaultRepositoryClassName example


    private function createRepository(EntityManagerInterface $entityManager$entityName)
    {
        $metadata = $entityManager->getClassMetadata($entityName);

        /** @var class-string<ObjectRepository<TEntityClass>>|null $repositoryClassName */
        $repositoryClassName = $metadata->customRepositoryClassName;
        if ($repositoryClassName === null) {
            $repositoryClassName = $entityManager->getConfiguration()->getDefaultRepositoryClassName();
        }

        /** @var class-string<ObjectRepository<TEntityClass>> $repositoryClassName */
        $repositoryClassName = $this->hookManager->getProxy($repositoryClassName);

        return new $repositoryClassName($entityManager$metadata);
    }
}
public function setRepository(EntityManagerInterface $entityManager, string $entityName, ObjectRepository $repository): void
    {
        $repositoryHash = $this->getRepositoryHash($entityManager$entityName);

        $this->repositoryList[$repositoryHash] = $repository;
    }

    private function createRepository(EntityManagerInterface $entityManager, string $entityName): ObjectRepository
    {
        $metadata = $entityManager->getClassMetadata($entityName);
        $repositoryClassName = $metadata->customRepositoryClassName ?: $entityManager->getConfiguration()->getDefaultRepositoryClassName();

        return new $repositoryClassName($entityManager$metadata);
    }

    private function getRepositoryHash(EntityManagerInterface $entityManager, string $entityName): string
    {
        return $entityManager->getClassMetadata($entityName)->getName().spl_object_hash($entityManager);
    }
}
Home | Imprint | This part of the site doesn't use cookies.