Your IP : 216.73.216.220


Current Path : /var/www/www.indacotrentino.com/www/app/code/Amasty/ExportCore/Export/Template/
Upload File :
Current File : /var/www/www.indacotrentino.com/www/app/code/Amasty/ExportCore/Export/Template/RendererProvider.php

<?php

declare(strict_types=1);

/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Export Core for Magento 2 (System)
 */

namespace Amasty\ExportCore\Export\Template;

use Amasty\ExportCore\Api\Template\RendererInterface;
use Magento\Framework\ObjectManagerInterface;

class RendererProvider
{
    /**
     * @var ObjectManagerInterface
     */
    private $objectManager;

    /**
     * @var TemplateConfig
     */
    private $templateConfig;

    public function __construct(
        ObjectManagerInterface $objectManager,
        TemplateConfig $templateConfig
    ) {
        $this->objectManager = $objectManager;
        $this->templateConfig = $templateConfig;
    }

    public function getRenderer(string $type): RendererInterface
    {
        $rendererClass = $this->templateConfig->get($type)['rendererClass'];

        if (!is_subclass_of($rendererClass, RendererInterface::class)) {
            throw new \RuntimeException('Wrong source renderer class: "' . $rendererClass);
        }

        return $this->objectManager->create($rendererClass);
    }
}