1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the class {@see \Mailcode\Parser\PreParser\Debugger}. |
4
|
|
|
* |
5
|
|
|
* @package Mailcode |
6
|
|
|
* @subpackage Parser |
7
|
|
|
* @see \Mailcode\Parser\PreParser\Debugger |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Mailcode\Parser\PreParser; |
13
|
|
|
|
14
|
|
|
use Mailcode\Mailcode; |
15
|
|
|
use Mailcode\Parser\PreParser\CommandDef; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Specialized debugger for the pre-parser, used to |
19
|
|
|
* prepare relevant information for debug logging. |
20
|
|
|
* |
21
|
|
|
* @package Mailcode |
22
|
|
|
* @subpackage Parser |
23
|
|
|
* @author Sebastian Mordziol <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class Debugger |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @param array<int,array<int,string>> $matches |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
public function debugOpeningCommands(array $matches) : void |
32
|
|
|
{ |
33
|
|
|
if(!Mailcode::isDebugEnabled()) |
34
|
|
|
{ |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
Mailcode::debug('Opening command matches:'); |
39
|
|
|
|
40
|
|
|
if(empty($matches)) |
41
|
|
|
{ |
42
|
|
|
Mailcode::debug('...None found.'); |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
foreach($matches[0] as $idx => $matchedText) |
47
|
|
|
{ |
48
|
|
|
$number = $idx+1; |
49
|
|
|
|
50
|
|
|
Mailcode::debug(sprintf('...#%02d matched: [%s]', $number, $matchedText)); |
51
|
|
|
Mailcode::debug(sprintf('...#%02d name...: [%s]', $number, $matches[1][$idx])); |
52
|
|
|
Mailcode::debug(sprintf('...#%02d params.: [%s]', $number, $matches[2][$idx])); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param array<int,array{name:string,matchedText:string}> $commands |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function debugClosingCommands(array $commands) : void |
61
|
|
|
{ |
62
|
|
|
if(!Mailcode::isDebugEnabled()) |
63
|
|
|
{ |
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
Mailcode::debug('Closing command matches:', $commands); |
68
|
|
|
|
69
|
|
|
if(empty($commands)) |
70
|
|
|
{ |
71
|
|
|
Mailcode::debug('...None found.'); |
72
|
|
|
return; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
foreach($commands as $idx => $command) |
76
|
|
|
{ |
77
|
|
|
$number = $idx+1; |
78
|
|
|
|
79
|
|
|
Mailcode::debug(sprintf('...#%02d matched: [%s]', $number, $command['matchedText'])); |
80
|
|
|
Mailcode::debug(sprintf('...#%02d name...: [%s]', $number, $command['name'])); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function debugCommandDef(CommandDef $commandDef) : void |
85
|
|
|
{ |
86
|
|
|
if(!Mailcode::isDebugEnabled()) |
87
|
|
|
{ |
88
|
|
|
return; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
Mailcode::debug('Command definition:', $commandDef->toArray()); |
92
|
|
|
|
93
|
|
|
if(defined('TESTS_ROOT')) |
94
|
|
|
{ |
95
|
|
|
print_r($commandDef->toArray()); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|