1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace UCD\Infrastructure\Repository\CharacterRepository; |
4
|
|
|
|
5
|
|
|
use Psr\Log\LoggerInterface; |
6
|
|
|
|
7
|
|
|
use UCD\Unicode\Character\Properties\General\Block; |
8
|
|
|
use UCD\Unicode\Character\Properties\General\GeneralCategory; |
9
|
|
|
use UCD\Unicode\Character\Properties\General\Script; |
10
|
|
|
use UCD\Unicode\Codepoint; |
11
|
|
|
use UCD\Unicode\Character\Repository; |
12
|
|
|
|
13
|
|
|
class DebugRepository implements Repository |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var Repository |
17
|
|
|
*/ |
18
|
|
|
protected $delegate; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var LoggerInterface |
22
|
|
|
*/ |
23
|
|
|
private $logger; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Repository $delegate |
27
|
|
|
* @param LoggerInterface $logger |
28
|
|
|
*/ |
29
|
|
|
public function __construct(Repository $delegate, LoggerInterface $logger) |
30
|
|
|
{ |
31
|
|
|
$this->delegate = $delegate; |
32
|
|
|
$this->logger = $logger; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritDoc} |
37
|
|
|
*/ |
38
|
|
|
public function getByCodepoint(Codepoint $codepoint) |
39
|
|
|
{ |
40
|
|
|
$this->logMethodCall(__FUNCTION__, [$codepoint]); |
41
|
|
|
|
42
|
|
|
return $this->delegate->getByCodepoint($codepoint); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritDoc} |
47
|
|
|
*/ |
48
|
|
|
public function getByCodepoints(Codepoint\Collection $codepoints) |
49
|
|
|
{ |
50
|
|
|
$this->logMethodCall(__FUNCTION__, [$codepoints]); |
51
|
|
|
|
52
|
|
|
return $this->delegate->getByCodepoints($codepoints); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritDoc} |
57
|
|
|
*/ |
58
|
|
|
public function getAll() |
59
|
|
|
{ |
60
|
|
|
$this->logMethodCall(__FUNCTION__); |
61
|
|
|
|
62
|
|
|
return $this->delegate->getAll(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritDoc} |
67
|
|
|
*/ |
68
|
|
|
public function getCodepointsByBlock(Block $block) |
69
|
|
|
{ |
70
|
|
|
$this->logMethodCall(__FUNCTION__); |
71
|
|
|
|
72
|
|
|
return $this->delegate->getCodepointsByBlock($block); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritDoc} |
77
|
|
|
*/ |
78
|
|
|
public function getCodepointsByCategory(GeneralCategory $category) |
79
|
|
|
{ |
80
|
|
|
$this->logMethodCall(__FUNCTION__); |
81
|
|
|
|
82
|
|
|
return $this->delegate->getCodepointsByCategory($category); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritDoc} |
87
|
|
|
*/ |
88
|
|
|
public function getCodepointsByScript(Script $script) |
89
|
|
|
{ |
90
|
|
|
$this->logMethodCall(__FUNCTION__); |
91
|
|
|
|
92
|
|
|
return $this->delegate->getCodepointsByScript($script); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritDoc} |
97
|
|
|
*/ |
98
|
|
|
public function count() |
99
|
|
|
{ |
100
|
|
|
$this->logMethodCall(__FUNCTION__); |
101
|
|
|
|
102
|
|
|
return $this->delegate->count(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string $method |
107
|
|
|
* @param array $details |
108
|
|
|
*/ |
109
|
|
|
protected function logMethodCall($method, array $details = []) |
110
|
|
|
{ |
111
|
|
|
$message = $this->composeMessageFromMethodDetails($method, $details); |
112
|
|
|
$this->log($message); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $method |
117
|
|
|
* @param array $details |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
protected function composeMessageFromMethodDetails($method, array $details = []) |
121
|
|
|
{ |
122
|
|
|
return sprintf('Repository::%s/%s', $method, json_encode($details)); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param string $message |
127
|
|
|
*/ |
128
|
|
|
protected function log($message) |
129
|
|
|
{ |
130
|
|
|
$this->logger->info($message); |
131
|
|
|
} |
132
|
|
|
} |