Base for a static organization website

CakeEvent.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @package Cake.Observer
  13. * @since CakePHP(tm) v 2.1
  14. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  15. */
  16. /**
  17. * Represents the transport class of events across the system. It receives a name, subject and an optional
  18. * payload. The name can be any string that uniquely identifies the event across the application, while the subject
  19. * represents the object that the event applies to.
  20. *
  21. * @package Cake.Event
  22. */
  23. class CakeEvent {
  24. /**
  25. * Name of the event
  26. *
  27. * @var string
  28. */
  29. protected $_name = null;
  30. /**
  31. * The object this event applies to (usually the same object that generates the event)
  32. *
  33. * @var object
  34. */
  35. protected $_subject;
  36. /**
  37. * Custom data for the method that receives the event
  38. *
  39. * @var mixed
  40. */
  41. public $data = null;
  42. /**
  43. * Property used to retain the result value of the event listeners
  44. *
  45. * @var mixed
  46. */
  47. public $result = null;
  48. /**
  49. * Flags an event as stopped or not, default is false
  50. *
  51. * @var bool
  52. */
  53. protected $_stopped = false;
  54. /**
  55. * Constructor
  56. *
  57. * @param string $name Name of the event
  58. * @param object $subject the object that this event applies to (usually the object that is generating the event)
  59. * @param mixed $data any value you wish to be transported with this event to it can be read by listeners
  60. *
  61. * ## Examples of usage:
  62. *
  63. * ```
  64. * $event = new CakeEvent('Order.afterBuy', $this, array('buyer' => $userData));
  65. * $event = new CakeEvent('User.afterRegister', $UserModel);
  66. * ```
  67. */
  68. public function __construct($name, $subject = null, $data = null) {
  69. $this->_name = $name;
  70. $this->data = $data;
  71. $this->_subject = $subject;
  72. }
  73. /**
  74. * Dynamically returns the name and subject if accessed directly
  75. *
  76. * @param string $attribute Attribute name.
  77. * @return mixed
  78. */
  79. public function __get($attribute) {
  80. if ($attribute === 'name' || $attribute === 'subject') {
  81. return $this->{$attribute}();
  82. }
  83. }
  84. /**
  85. * Returns the name of this event. This is usually used as the event identifier
  86. *
  87. * @return string
  88. */
  89. public function name() {
  90. return $this->_name;
  91. }
  92. /**
  93. * Returns the subject of this event
  94. *
  95. * @return string
  96. */
  97. public function subject() {
  98. return $this->_subject;
  99. }
  100. /**
  101. * Stops the event from being used anymore
  102. *
  103. * @return void
  104. */
  105. public function stopPropagation() {
  106. return $this->_stopped = true;
  107. }
  108. /**
  109. * Check if the event is stopped
  110. *
  111. * @return bool True if the event is stopped
  112. */
  113. public function isStopped() {
  114. return $this->_stopped;
  115. }
  116. }