1
|
|
|
<?php |
2
|
|
|
namespace PhpAmqpLib\Helper; |
3
|
|
|
|
4
|
|
|
class DebugHelper |
5
|
|
|
{ |
6
|
|
|
protected $debug; |
7
|
|
|
|
8
|
|
|
protected $PROTOCOL_CONSTANTS_CLASS; |
9
|
|
|
|
10
|
60 |
|
public function __construct($PROTOCOL_CONSTANTS_CLASS) { |
11
|
60 |
|
$this->debug = defined('AMQP_DEBUG') ? AMQP_DEBUG : false; |
12
|
60 |
|
$this->PROTOCOL_CONSTANTS_CLASS = $PROTOCOL_CONSTANTS_CLASS; |
13
|
60 |
|
} |
14
|
|
|
|
15
|
60 |
|
public function debug_msg($msg) { |
16
|
60 |
|
if ($this->debug) { |
17
|
|
|
$this->print_msg($msg); |
18
|
|
|
} |
19
|
60 |
|
} |
20
|
|
|
|
21
|
60 |
|
public function debug_allowed_methods($allowed_methods) { |
22
|
60 |
|
if ($allowed_methods) { |
23
|
60 |
|
$msg = 'waiting for ' . implode(', ', $allowed_methods); |
24
|
48 |
|
} else { |
25
|
25 |
|
$msg = 'waiting for any method'; |
26
|
|
|
} |
27
|
60 |
|
$this->debug_msg($msg); |
28
|
60 |
|
} |
29
|
|
|
|
30
|
60 |
|
public function debug_method_signature1($method_sig) { |
31
|
60 |
|
$this->debug_method_signature('< %s:', $method_sig); |
32
|
60 |
|
} |
33
|
|
|
|
34
|
60 |
|
public function debug_method_signature($msg, $method_sig) { |
35
|
60 |
|
if ($this->debug) { |
36
|
|
|
$PROTOCOL_CONSTANTS_CLASS = $this->PROTOCOL_CONSTANTS_CLASS; |
37
|
|
|
$this->debug_msg(sprintf( |
38
|
|
|
$msg . ': %s', |
39
|
|
|
MiscHelper::methodSig($method_sig), |
40
|
|
|
$PROTOCOL_CONSTANTS_CLASS::$GLOBAL_METHOD_NAMES[MiscHelper::methodSig($method_sig)] |
41
|
|
|
)); |
42
|
|
|
} |
43
|
60 |
|
} |
44
|
|
|
|
45
|
60 |
|
public function debug_hexdump($data) { |
46
|
60 |
|
if ($this->debug) { |
47
|
|
|
$this->debug_msg(sprintf( |
48
|
|
|
'< [hex]: %s%s', |
49
|
|
|
PHP_EOL, |
50
|
|
|
MiscHelper::hexdump($data, $htmloutput = false, $uppercase = true, $return = true) |
51
|
|
|
)); |
52
|
|
|
} |
53
|
60 |
|
} |
54
|
|
|
|
55
|
60 |
|
public function debug_connection_start($version_major, $version_minor, $server_properties, $mechanisms, $locales) { |
56
|
60 |
|
if ($this->debug) { |
57
|
|
|
$this->debug_msg(sprintf( |
58
|
|
|
'Start from server, version: %d.%d, properties: %s, mechanisms: %s, locales: %s', |
59
|
|
|
$version_major, |
60
|
|
|
$version_minor, |
61
|
|
|
MiscHelper::dump_table($server_properties), |
62
|
|
|
implode(', ', $mechanisms), |
63
|
|
|
implode(', ', $locales) |
64
|
|
|
)); |
65
|
|
|
} |
66
|
60 |
|
} |
67
|
|
|
|
68
|
|
|
protected function print_msg($s) { |
69
|
|
|
echo $s . PHP_EOL; |
70
|
|
|
} |
71
|
|
|
} |