sfEvent.class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfEvent.
  11. *
  12. * @package symfony
  13. * @subpackage util
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfEvent.class.php 8698 2008-04-30 16:35:28Z fabien $
  16. */
  17. class sfEvent implements ArrayAccess
  18. {
  19. protected
  20. $value = null,
  21. $processed = false,
  22. $subject = null,
  23. $name = '',
  24. $parameters = null;
  25. /**
  26. * Constructs a new sfEvent.
  27. *
  28. * @param mixed $subject The subject
  29. * @param string $name The event name
  30. * @param array $parameters An array of parameters
  31. */
  32. public function __construct($subject, $name, $parameters = array())
  33. {
  34. $this->subject = $subject;
  35. $this->name = $name;
  36. $this->parameters = $parameters;
  37. }
  38. /**
  39. * Returns the subject.
  40. *
  41. * @return mixed The subject
  42. */
  43. public function getSubject()
  44. {
  45. return $this->subject;
  46. }
  47. /**
  48. * Returns the event name.
  49. *
  50. * @return string The event name
  51. */
  52. public function getName()
  53. {
  54. return $this->name;
  55. }
  56. /**
  57. * Sets the return value for this event.
  58. *
  59. * @param mixed $value The return value
  60. */
  61. public function setReturnValue($value)
  62. {
  63. $this->value = $value;
  64. }
  65. /**
  66. * Returns the return value.
  67. *
  68. * @return mixed The return value
  69. */
  70. public function getReturnValue()
  71. {
  72. return $this->value;
  73. }
  74. /**
  75. * Sets the processed flag.
  76. *
  77. * @param Boolean $processed The processed flag value
  78. */
  79. public function setProcessed($processed)
  80. {
  81. $this->processed = (boolean) $processed;
  82. }
  83. /**
  84. * Returns whether the event has been processed by a listener or not.
  85. *
  86. * @return Boolean true if the event has been processed, false otherwise
  87. */
  88. public function isProcessed()
  89. {
  90. return $this->processed;
  91. }
  92. /**
  93. * Returns the event parameters.
  94. *
  95. * @return array The event parameters
  96. */
  97. public function getParameters()
  98. {
  99. return $this->parameters;
  100. }
  101. /**
  102. * Returns true if the parameter exists (implements the ArrayAccess interface).
  103. *
  104. * @param string $name The parameter name
  105. *
  106. * @return Boolean true if the parameter exists, false otherwise
  107. */
  108. public function offsetExists($name)
  109. {
  110. return array_key_exists($name, $this->parameters);
  111. }
  112. /**
  113. * Returns a parameter value (implements the ArrayAccess interface).
  114. *
  115. * @param string $name The parameter name
  116. *
  117. * @return mixed The parameter value
  118. */
  119. public function offsetGet($name)
  120. {
  121. if (!array_key_exists($name, $this->parameters))
  122. {
  123. throw new InvalidArgumentException(sprintf('The event "%s" has no "%s" parameter.', $this->name, $name));
  124. }
  125. return $this->parameters[$name];
  126. }
  127. /**
  128. * Sets a parameter (implements the ArrayAccess interface).
  129. *
  130. * @param string $name The parameter name
  131. * @param mixed $value The parameter value
  132. */
  133. public function offsetSet($name, $value)
  134. {
  135. $this->parameters[$name] = $value;
  136. }
  137. /**
  138. * Removes a parameter (implements the ArrayAccess interface).
  139. *
  140. * @param string $name The parameter name
  141. */
  142. public function offsetUnset($name)
  143. {
  144. unset($this->parameters[$name]);
  145. }
  146. }