1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\PageCache\Controller\Adminhtml\PageCache;
use Magento\Framework\App\Filesystem\DirectoryList;
class ExportVarnishConfig extends \Magento\Backend\App\Action
{
/**
* Authorization level of a basic admin session
*/
const ADMIN_RESOURCE = 'Magento_Backend::system';
/**
* @var \Magento\Backend\App\Response\Http\FileFactory
*/
protected $fileFactory;
/**
* @var \Magento\PageCache\Model\Config
*/
protected $config;
/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
* @param \Magento\PageCache\Model\Config $config
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
\Magento\PageCache\Model\Config $config
) {
parent::__construct($context);
$this->config = $config;
$this->fileFactory = $fileFactory;
}
/**
* Export Varnish Configuration as .vcl
*
* @return \Magento\Framework\App\ResponseInterface
*/
public function execute()
{
$fileName = 'varnish.vcl';
$varnishVersion = $this->getRequest()->getParam('varnish');
switch ($varnishVersion) {
case 5:
$content = $this->config->getVclFile(\Magento\PageCache\Model\Config::VARNISH_5_CONFIGURATION_PATH);
break;
default:
$content = $this->config->getVclFile(\Magento\PageCache\Model\Config::VARNISH_4_CONFIGURATION_PATH);
break;
}
return $this->fileFactory->create($fileName, $content, DirectoryList::VAR_DIR);
}
}