protected function getSessionConfig(
        ServiceLocatorInterface $serviceLocator,
        $sessionConfig
    ) {
        if (empty($sessionConfig)
            || empty($sessionConfig['config'])
        ) {
            return new SessionConfig();
        }

        $class = '\Zend\Session\Config\SessionConfig';
        $options = [];

        if (isset($sessionConfig['config']['class'])
        ) {
            $class = $sessionConfig['config']['class'];
        }

        if (isset($sessionConfig['config']['options'])
        ) {
            $options = $sessionConfig['config']['options'];
        }

        /** @var \Zend\Session\Config\ConfigInterface $sessionConfigObject */
        if ($serviceLocator->has($class)) {
            $sessionConfigObject = $serviceLocator->get($class);
        } else {
            $sessionConfigObject = new $class();
        }

        if (!$sessionConfigObject instanceof ConfigInterface) {
            throw new InvalidArgumentException(
                'Session Config class must implement '
                . '\Zend\Session\Config\ConfigInterface'
            );
        }

        $sessionConfigObject->setOptions($options);

        return $sessionConfigObject;
    }