2 namespace callnotifier;
4 class Logger_Debug implements Logger
6 public $edss1MsgOnly = false;
8 public function __construct()
10 $cc = new \Console_Color2();
11 $this->begin = $cc->convert('%y');
12 $this->end = $cc->convert('%n');
13 $this->blue = $cc->convert('%b');
14 $this->red = $cc->convert('%r');
15 $this->white = $cc->convert('%w');
16 $this->purple = $cc->convert('%p');
19 public function log($type, $arData)
21 if ($type == 'msgData') {
22 $this->echoMsgData($arData);
23 } else if ($type == 'edss1msg') {
24 $this->echoEDSS1($arData['msg']);
27 echo $this->blue . $type . $this->end . ': '
28 . var_export($arData, true) . "\n";
33 protected function echoMsgData($arData)
35 if ($this->edss1MsgOnly
36 && substr($arData['details'], 16, 4) != ' 08 '
38 //only E-DSS-1, no other packets
42 echo $this->begin . $arData['type'] . $this->end
43 . ': ' . $arData['details'] . "\n";
45 //Show bytes of N01|N02|T01|T02 etc
46 if (preg_match('#^[A-Z][0-9]{2}: (.+)$#', $arData['details'], $matches)) {
47 $bytestring = $matches[1];
49 foreach (explode(' ', $bytestring) as $strbyte) {
50 $line .= chr(hexdec($strbyte));
54 $this->white . '?' . $this->end,
57 echo $this->red . ' bytes' . $this->end . ': ' . $line . "\n";
61 protected function echoEDSS1($msg)
64 $this->purple . 'EDSS1_Message' . $this->end
66 . $this->blue . '%s' . $this->end
67 . ' SAPI %d, CR %d, TEI %d, call %d-%s'
75 $msg->callRefType == 0 ? 'source' : 'target',
76 count($msg->parameters)
79 foreach ($msg->parameters as $param) {
81 " Parameter type 0x%02X%s, %d bytes: %s\n",
84 ? ' ' . $this->purple . $param->title . $this->end
85 : ' ' . $this->purple . $param->getTypeName() . $this->end,
87 preg_replace('/[^[:print:]]/', '?', $param->data)
88 . (isset($param->number)
89 ? ' ' . $this->red . $param->number . $this->end
93 if ($param instanceof EDSS1_Parameter_INumber) {
95 " Number type: %s, plan: %s\n",
96 EDSS1_Parameter_Names::$numberTypes[$param->numberType],
97 EDSS1_Parameter_Names::$numberingPlans[$param->numberingPlan]