<?php

namespace Application\Factory;

use Application\Service\Redis\RedisExtend;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;

class RedisExtendFactory implements FactoryInterface
{
    private static ?RedisExtend $instance = null;
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $redisConfig = $container->get('config')['caches']['Redis']['adapter']['options'];
        if (self::$instance !== null) {
            return self::$instance->setDatabase($redisConfig['database']);
        }

        // TODO: Implement __invoke() method.
        self::$instance = new $requestedName($redisConfig);

        return self::$instance;
    }
}