read TEI and call reference
[auerswald-callnotifier.git] / src / callnotifier / Logger / Echo.php
1 <?php
2 namespace callnotifier;
3
4 class Logger_Echo implements Logger
5 {
6     public function __construct()
7     {
8         $cc = new \Console_Color2();
9         $this->begin = $cc->convert('%y');
10         $this->end = $cc->convert('%n');
11         $this->blue = $cc->convert('%b');
12         $this->red = $cc->convert('%r');
13         $this->white = $cc->convert('%w');
14         $this->purple = $cc->convert('%p');
15     }
16
17     public function log($type, $arData)
18     {
19         if ($type == 'msgData') {
20             echo $this->begin . $arData['type'] . $this->end
21                 . ': ' . $arData['details'] . "\n";
22             if (preg_match('#^[A-Z][0-9]{2}: (.+)$#', $arData['details'], $matches)) {
23                 $bytestring = $matches[1];
24                 $line = '';
25                 foreach (explode(' ', $bytestring) as $strbyte) {
26                     $line .= chr(hexdec($strbyte));
27                 }
28                 $line = preg_replace(
29                     '/[^[:print:]]/',
30                     $this->white . '?' . $this->end,
31                     $line
32                 );
33                 echo $this->red . '     bytes' . $this->end . ': ' . $line . "\n";
34             }
35         } else if ($type == 'edss1msg') {
36             $msg = $arData['msg'];
37             echo sprintf(
38                 $this->purple . 'EDSS1_Message' . $this->end
39                 . ' type %02X '
40                 . $this->purple . '%s' . $this->end
41                 . ' TEI %d, call %d'
42                 . ', %d parameters',
43                 $msg->type,
44                 $msg->getTypeName(),
45                 $msg->tei,
46                 $msg->callRef,
47                 count($msg->parameters)
48             ) . "\n";
49             foreach ($msg->parameters as $param) {
50                 echo sprintf(
51                     " Parameter type %02X, %d bytes: %s\n",
52                     $param->type,
53                     $param->length,
54                     preg_replace('/[^[:print:]]/', '?', $param->data)
55                 );
56             }
57         } else {
58             echo $this->blue . $type . $this->end . ': '
59                 . var_export($arData, true) . "\n";
60         }
61     }
62
63 }
64
65 ?>