Files
luos/thirdparty/html2ps_pdf/dispatcher.class.php
Paula Quispe 9eb7d6cac2 HOR-2689
2017-08-03 17:00:30 -04:00

37 lines
713 B
PHP

<?php
class Dispatcher {
var $_callbacks;
function Dispatcher() {
$this->_callbacks = array();
}
/**
* @param String $type name of the event to dispatch
*/
function add_event($type) {
$this->_callbacks[$type] = array();
}
function add_observer($type, $callback) {
$this->_check_event_type($type);
$this->_callbacks[$type][] = $callback;
}
function fire($type, $params) {
$this->_check_event_type($type);
foreach ($this->_callbacks[$type] as $callback) {
call_user_func($callback, $params);
};
}
function _check_event_type($type) {
if (!isset($this->_callbacks[$type])) {
die(sprintf("Invalid event type: %s", $type));
};
}
}
?>