1 | <?php |
||
40 | class EveApiXmlData implements EveApiReadWriteInterface |
||
41 | { |
||
42 | /** |
||
43 | * Used to add item to arguments list. |
||
44 | * |
||
45 | * @param string $name |
||
46 | * @param string $value |
||
47 | * |
||
48 | * @return self Fluent interface. |
||
49 | */ |
||
50 | public function addEveApiArgument(string $name, string $value): self |
||
51 | { |
||
52 | $this->eveApiArguments[$name] = $value; |
||
53 | return $this; |
||
54 | } |
||
55 | /** |
||
56 | * Getter for cache interval. |
||
57 | * |
||
58 | * @return int |
||
59 | * @throws \LogicException |
||
60 | */ |
||
61 | public function getCacheInterval(): int |
||
62 | { |
||
63 | return $this->cacheInterval; |
||
64 | } |
||
65 | /** |
||
66 | * Getter for an existing Eve API argument. |
||
67 | * |
||
68 | * @param string $name |
||
69 | * |
||
70 | * @return string |
||
71 | * @throws \DomainException |
||
72 | */ |
||
73 | public function getEveApiArgument(string $name): string |
||
74 | { |
||
75 | if (!array_key_exists($name, $this->eveApiArguments)) { |
||
76 | $mess = 'Unknown argument ' . $name; |
||
77 | throw new \DomainException($mess); |
||
78 | } |
||
79 | return $this->eveApiArguments[$name]; |
||
80 | } |
||
81 | /** |
||
82 | * Getter for Eve API argument list. |
||
83 | * |
||
84 | * @return string[] |
||
85 | */ |
||
86 | 25 | public function getEveApiArguments(): array |
|
87 | { |
||
88 | 25 | return $this->eveApiArguments; |
|
89 | } |
||
90 | /** |
||
91 | * Getter for name of Eve API. |
||
92 | * |
||
93 | * @return string |
||
94 | * @throws \LogicException Throws exception if accessed before being set. |
||
95 | */ |
||
96 | 39 | public function getEveApiName(): string |
|
97 | { |
||
98 | 39 | if (null === $this->eveApiName) { |
|
99 | $mess = 'Tried to access Eve Api name before it was set'; |
||
100 | throw new \LogicException($mess); |
||
101 | } |
||
102 | 39 | return $this->eveApiName; |
|
103 | } |
||
104 | /** |
||
105 | * Getter for name of Eve API section. |
||
106 | * |
||
107 | * @return string |
||
108 | * @throws \LogicException Throws exception if accessed before being set. |
||
109 | */ |
||
110 | 39 | public function getEveApiSectionName(): string |
|
111 | { |
||
112 | 39 | if (null === $this->eveApiSectionName) { |
|
113 | $mess = 'Tried to access Eve Api section name before it was set'; |
||
114 | throw new \LogicException($mess); |
||
115 | } |
||
116 | 39 | return $this->eveApiSectionName; |
|
117 | } |
||
118 | /** |
||
119 | * Getter for the actual Eve API XML received. |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | 35 | public function getEveApiXml(): string |
|
124 | { |
||
125 | 35 | return $this->eveApiXml; |
|
126 | } |
||
127 | /** |
||
128 | * Used to get a repeatable unique hash for any combination API name, section, and arguments. |
||
129 | * |
||
130 | * @return string |
||
131 | * @throws \LogicException |
||
132 | */ |
||
133 | 14 | public function getHash(): string |
|
134 | { |
||
135 | 14 | $hash = $this->getEveApiName() . $this->getEveApiSectionName(); |
|
136 | 14 | $arguments = $this->getEveApiArguments(); |
|
137 | 14 | unset($arguments['mask'], $arguments['rowCount']); |
|
138 | 14 | ksort($arguments); |
|
139 | 14 | foreach ($arguments as $key => $value) { |
|
140 | $hash .= $key . $value; |
||
141 | } |
||
142 | 14 | return hash('md5', $hash); |
|
143 | } |
||
144 | /** |
||
145 | * Used to check if an argument exists. |
||
146 | * |
||
147 | * @param string $name |
||
148 | * |
||
149 | * @return bool |
||
150 | */ |
||
151 | 39 | public function hasEveApiArgument(string $name): bool |
|
152 | { |
||
153 | 39 | return array_key_exists($name, $this->eveApiArguments); |
|
154 | } |
||
155 | /** |
||
156 | * Cache interval setter. |
||
157 | * |
||
158 | * @param int $value Caching interval in seconds. |
||
159 | * |
||
160 | * @return self Fluent interface. |
||
161 | */ |
||
162 | public function setCacheInterval(int $value): self |
||
167 | /** |
||
168 | * Used to set a list of arguments used when forming request to Eve Api |
||
169 | * server. |
||
170 | * |
||
171 | * Things like KeyID, vCode etc that are either required or optional for the |
||
172 | * Eve API. See adder for example. |
||
173 | * |
||
174 | * Example: |
||
175 | * <code> |
||
176 | * <?php |
||
177 | * $args = array( 'KeyID' => '1156', 'vCode' => 'abc123'); |
||
178 | * $api->setEveApiArguments($args); |
||
179 | * ... |
||
180 | * </code> |
||
181 | * |
||
182 | * @param string[] $values |
||
183 | * |
||
184 | * @return self Fluent interface. |
||
185 | * @uses EveApiXmlData::addEveApiArgument() |
||
186 | */ |
||
187 | public function setEveApiArguments(array $values): self |
||
198 | /** |
||
199 | * Eve API name setter. |
||
200 | * |
||
201 | * @param string $value |
||
202 | * |
||
203 | * @return self Fluent interface. |
||
204 | */ |
||
205 | 40 | public function setEveApiName(string $value): self |
|
210 | /** |
||
211 | * Eve API section name setter. |
||
212 | * |
||
213 | * @param string $value |
||
214 | * |
||
215 | * @return self Fluent interface. |
||
216 | */ |
||
217 | 40 | public function setEveApiSectionName(string $value): self |
|
222 | /** |
||
223 | * Sets the actual Eve API XML data received. |
||
224 | * |
||
225 | * @param string $xml Actual XML content. |
||
226 | * |
||
227 | * @return self Fluent interface. |
||
228 | */ |
||
229 | 37 | public function setEveApiXml(string $xml = ''): self |
|
234 | /** |
||
235 | * Holds expected/calculated cache interval for the current API in seconds. |
||
236 | * |
||
237 | * @var int $cacheInterval |
||
238 | */ |
||
239 | private $cacheInterval = 300; |
||
240 | /** |
||
241 | * List of API arguments. |
||
242 | * |
||
243 | * @var string[] $eveApiArguments |
||
244 | */ |
||
245 | private $eveApiArguments = []; |
||
246 | /** |
||
247 | * Holds Eve API name. |
||
248 | * |
||
249 | * @var string $eveApiName |
||
250 | */ |
||
251 | private $eveApiName; |
||
252 | /** |
||
253 | * Holds Eve API section name. |
||
254 | * |
||
255 | * @var string $eveApiSectionName |
||
256 | */ |
||
257 | private $eveApiSectionName; |
||
258 | /** |
||
259 | * Holds the actual Eve API XML data. |
||
260 | * |
||
261 | * @var string $eveApiXml |
||
262 | */ |
||
263 | private $eveApiXml = ''; |
||
264 | } |
||
265 |