Cache.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Controller\Adminhtml;
  7. use Magento\Backend\App\Action;
  8. use Magento\Framework\Exception\LocalizedException;
  9. abstract class Cache extends Action
  10. {
  11. /**
  12. * Authorization level of a basic admin session
  13. *
  14. * @see _isAllowed()
  15. */
  16. const ADMIN_RESOURCE = 'Magento_Backend::cache';
  17. /**
  18. * @var \Magento\Framework\App\Cache\TypeListInterface
  19. */
  20. protected $_cacheTypeList;
  21. /**
  22. * @var \Magento\Framework\App\Cache\StateInterface
  23. */
  24. protected $_cacheState;
  25. /**
  26. * @var \Magento\Framework\App\Cache\Frontend\Pool
  27. */
  28. protected $_cacheFrontendPool;
  29. /**
  30. * @var \Magento\Framework\View\Result\PageFactory
  31. */
  32. protected $resultPageFactory;
  33. /**
  34. * @param Action\Context $context
  35. * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  36. * @param \Magento\Framework\App\Cache\StateInterface $cacheState
  37. * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
  38. * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
  39. */
  40. public function __construct(
  41. Action\Context $context,
  42. \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
  43. \Magento\Framework\App\Cache\StateInterface $cacheState,
  44. \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool,
  45. \Magento\Framework\View\Result\PageFactory $resultPageFactory
  46. ) {
  47. parent::__construct($context);
  48. $this->_cacheTypeList = $cacheTypeList;
  49. $this->_cacheState = $cacheState;
  50. $this->_cacheFrontendPool = $cacheFrontendPool;
  51. $this->resultPageFactory = $resultPageFactory;
  52. }
  53. /**
  54. * Check whether specified cache types exist
  55. *
  56. * @param array $types
  57. * @return void
  58. * @throws \Magento\Framework\Exception\LocalizedException
  59. */
  60. protected function _validateTypes(array $types)
  61. {
  62. if (empty($types)) {
  63. return;
  64. }
  65. $allTypes = array_keys($this->_cacheTypeList->getTypes());
  66. $invalidTypes = array_diff($types, $allTypes);
  67. if (count($invalidTypes) > 0) {
  68. throw new LocalizedException(__('These cache type(s) don\'t exist: %1', join(', ', $invalidTypes)));
  69. }
  70. }
  71. }