call echo logger
[auerswald-callnotifier.git] / src / callnotifier / Log.php
1 <?php
2 namespace callnotifier;
3
4 class Log
5 {
6     /**
7      * Array of logger object arrays.
8      * Key is the notification type, value is an array of logger objects
9      * that want to get notified about the type.
10      *
11      * @var array
12      */
13     protected $logger = array(
14         'msgData' => array(),
15         'edss1msg' => array(),
16         'incomingCall' => array(),
17         'finishedCall' => array(),
18     );
19
20     /**
21      * Add a logger
22      *
23      * @param Logger       $logger Logger object to register
24      * @param array|string $types  Single notification type or array of such
25      *                             types. "*" means "register for all types".
26      *
27      * @return self
28      */
29     public function addLogger(Logger $logger, $types)
30     {
31         if ($types == '*') {
32             $types = array_keys($this->logger);
33         }
34         $types = (array)$types;
35
36         foreach ($types as $type) {
37             if (!isset($this->logger[$type])) {
38                 throw new \Exception('Unknown log type: ' . $type);
39             }
40             $this->logger[$type][] = $logger;
41         }
42     }
43
44     public function log($type, $arData)
45     {
46         if (!isset($this->logger[$type])) {
47             throw new \Exception('Unknown log type: ' . $type);
48         }
49         
50         if (count($this->logger[$type])) {
51             foreach ($this->logger[$type] as $logger) {
52                 $logger->log($type, $arData);
53             }
54         }
55     }
56
57 }
58
59 ?>