protected function configureRepository(Config $config): OptionRepository
    {
        $repositories = [];

        foreach ($config->getAll() as $class => $optionsArray) {
            $prefix = array_key_exists(OptionRepository::PREFIX, $optionsArray)
                ? $optionsArray[OptionRepository::PREFIX]
                : '';
            $options = $this->configureOptions((array)$optionsArray);

            try {
                $repositories[] = $this->isPrefixable($class)
                    ? new $class($prefix, $options->getValues())
                    : new $class($options->getValues());
            } catch (Exception $exception) {
                throw InvalidOptionRepository::fromInstantiationException($class, $exception);
            }
        }

        if (empty($repositories)) {
            throw InvalidOptionRepository::fromConfig($config);
        }

        if (1 === count($repositories)) {
            return $repositories[0];
        }

        return new AggregateOptionRepository($repositories);
    }