<?php

namespace Application\Service\Extension;


use Application\Service\Extension\Uploader\UploadException;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;

class CommonServiceFactory implements FactoryInterface
{
    private static array $instance = [];
    /**
     * @param ContainerInterface $container
     * @param string $requestedName
     * @param array|null $options
     * @return mixed
     * @throws UploadException
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        if (isset(self::$instance[$requestedName])) {
            return self::$instance[$requestedName];
        }
        self::$instance[$requestedName] = new $requestedName($container);
        return self::$instance[$requestedName];
    }
}