2 namespace callnotifier;
9 * Array of logger object arrays.
10 * Key is the notification type, value is an array of logger objects
11 * that want to get notified about the type.
15 protected $logger = array(
17 'incomingCall' => array()
21 public function __construct($config)
23 $this->config = $config;
30 * @param Logger $logger Logger object to register
31 * @param array|string $types Single notification type or array of such
32 * types. "*" means "register for all types".
36 public function addLogger(Logger $logger, $types)
39 $types = array_keys($this->logger);
41 $types = (array)$types;
43 foreach ($types as $type) {
44 if (!isset($this->logger[$type])) {
45 throw new \Exception('Unknown log type: ' . $type);
47 $this->logger[$type][] = $logger;
51 public function handle($msg)
53 if ($this->config->dumpFile !== null) {
56 if (substr($msg, 0, 9) != '[DKANPROT') {
57 //unknown message type
60 $regex = '#^\\[DKANPROT-([^ ]+) ([0-9]+)\\] (.*)$#';
61 if (!preg_match($regex, $msg, $matches)) {
62 //message should always be that way
65 list(, $type, $someid, $details) = $matches;
75 if ($type != 'Info') {
76 //we only want info messages
79 //Vegw/Ets-Cref:[0xffef]/[0x64] - VEGW_SETUP from upper layer to internal destination: CGPN[**22]->CDPN[41],
80 $regex = '#CGPN\\[([^\\]]+)\\]->CDPN\\[([^\\]]+)\\]#';
81 if (preg_match($regex, $details, $matches)) {
82 list(, $from, $to) = $matches;
83 $this->log('incomingCall', array('from' => $from, 'to' => $to));
87 protected function log($type, $arData)
89 if (!isset($this->logger[$type])) {
90 throw new \Exception('Unknown log type: ' . $type);
93 if (count($this->logger[$type])) {
94 foreach ($this->logger[$type] as $logger) {
95 $logger->log($type, $arData);
100 protected function prepareDump()
102 if ($this->config->dumpFile === null) {
105 $this->dumpHdl = fopen($this->config->dumpFile, 'w');
106 if (!$this->dumpHdl) {
107 throw new Exception('Cannot open replay file for reading');
111 protected function dump($msg)
113 fwrite($this->dumpHdl, $msg . "\n");