ResourceEvent.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /*
  3. * This file is part of the Sylius package.
  4. *
  5. * (c) Paweł Jędrzejewski
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sylius\Component\Resource\Event;
  11. use Symfony\Component\EventDispatcher\GenericEvent;
  12. /**
  13. * Resource event.
  14. *
  15. * @author Jérémy Leherpeur <jeremy@leherpeur.net>
  16. */
  17. class ResourceEvent extends GenericEvent
  18. {
  19. const TYPE_ERROR = 'error';
  20. const TYPE_WARNING = 'warning';
  21. const TYPE_INFO = 'info';
  22. const TYPE_SUCCESS = 'success';
  23. /**
  24. * Message type
  25. *
  26. * @var string
  27. */
  28. protected $messageType = '';
  29. /**
  30. * Message
  31. *
  32. * @var string
  33. */
  34. protected $message = '';
  35. /**
  36. * Message parameters
  37. *
  38. * @var array
  39. */
  40. protected $messageParameters = array();
  41. /**
  42. * Stop event propagation
  43. *
  44. * @param string $message
  45. * @param string $type
  46. * @param array $parameters
  47. */
  48. public function stop($message, $type = self::TYPE_ERROR, $parameters = array())
  49. {
  50. $this->messageType = $type;
  51. $this->message = $message;
  52. $this->messageParameters = $parameters;
  53. $this->stopPropagation();
  54. }
  55. /**
  56. * Alias
  57. *
  58. * @return bool
  59. */
  60. public function isStopped()
  61. {
  62. return $this->isPropagationStopped();
  63. }
  64. /**
  65. * Get messageType property
  66. *
  67. * @return string
  68. */
  69. public function getMessageType()
  70. {
  71. return $this->messageType;
  72. }
  73. /**
  74. * Sets messageType property
  75. *
  76. * @param string $messageType Should be one of ResourceEvent's TYPE constants
  77. *
  78. * @return $this
  79. */
  80. public function setMessageType($messageType)
  81. {
  82. $this->messageType = $messageType;
  83. return $this;
  84. }
  85. /**
  86. * Get message property
  87. *
  88. * @return string
  89. */
  90. public function getMessage()
  91. {
  92. return $this->message;
  93. }
  94. /**
  95. * Sets message property
  96. *
  97. * @param string $message
  98. *
  99. * @return $this
  100. */
  101. public function setMessage($message)
  102. {
  103. $this->message = $message;
  104. return $this;
  105. }
  106. /**
  107. * Get messageParameters property
  108. *
  109. * @return array
  110. */
  111. public function getMessageParameters()
  112. {
  113. return $this->messageParameters;
  114. }
  115. /**
  116. * Sets messageParameters property
  117. *
  118. * @param array $messageParameters
  119. *
  120. * @return $this
  121. */
  122. public function setMessageParameters(array $messageParameters)
  123. {
  124. $this->messageParameters = $messageParameters;
  125. return $this;
  126. }
  127. }