LdapTools\LdapManager::getRepository PHP Method

getRepository() public method

Get a repository for a specific LDAP object type.
public getRepository ( string $type ) : LdapObjectRepository
$type string
return LdapTools\Object\LdapObjectRepository
    public function getRepository($type)
    {
        try {
            $ldapObjectSchema = $this->getLdapObjectSchema($type);
            $repositoryClass = $ldapObjectSchema->getRepository();
            if (!class_exists($repositoryClass)) {
                throw new \RuntimeException(sprintf('Repository class "%s" not found.', $repositoryClass));
            }
            $repository = new $repositoryClass($ldapObjectSchema, $this->getConnection());
            if (!$repository instanceof LdapObjectRepository) {
                throw new \RuntimeException('Your repository class must extend \\LdapTools\\Object\\LdapObjectRepository.');
            }
        } catch (\Exception $e) {
            throw new \RuntimeException(sprintf('Unable to load Repository for type "%s": %s', $type, $e->getMessage()));
        } catch (\Throwable $e) {
            throw new \RuntimeException(sprintf('Unable to load Repository for type "%s": %s', $type, $e->getMessage()));
        }
        return $repository;
    }