self::VARNISH_4_CONFIGURATION_PATH, self::VARNISH_SUPPORTED_VERSION_5 => self::VARNISH_5_CONFIGURATION_PATH, ]; /** * @var Reader */ private $reader; /** * @var ReadFactory */ private $readFactory; /** * @var ScopeConfigInterface */ private $scopeConfig; /** * VclTemplateLocator constructor. * * @param Reader $reader * @param ReadFactory $readFactory * @param ScopeConfigInterface $scopeConfig */ public function __construct(Reader $reader, ReadFactory $readFactory, ScopeConfigInterface $scopeConfig) { $this->reader = $reader; $this->readFactory = $readFactory; $this->scopeConfig = $scopeConfig; } /** * {@inheritdoc} */ public function getTemplate($version) { $moduleEtcPath = $this->reader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_PageCache'); $configFilePath = $moduleEtcPath . '/' . $this->scopeConfig->getValue($this->getVclTemplatePath($version)); $directoryRead = $this->readFactory->create($moduleEtcPath); $configFilePath = $directoryRead->getRelativePath($configFilePath); $template = $directoryRead->readFile($configFilePath); return $template; } /** * Get Vcl template path * * @param int $version Varnish version * @return string * @throws UnsupportedVarnishVersion */ private function getVclTemplatePath($version) { if (!isset($this->supportedVarnishVersions[$version])) { throw new UnsupportedVarnishVersion(__('Unsupported varnish version')); } return $this->supportedVarnishVersions[$version]; } }