AbstractSynchronization.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AdminNotification\Model\System\Message\Media;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. abstract class AbstractSynchronization implements \Magento\Framework\Notification\MessageInterface
  12. {
  13. /**
  14. * @var \Magento\MediaStorage\Model\File\Storage\Flag
  15. */
  16. protected $_syncFlag;
  17. /**
  18. * Message identity
  19. *
  20. * @var string
  21. */
  22. protected $_identity;
  23. /**
  24. * Is displayed flag
  25. *
  26. * @var bool
  27. */
  28. protected $_isDisplayed = null;
  29. /**
  30. * @param \Magento\MediaStorage\Model\File\Storage\Flag $fileStorage
  31. */
  32. public function __construct(\Magento\MediaStorage\Model\File\Storage\Flag $fileStorage)
  33. {
  34. $this->_syncFlag = $fileStorage->loadSelf();
  35. }
  36. /**
  37. * Check if message should be displayed
  38. *
  39. * @return bool
  40. */
  41. abstract protected function _shouldBeDisplayed();
  42. /**
  43. * Retrieve unique message identity
  44. *
  45. * @return string
  46. */
  47. public function getIdentity()
  48. {
  49. return $this->_identity;
  50. }
  51. /**
  52. * Check whether
  53. *
  54. * @return bool
  55. */
  56. public function isDisplayed()
  57. {
  58. if (null === $this->_isDisplayed) {
  59. $output = $this->_shouldBeDisplayed();
  60. if ($output) {
  61. $this->_syncFlag->setState(\Magento\MediaStorage\Model\File\Storage\Flag::STATE_NOTIFIED);
  62. $this->_syncFlag->save();
  63. }
  64. $this->_isDisplayed = $output;
  65. }
  66. return $this->_isDisplayed;
  67. }
  68. /**
  69. * Retrieve message severity
  70. *
  71. * @return int
  72. */
  73. public function getSeverity()
  74. {
  75. return \Magento\Framework\Notification\MessageInterface::SEVERITY_MAJOR;
  76. }
  77. }