/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record/Listener/Chain.php

https://github.com/proyectoalba/alba · PHP · 223 lines · 177 code · 3 blank · 43 comment · 1 complexity · 9e5a8d9f670d47468884f05aaeda8cdd MD5 · raw file

  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information, see
  19. * <http://www.phpdoctrine.org>.
  20. */
  21. /**
  22. * Doctrine_Record_Listener_Chain
  23. * this class represents a chain of different listeners,
  24. * useful for having multiple listeners listening the events at the same time
  25. *
  26. * @package Doctrine
  27. * @subpackage Record
  28. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
  29. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  30. * @link www.phpdoctrine.org
  31. * @since 1.0
  32. * @version $Revision$
  33. */
  34. class Doctrine_Record_Listener_Chain extends Doctrine_Access implements Doctrine_Record_Listener_Interface
  35. {
  36. /**
  37. * @var array $listeners an array containing all listeners
  38. */
  39. protected $_listeners = array();
  40. /**
  41. * add
  42. * adds a listener to the chain of listeners
  43. *
  44. * @param object $listener
  45. * @param string $name
  46. * @return void
  47. */
  48. public function add($listener, $name = null)
  49. {
  50. if ( ! ($listener instanceof Doctrine_Record_Listener_Interface) &&
  51. ! ($listener instanceof Doctrine_Overloadable)) {
  52. throw new Doctrine_EventListener_Exception("Couldn't add eventlistener. Record listeners should implement either Doctrine_Record_Listener_Interface or Doctrine_Overloadable");
  53. }
  54. if ($name === null) {
  55. $this->_listeners[] = $listener;
  56. } else {
  57. $this->_listeners[$name] = $listener;
  58. }
  59. }
  60. /**
  61. * returns a Doctrine_Record_Listener on success
  62. * and null on failure
  63. *
  64. * @param mixed $key
  65. * @return mixed
  66. */
  67. public function get($key)
  68. {
  69. if ( ! isset($this->_listeners[$key])) {
  70. return null;
  71. }
  72. return $this->_listeners[$key];
  73. }
  74. /**
  75. * set
  76. *
  77. * @param mixed $key
  78. * @param Doctrine_Record_Listener $listener listener to be added
  79. * @return Doctrine_Record_Listener_Chain this object
  80. */
  81. public function set($key, $listener)
  82. {
  83. $this->_listeners[$key] = $listener;
  84. }
  85. public function preSerialize(Doctrine_Event $event)
  86. {
  87. foreach ($this->_listeners as $listener) {
  88. $listener->preSerialize($event);
  89. }
  90. }
  91. public function postSerialize(Doctrine_Event $event)
  92. {
  93. foreach ($this->_listeners as $listener) {
  94. $listener->postSerialize($event);
  95. }
  96. }
  97. public function preUnserialize(Doctrine_Event $event)
  98. {
  99. foreach ($this->_listeners as $listener) {
  100. $listener->preUnserialize($event);
  101. }
  102. }
  103. public function postUnserialize(Doctrine_Event $event)
  104. {
  105. foreach ($this->_listeners as $listener) {
  106. $listener->postUnserialize($event);
  107. }
  108. }
  109. public function preDqlSelect(Doctrine_Event $event)
  110. {
  111. foreach ($this->_listeners as $listener) {
  112. $listener->preDqlSelect($event);
  113. }
  114. }
  115. public function preSave(Doctrine_Event $event)
  116. {
  117. foreach ($this->_listeners as $listener) {
  118. $listener->preSave($event);
  119. }
  120. }
  121. public function postSave(Doctrine_Event $event)
  122. {
  123. foreach ($this->_listeners as $listener) {
  124. $listener->postSave($event);
  125. }
  126. }
  127. public function preDqlDelete(Doctrine_Event $event)
  128. {
  129. foreach ($this->_listeners as $listener) {
  130. $listener->preDqlDelete($event);
  131. }
  132. }
  133. public function preDelete(Doctrine_Event $event)
  134. {
  135. foreach ($this->_listeners as $listener) {
  136. $listener->preDelete($event);
  137. }
  138. }
  139. public function postDelete(Doctrine_Event $event)
  140. {
  141. foreach ($this->_listeners as $listener) {
  142. $listener->postDelete($event);
  143. }
  144. }
  145. public function preDqlUpdate(Doctrine_Event $event)
  146. {
  147. foreach ($this->_listeners as $listener) {
  148. $listener->preDqlUpdate($event);
  149. }
  150. }
  151. public function preUpdate(Doctrine_Event $event)
  152. {
  153. foreach ($this->_listeners as $listener) {
  154. $listener->preUpdate($event);
  155. }
  156. }
  157. public function postUpdate(Doctrine_Event $event)
  158. {
  159. foreach ($this->_listeners as $listener) {
  160. $listener->postUpdate($event);
  161. }
  162. }
  163. public function preInsert(Doctrine_Event $event)
  164. {
  165. foreach ($this->_listeners as $listener) {
  166. $listener->preInsert($event);
  167. }
  168. }
  169. public function postInsert(Doctrine_Event $event)
  170. {
  171. foreach ($this->_listeners as $listener) {
  172. $listener->postInsert($event);
  173. }
  174. }
  175. public function preHydrate(Doctrine_Event $event)
  176. {
  177. foreach ($this->_listeners as $listener) {
  178. $listener->preHydrate($event);
  179. }
  180. }
  181. public function postHydrate(Doctrine_Event $event)
  182. {
  183. foreach ($this->_listeners as $listener) {
  184. $listener->postHydrate($event);
  185. }
  186. }
  187. public function preValidate(Doctrine_Event $event)
  188. {
  189. foreach ($this->_listeners as $listener) {
  190. $listener->preValidate($event);
  191. }
  192. }
  193. public function postValidate(Doctrine_Event $event)
  194. {
  195. foreach ($this->_listeners as $listener) {
  196. $listener->postValidate($event);
  197. }
  198. }
  199. }