CacheInvalidator.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\WebapiSecurity\Model\Plugin;
  7. class CacheInvalidator
  8. {
  9. /**
  10. * @var \Magento\Framework\App\Cache\TypeListInterface
  11. */
  12. protected $cacheTypeList;
  13. /**
  14. * CacheInvalidator constructor.
  15. *
  16. * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  17. */
  18. public function __construct(\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList)
  19. {
  20. $this->cacheTypeList = $cacheTypeList;
  21. }
  22. /**
  23. * Invalidate WebApi cache if needed.
  24. *
  25. * @param \Magento\Framework\App\Config\Value $subject
  26. * @param \Magento\Framework\App\Config\Value $result
  27. * @return \Magento\Framework\App\Config\Value
  28. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  29. */
  30. public function afterAfterSave(
  31. \Magento\Framework\App\Config\Value $subject,
  32. \Magento\Framework\App\Config\Value $result
  33. ) {
  34. if ($result->getPath() == \Magento\WebapiSecurity\Model\Plugin\AnonymousResourceSecurity::XML_ALLOW_INSECURE
  35. && $result->isValueChanged()
  36. ) {
  37. $this->cacheTypeList->invalidate(\Magento\Webapi\Model\Cache\Type\Webapi::TYPE_IDENTIFIER);
  38. }
  39. return $result;
  40. }
  41. }