ExportVarnishConfig.php 1.8 KB

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