Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
VclTemplateLocator.php
Go to the documentation of this file.
1 <?php
8 
15 
17 {
21  const VARNISH_5_CONFIGURATION_PATH = 'system/full_page_cache/varnish5/path';
22 
26  const VARNISH_4_CONFIGURATION_PATH = 'system/full_page_cache/varnish4/path';
27 
32 
37 
41  private $supportedVarnishVersions = [
42  self::VARNISH_SUPPORTED_VERSION_4 => self::VARNISH_4_CONFIGURATION_PATH,
43  self::VARNISH_SUPPORTED_VERSION_5 => self::VARNISH_5_CONFIGURATION_PATH,
44  ];
45 
49  private $reader;
50 
54  private $readFactory;
55 
59  private $scopeConfig;
60 
68  public function __construct(Reader $reader, ReadFactory $readFactory, ScopeConfigInterface $scopeConfig)
69  {
70  $this->reader = $reader;
71  $this->readFactory = $readFactory;
72  $this->scopeConfig = $scopeConfig;
73  }
74 
78  public function getTemplate($version)
79  {
80  $moduleEtcPath = $this->reader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_PageCache');
81  $configFilePath = $moduleEtcPath . '/' . $this->scopeConfig->getValue($this->getVclTemplatePath($version));
82  $directoryRead = $this->readFactory->create($moduleEtcPath);
83  $configFilePath = $directoryRead->getRelativePath($configFilePath);
84  $template = $directoryRead->readFile($configFilePath);
85  return $template;
86  }
87 
95  private function getVclTemplatePath($version)
96  {
97  if (!isset($this->supportedVarnishVersions[$version])) {
98  throw new UnsupportedVarnishVersion(__('Unsupported varnish version'));
99  }
100 
101  return $this->supportedVarnishVersions[$version];
102  }
103 }
__()
Definition: __.php:13
__construct(Reader $reader, ReadFactory $readFactory, ScopeConfigInterface $scopeConfig)
$template
Definition: export.php:12