<?php

/**
 * Lifestyle Webconsulting GmbH
 *
 * LICENSE: This Software is the property of Lifestyle Webconsulting GmbH (Aschaffenburg, Germany)
 * and is private by copyright law - it is NOT Freeware.
 *
 * Any unauthorized use of this software without a valid license
 * is a violation of the license agreement and will be prosecuted by
 * civil and criminal law.
 *
 * @copyright  2016 Lifestyle Webconsulting GmbH
 * @link       http://www.life-style.de
 */

namespace Sso\WebserviceBundle\Services\UserApplication\ShowDetails\Response;

use Sso\WebserviceBundle\Api\ApiManagerInterface;
use Sso\WebserviceBundle\Services\ApiVersionInflectorInterface;

/**
 * Class Factory
 *
 * @copyright  2016 Lifestyle Webconsulting GmbH
 * @link       http://www.life-style.de
 * @package Sso\WebserviceBundle\Services\UserApplication\ShowDetails\Response
 */
final class Factory
{
    /**
     * @var ApiManagerInterface
     */
    private $apiM;

    /**
     * @var ApiVersionInflectorInterface
     */
    private $apiVersionInflector;

    /**
     * @var array
     */
    private $factory = array();

    /**
     * Factory constructor.
     * @param ApiManagerInterface $apiM
     * @param ApiVersionInflectorInterface $apiVersionInflector
     */
    public function __construct(ApiManagerInterface $apiM, ApiVersionInflectorInterface $apiVersionInflector)
    {
        $this->apiM = $apiM;
        $this->apiVersionInflector = $apiVersionInflector;
    }

    /**
     * @return ResponseFactoryInterface
     */
    public function factory()
    {
        $className = $this->apiVersionInflector->inflect(__NAMESPACE__, 'Factory');
        return isset($this->factory[__METHOD__]) ? $this->factory[__METHOD__] : ($this->factory[__METHOD__] = new $className($this->apiM));
    }
}
