Guest User

Untitled

a guest
Jul 17th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. <?php // $Id$
  2.  
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. # ***** BEGIN LICENSE BLOCK *****
  6. # This file is part of EventManager.
  7. # Copyright (c) 2005-2007 Frederic Minne <zefredz@gmail.com>.
  8. # All rights reserved.
  9. #
  10. # EventManager is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # EventManager is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with DotClear; if not, write to the Free Software
  22. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. #
  24. # ***** END LICENSE BLOCK *****
  25.  
  26. require_once dirname(__FILE__) . "/event/inc.event.php";
  27.  
  28. // ---------------------- Test Class --------------------
  29.  
  30. /**
  31. * Sample event driven object
  32. */
  33. class MyEventDrivenObject extends EventDriven
  34. {
  35. /**
  36. * sample event callback
  37. */
  38. function onHelloEventCallMe( )
  39. {
  40. echo "Hello World\n";
  41. }
  42.  
  43. /**
  44. * sample event callback
  45. */
  46. function onHelloEventCallMe2( )
  47. {
  48. echo "Hello World 2\n";
  49. }
  50.  
  51. /**
  52. * sample event callback
  53. */
  54. function onAnotherEventCallMe( )
  55. {
  56. echo "another event occurs\n";
  57. }
  58.  
  59. /**
  60. * main() method
  61. * @static
  62. */
  63. function main( )
  64. {
  65. echo "> creating objects...\n";
  66. $registry = EventManager::getInstance();
  67. $edo = new MyEventDrivenObject();
  68. $em = new EventGenerator();
  69. echo "> done\n\n";
  70.  
  71. echo "> registrering listeners\n";
  72. $id1 = $edo->addListener( "hello", 'onHelloEventCallMe' );
  73. $id2 = $edo->addListener( "another", 'onAnotherEventCallMe' );
  74. echo "> done\n\n";
  75.  
  76. echo "> sending events\n";
  77. $em->sendEvent( new Event("hello") );
  78. $em->sendEvent( new Event("another") );
  79. echo "> done\n\n";
  80.  
  81. echo "> lists\n";
  82. echo "* registry:\n";
  83. $registry->listRegisteredListeners( );
  84.  
  85. echo "> registrering another hello listener\n";
  86. $id3 = $edo->addListener( "hello", 'onHelloEventCallMe2' );
  87. echo "> done\n\n";
  88.  
  89. echo "> lists\n";
  90. echo "* registry:\n";
  91. $registry->listRegisteredListeners( );
  92.  
  93. echo "> sending events\n";
  94. $em->sendEvent( new Event("hello") );
  95. $em->sendEvent( new Event("another") );
  96. echo "> done\n\n";
  97.  
  98. echo "> sending events staticaly\n";
  99. EventManager::notify( new Event("hello") );
  100. EventManager::notify( new Event("another") );
  101. echo "> done\n\n";
  102.  
  103. echo "> unregistrering another and second hello listener\n";
  104. $edo->removeListener( "another", $id2 );
  105. $edo->removeListener( "hello", $id3 );
  106. echo "> done\n\n";
  107.  
  108. echo "> lists\n";
  109. echo "* registry:\n";
  110. $registry->listRegisteredListeners( );
  111.  
  112. echo "> sending events\n";
  113. $em->sendEvent( new Event("hello") );
  114. $em->sendEvent( new Event("another") );
  115. echo "> done\n";
  116. }
  117. }
  118.  
  119. // -------------------- Run Test ---------------------
  120.  
  121. if ( ! defined( "DEBUG_MODE" ) ) define ( "DEBUG_MODE", true );
  122. echo "<pre>";
  123. MyEventDrivenObject::main();
  124. echo "</pre>";
  125. ?>
Add Comment
Please, Sign In to add comment