Advertisement
mikjaer

Untitled

Jan 16th, 2020
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Twing;
  4. class observer
  5. {
  6.     private $subscribers;
  7.  
  8.     public function dispatch($event)
  9.     {
  10.         foreach ($this->subscribers[$event] as $subscriber)
  11.             call_user_func(array( $subscriber["object"] ,$subscriber["method"]));
  12.     }
  13.  
  14.     public function subscribe($event, $object, $method)
  15.     {
  16.         foreach ($this->subscribers[$event] as $subscriber)
  17.             if (($subsciber["object"] == $object) or ($subscriber["method"] == $method))
  18.                 return true; // Allready subscribed
  19.  
  20.         $this->subscribers[$event][] = array(   "object" => $object,
  21.                                                 "method" => $method);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement