TransportInterfacePlugin.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Email\Model\Mail;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Framework\Exception\MailException;
  9. use Magento\Framework\Mail\TransportInterface;
  10. use Magento\Store\Model\ScopeInterface;
  11. /**
  12. * Plugin over \Magento\Framework\Mail\TransportInterface
  13. *
  14. * It disables email sending depending on the system configuration settings
  15. */
  16. class TransportInterfacePlugin
  17. {
  18. /**
  19. * @var ScopeConfigInterface
  20. */
  21. private $scopeConfig;
  22. /**
  23. * @param ScopeConfigInterface $scopeConfig
  24. */
  25. public function __construct(
  26. ScopeConfigInterface $scopeConfig
  27. ) {
  28. $this->scopeConfig = $scopeConfig;
  29. }
  30. /**
  31. * Omit email sending depending on the system configuration setting
  32. *
  33. * @param TransportInterface $subject
  34. * @param \Closure $proceed
  35. * @return void
  36. * @throws MailException
  37. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  38. */
  39. public function aroundSendMessage(
  40. TransportInterface $subject,
  41. \Closure $proceed
  42. ) {
  43. if (!$this->scopeConfig->isSetFlag('system/smtp/disable', ScopeInterface::SCOPE_STORE)) {
  44. $proceed();
  45. }
  46. }
  47. }