new event handler
This commit is contained in:
parent
51fef13893
commit
cc4009670a
|
|
@ -0,0 +1,36 @@
|
||||||
|
include_once('virtual.php');
|
||||||
|
|
||||||
|
class Syslog extends Event_Handler{
|
||||||
|
|
||||||
|
protected $ident;
|
||||||
|
protected $option;
|
||||||
|
protected $facility;
|
||||||
|
protected $priority;
|
||||||
|
function __construct($ident='fusionpbx', $option=(LOG_PID | LOG_PERROR), $facility=LOG_LOCAL0, $priority=LOG_INFO){
|
||||||
|
$this->ident = $ident;
|
||||||
|
$this->option = $option;
|
||||||
|
$this->facility = $facility;
|
||||||
|
$this->priority = $priority;
|
||||||
|
|
||||||
|
if ($_SESSION['event']['syslog']['enable'] <> 0){
|
||||||
|
openlog($ident, $option, $facility);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function __destruct(){
|
||||||
|
if ($_SESSION['event']['syslog']['enable'] <> 0){
|
||||||
|
closelog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function log_event($event_type, $params){
|
||||||
|
if ($_SESSION['event']['syslog']['enable'] <> 0){
|
||||||
|
$log = '' ;
|
||||||
|
foreach ($params as $k => $v) {
|
||||||
|
$log .= "[$k]=[$v] ";
|
||||||
|
}
|
||||||
|
|
||||||
|
syslog($priority, $log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
abstract class Event_Handler{
|
||||||
|
// Force Extending class to define this method
|
||||||
|
abstract public function log_event($event_type, $params);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Events class:
|
||||||
|
* - manages events in the FusionPBX
|
||||||
|
* use:
|
||||||
|
* $e = new Events;
|
||||||
|
* $e->add_event_function('myfunction') it could be a static method as well
|
||||||
|
* $e->execute_event(ADD, $params) event type, params is an associative array
|
||||||
|
*/
|
||||||
|
include "root.php";
|
||||||
|
|
||||||
|
define ("MODULE_LOAD", 1); // when loading a FS module with FS
|
||||||
|
define ("MODULE_UNLOAD", 2);
|
||||||
|
define ("RELOADXML", 3); // when reloading xml
|
||||||
|
define ("ADD", 4); // when adding something
|
||||||
|
define ("EDIT", 5); // when editing something
|
||||||
|
define ("DEL", 6); // when deleting something
|
||||||
|
define ("LOGIN", 7); // when login
|
||||||
|
define ("LOGOUT", 8); // when logout
|
||||||
|
|
||||||
|
if (!class_exists('database')) {
|
||||||
|
class Events{
|
||||||
|
private $handler = array();
|
||||||
|
private $event = array();
|
||||||
|
|
||||||
|
public function __construct(){
|
||||||
|
}
|
||||||
|
// declare log file and file pointer as private properties
|
||||||
|
|
||||||
|
public function add_event_function($event_type, $event_function){
|
||||||
|
$event[$event_type][] = $event_function;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute_event($event_type, $params=null){
|
||||||
|
foreach ($this->event[$event_type] as $event_function){
|
||||||
|
call_user_func($event_function, $params);
|
||||||
|
|
||||||
|
// Lets log
|
||||||
|
foreach ($this->handler as $handler){
|
||||||
|
$handler->log_event($event_type, $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue