|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
/** |
|
4
|
|
|
* Contains MessageBuilderTrait Trait. |
|
5
|
|
|
* |
|
6
|
|
|
* PHP version 7.0+ |
|
7
|
|
|
* |
|
8
|
|
|
* LICENSE: |
|
9
|
|
|
* This file is part of Yet Another Php Eve Api Library also know as Yapeal |
|
10
|
|
|
* which can be used to access the Eve Online API data and place it into a |
|
11
|
|
|
* database. |
|
12
|
|
|
* Copyright (C) 2015-2017 Michael Cummings |
|
13
|
|
|
* |
|
14
|
|
|
* This program is free software: you can redistribute it and/or modify it |
|
15
|
|
|
* under the terms of the GNU Lesser General Public License as published by the |
|
16
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
|
17
|
|
|
* option) any later version. |
|
18
|
|
|
* |
|
19
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
20
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
|
22
|
|
|
* for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
25
|
|
|
* along with this program. If not, see |
|
26
|
|
|
* <http://spdx.org/licenses/LGPL-3.0.html>. |
|
27
|
|
|
* |
|
28
|
|
|
* You should be able to find a copy of this license in the COPYING-LESSER.md |
|
29
|
|
|
* file. A copy of the GNU GPL should also be available in the COPYING.md file. |
|
30
|
|
|
* |
|
31
|
|
|
* @copyright 2015-2017 Michael Cummings |
|
32
|
|
|
* @license LGPL-3.0+ |
|
33
|
|
|
* @author Michael Cummings <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
namespace Yapeal\Log; |
|
36
|
|
|
|
|
37
|
|
|
use Yapeal\Xml\EveApiReadWriteInterface; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Trait MessageBuilderTrait |
|
41
|
|
|
*/ |
|
42
|
|
|
trait MessageBuilderTrait |
|
43
|
|
|
{ |
|
44
|
|
|
/** |
|
45
|
|
|
* @param string $messagePrefix |
|
46
|
|
|
* @param EveApiReadWriteInterface $data |
|
47
|
|
|
* |
|
48
|
|
|
* @return string |
|
49
|
|
|
* @throws \LogicException |
|
50
|
|
|
*/ |
|
51
|
39 |
|
protected function createEveApiMessage(string $messagePrefix, EveApiReadWriteInterface $data): string |
|
52
|
|
|
{ |
|
53
|
39 |
|
$mess = $messagePrefix . ' Eve API %1$s/%2$s'; |
|
54
|
39 |
|
$subs = [lcfirst($data->getEveApiSectionName()), $data->getEveApiName()]; |
|
55
|
39 |
|
if ($data->hasEveApiArgument('keyID')) { |
|
56
|
|
|
$mess .= ' for keyID = %3$s'; |
|
57
|
|
|
$subs[] = $data->getEveApiArgument('keyID'); |
|
58
|
|
|
if ($data->hasEveApiArgument('characterID')) { |
|
59
|
|
|
$mess .= ' and characterID = %4$s'; |
|
60
|
|
|
$subs[] = $data->getEveApiArgument('characterID'); |
|
61
|
|
|
} elseif ($data->hasEveApiArgument('corporationID')) { |
|
62
|
|
|
$mess .= ' and corporationID = %4$s'; |
|
63
|
|
|
$subs[] = $data->getEveApiArgument('corporationID'); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
39 |
|
return vsprintf($mess, $subs); |
|
67
|
|
|
} |
|
68
|
|
|
/** |
|
69
|
|
|
* @param string $messagePrefix |
|
70
|
|
|
* @param EveApiReadWriteInterface $data |
|
71
|
|
|
* @param string $eventName |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
* @throws \LogicException |
|
75
|
|
|
*/ |
|
76
|
39 |
|
protected function createEventMessage( |
|
77
|
|
|
string $messagePrefix, |
|
78
|
|
|
EveApiReadWriteInterface $data, |
|
79
|
|
|
string $eventName |
|
80
|
|
|
): string { |
|
81
|
39 |
|
$messagePrefix .= sprintf(' the %s event while processing', $eventName); |
|
82
|
39 |
|
return $this->createEveApiMessage($messagePrefix, $data); |
|
83
|
|
|
} |
|
84
|
|
|
/** |
|
85
|
|
|
* @param EveApiReadWriteInterface $data |
|
86
|
|
|
* @param string $eventName |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
* @throws \LogicException |
|
90
|
|
|
*/ |
|
91
|
4 |
|
protected function getEmittingEventMessage(EveApiReadWriteInterface $data, string $eventName): string |
|
92
|
|
|
{ |
|
93
|
4 |
|
$messagePrefix = 'Emitting'; |
|
94
|
4 |
|
return $this->createEventMessage($messagePrefix, $data, $eventName); |
|
95
|
|
|
} |
|
96
|
|
|
/** |
|
97
|
|
|
* @param EveApiReadWriteInterface $data |
|
98
|
|
|
* @param string $eventName |
|
99
|
|
|
* |
|
100
|
|
|
* @return string |
|
101
|
|
|
* @throws \LogicException |
|
102
|
|
|
*/ |
|
103
|
|
|
protected function getEmptyXmlDataMessage(EveApiReadWriteInterface $data, string $eventName): string |
|
104
|
|
|
{ |
|
105
|
|
|
$messagePrefix = 'XML is empty after'; |
|
106
|
|
|
return $this->createEventMessage($messagePrefix, $data, $eventName); |
|
107
|
|
|
} |
|
108
|
|
|
/** |
|
109
|
|
|
* @param EveApiReadWriteInterface $data |
|
110
|
|
|
* @param string $fileName |
|
111
|
|
|
* |
|
112
|
|
|
* @return string |
|
113
|
|
|
* @throws \LogicException |
|
114
|
|
|
*/ |
|
115
|
|
|
protected function getFailedToWriteFileMessage( |
|
116
|
|
|
EveApiReadWriteInterface $data, |
|
117
|
|
|
string $fileName |
|
118
|
|
|
): string { |
|
119
|
|
|
$messagePrefix = sprintf('Writing file %s failed during the creation of', $fileName); |
|
120
|
|
|
return $this->createEveApiMessage($messagePrefix, $data); |
|
121
|
|
|
} |
|
122
|
|
|
/** |
|
123
|
|
|
* @param EveApiReadWriteInterface $data |
|
124
|
|
|
* @param string $eventName |
|
125
|
|
|
* |
|
126
|
|
|
* @return string |
|
127
|
|
|
* @throws \LogicException |
|
128
|
|
|
*/ |
|
129
|
|
|
protected function getFinishedEventMessage(EveApiReadWriteInterface $data, string $eventName): string |
|
130
|
|
|
{ |
|
131
|
|
|
$messagePrefix = 'Finished'; |
|
132
|
|
|
return $this->createEventMessage($messagePrefix, $data, $eventName); |
|
133
|
|
|
} |
|
134
|
|
|
/** |
|
135
|
|
|
* @param EveApiReadWriteInterface $data |
|
136
|
|
|
* @param string $eventName |
|
137
|
|
|
* |
|
138
|
|
|
* @return string |
|
139
|
|
|
* @throws \LogicException |
|
140
|
|
|
*/ |
|
141
|
4 |
|
protected function getNonHandledEventMessage(EveApiReadWriteInterface $data, string $eventName): string |
|
142
|
|
|
{ |
|
143
|
4 |
|
$messagePrefix = 'Nothing reported handling'; |
|
144
|
4 |
|
return $this->createEventMessage($messagePrefix, $data, $eventName); |
|
145
|
|
|
} |
|
146
|
|
|
/** |
|
147
|
|
|
* @param EveApiReadWriteInterface $data |
|
148
|
|
|
* @param string $eventName |
|
149
|
|
|
* @param string $location |
|
150
|
|
|
* |
|
151
|
|
|
* @return string |
|
152
|
|
|
* @throws \LogicException |
|
153
|
|
|
*/ |
|
154
|
39 |
|
protected function getReceivedEventMessage( |
|
155
|
|
|
EveApiReadWriteInterface $data, |
|
156
|
|
|
string $eventName, |
|
157
|
|
|
string $location |
|
158
|
|
|
): string { |
|
159
|
39 |
|
$messagePrefix = sprintf('Received in %s', $location); |
|
160
|
39 |
|
return $this->createEventMessage($messagePrefix, $data, $eventName); |
|
161
|
|
|
} |
|
162
|
|
|
/** |
|
163
|
|
|
* @param EveApiReadWriteInterface $data |
|
164
|
|
|
* @param string $eventName |
|
165
|
|
|
* |
|
166
|
|
|
* @return string |
|
167
|
|
|
* @throws \LogicException |
|
168
|
|
|
*/ |
|
169
|
|
|
protected function getSufficientlyHandledEventMessage(EveApiReadWriteInterface $data, string $eventName): string |
|
170
|
|
|
{ |
|
171
|
|
|
$messagePrefix = 'Sufficiently handled'; |
|
172
|
|
|
return $this->createEventMessage($messagePrefix, $data, $eventName); |
|
173
|
|
|
} |
|
174
|
|
|
/** |
|
175
|
|
|
* @param EveApiReadWriteInterface $data |
|
176
|
|
|
* @param string $eventName |
|
177
|
|
|
* |
|
178
|
|
|
* @return string |
|
179
|
|
|
* @throws \LogicException |
|
180
|
|
|
*/ |
|
181
|
|
|
protected function getWasHandledEventMessage(EveApiReadWriteInterface $data, string $eventName): string |
|
182
|
|
|
{ |
|
183
|
|
|
$messagePrefix = 'Handled'; |
|
184
|
|
|
return $this->createEventMessage($messagePrefix, $data, $eventName); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|