| 1: | <?php |
| 2: | |
| 3: | namespace Zippy; |
| 4: | |
| 5: | use Zippy\Interfaces\EventReceiver; |
| 6: | use Zippy\Html\HtmlComponent; |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | class Event |
| 12: | { |
| 13: | private $handler; |
| 14: | private $receiver = null; |
| 15: | public $isajax = false; |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | public function __construct(EventReceiver $receiver, $handler) { |
| 24: | $this->receiver = $receiver; |
| 25: | |
| 26: | |
| 27: | $this->handler = $handler; |
| 28: | |
| 29: | } |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | public function onEvent($sender, $params = null) { |
| 37: | $h = $this->handler; |
| 38: | |
| 39: | if ($h != null && $this->receiver != null) { |
| 40: | return $this->receiver->{$h}($sender, $params); |
| 41: | } else { |
| 42: | throw new \Zippy\Exception(sprintf(ERROR_HANDLER_NOTFOUND, $sender->id)) ; |
| 43: | } |
| 44: | } |
| 45: | |
| 46: | } |
| 47: | |