1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace DMT\Insolvency; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use DMT\CommandBus\Validator\ValidationMiddleware; |
7
|
|
|
use DMT\Http\Client\RequestHandler; |
8
|
|
|
use DMT\Insolvency\Exception\Exception; |
9
|
|
|
use DMT\Insolvency\Exception\ExceptionMiddleware; |
10
|
|
|
use DMT\Insolvency\Http\GetReportHandler; |
11
|
|
|
use DMT\Insolvency\Http\Middleware\ExceptionMiddleware as HttpExceptionMiddleware; |
12
|
|
|
use DMT\Insolvency\Http\Middleware\SoapActionMiddleware; |
13
|
|
|
use DMT\Insolvency\Http\Request\GetReport; |
14
|
|
|
use DMT\Insolvency\Http\Response\GetReportResponse; |
15
|
|
|
use DMT\Insolvency\Model\BeschikbareVerslagen; |
16
|
|
|
use DMT\Insolvency\Model\Document; |
17
|
|
|
use DMT\Insolvency\Model\Insolvente; |
18
|
|
|
use DMT\Insolvency\Model\LastUpdate; |
19
|
|
|
use DMT\Insolvency\Model\PublicatieLijst; |
20
|
|
|
use DMT\Insolvency\Model\VerwijderdePublicatieLijst; |
21
|
|
|
use DMT\Insolvency\Soap\Handler as SoapHandler; |
22
|
|
|
use DMT\Insolvency\Soap\Request; |
23
|
|
|
use DMT\Insolvency\Soap\Request as SoapRequest; |
24
|
|
|
use DMT\Insolvency\Soap\Response; |
25
|
|
|
use DMT\Insolvency\Soap\Serializer\SoapSerializer; |
26
|
|
|
use GuzzleHttp\Client as HttpClient; |
27
|
|
|
use JMS\Serializer\SerializerInterface; |
28
|
|
|
use League\Tactician\CommandBus; |
29
|
|
|
use League\Tactician\Handler\CommandHandlerMiddleware; |
30
|
|
|
use League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor; |
31
|
|
|
use League\Tactician\Handler\Locator\CallableLocator; |
32
|
|
|
use League\Tactician\Handler\MethodNameInflector\HandleInflector; |
33
|
|
|
use League\Tactician\Plugins\LockingMiddleware; |
34
|
|
|
use Psr\Http\Client\ClientInterface; |
35
|
|
|
use Psr\Http\Message\RequestFactoryInterface; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Class Client |
39
|
|
|
*/ |
|
|
|
|
40
|
|
|
class Client |
41
|
|
|
{ |
42
|
|
|
private Config $config; |
|
|
|
|
43
|
|
|
private ClientInterface $client; |
|
|
|
|
44
|
|
|
private RequestFactoryInterface $requestFactory; |
|
|
|
|
45
|
|
|
private SerializerInterface $serializer; |
|
|
|
|
46
|
|
|
private CommandBus $commandBus; |
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
|
|
|
|
49
|
|
|
* @param Config $config |
|
|
|
|
50
|
|
|
* @param ClientInterface $client |
|
|
|
|
51
|
|
|
* @param RequestFactoryInterface $requestFactory |
|
|
|
|
52
|
|
|
* @param SoapSerializer|null $serializer |
|
|
|
|
53
|
|
|
*/ |
54
|
11 |
|
public function __construct( |
55
|
|
|
Config $config, |
56
|
|
|
ClientInterface $client, |
57
|
|
|
RequestFactoryInterface $requestFactory, |
58
|
|
|
SoapSerializer $serializer = null |
59
|
|
|
) { |
60
|
11 |
|
$this->config = $config; |
61
|
11 |
|
$this->client = $client; |
62
|
11 |
|
$this->requestFactory = $requestFactory; |
63
|
11 |
|
$this->serializer = $serializer ?? new SoapSerializer($this, $config); |
64
|
|
|
|
65
|
11 |
|
$this->commandBus = new CommandBus([ |
|
|
|
|
66
|
11 |
|
new LockingMiddleware(), |
67
|
11 |
|
new ExceptionMiddleware(), |
68
|
11 |
|
new ValidationMiddleware(), |
69
|
11 |
|
new CommandHandlerMiddleware( |
70
|
11 |
|
new ClassNameExtractor(), |
71
|
11 |
|
new CallableLocator([$this, 'getHandler']), |
72
|
11 |
|
new HandleInflector() |
73
|
|
|
) |
74
|
|
|
]); |
|
|
|
|
75
|
11 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Search for publications of a specific insolvency. |
79
|
|
|
* |
80
|
|
|
* @param string $insolvencyID the insolvency identification. |
|
|
|
|
81
|
|
|
* @param string|null $court the count (number) where the insolvency is registered. |
|
|
|
|
82
|
|
|
* |
83
|
|
|
* @return PublicatieLijst |
84
|
|
|
* @throws Exception |
85
|
|
|
*/ |
86
|
1 |
|
public function searchInsolvencyId(string $insolvencyID, string $court = null): PublicatieLijst |
87
|
|
|
{ |
88
|
1 |
|
$request = new Request\SearchInsolvencyID(); |
89
|
1 |
|
$request->insolvencyID = $insolvencyID; |
90
|
1 |
|
$request->court = $court; |
91
|
|
|
|
92
|
|
|
/** @var Response\SearchInsolvencyIDResponse $response */ |
|
|
|
|
93
|
1 |
|
$response = $this->process($request); |
94
|
|
|
|
95
|
1 |
|
return $response->result->publicatieLijst; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Search for publications for a person. |
100
|
|
|
* |
101
|
|
|
* @param DateTime|null $dateOfBirth the date of birth of the person. |
102
|
|
|
* @param string|null $prefix the surname prefix. |
|
|
|
|
103
|
|
|
* @param string|null $surname the surname of the person. |
|
|
|
|
104
|
|
|
* @param int|null $houseNumber the house number of the person's address. |
|
|
|
|
105
|
|
|
* @param string|null $postalCode the postcode of the person's address. |
|
|
|
|
106
|
|
|
* |
107
|
|
|
* @return PublicatieLijst |
108
|
|
|
* @throws Exception |
109
|
|
|
*/ |
110
|
1 |
|
public function searchNaturalPerson( |
111
|
|
|
DateTime $dateOfBirth = null, |
112
|
|
|
string $prefix = null, |
113
|
|
|
string $surname = null, |
114
|
|
|
int $houseNumber = null, |
115
|
|
|
string $postalCode = null |
116
|
|
|
): PublicatieLijst { |
117
|
1 |
|
$request = new Request\SearchNaturalPerson(); |
118
|
1 |
|
$request->dateOfBirth = $dateOfBirth; |
119
|
1 |
|
$request->prefix = $prefix; |
120
|
1 |
|
$request->surname = $surname; |
121
|
1 |
|
$request->houseNumber = $houseNumber; |
122
|
1 |
|
$request->postalCode = $postalCode; |
123
|
|
|
|
124
|
|
|
/** @var Response\SearchNaturalPersonResponse $response */ |
|
|
|
|
125
|
1 |
|
$response = $this->process($request); |
126
|
|
|
|
127
|
1 |
|
return $response->result->publicatieLijst; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Search for publications of an undertaking. |
132
|
|
|
* |
133
|
|
|
* @param string|null $name the name of the undertaking. |
|
|
|
|
134
|
|
|
* @param string|null $commercialRegisterID the chamber of commerce number. |
135
|
|
|
* @param string|null $postalCode the postcode of the undertaking's address. |
|
|
|
|
136
|
|
|
* @param int|null $houseNumber the house number of the undertaking' address. |
|
|
|
|
137
|
|
|
* |
138
|
|
|
* @return PublicatieLijst |
139
|
|
|
* @throws Exception |
140
|
|
|
*/ |
141
|
1 |
|
public function searchUndertaking( |
142
|
|
|
string $name = null, |
143
|
|
|
string $commercialRegisterID = null, |
144
|
|
|
string $postalCode = null, |
145
|
|
|
int $houseNumber = null |
146
|
|
|
): PublicatieLijst { |
147
|
1 |
|
$request = new Request\SearchUndertaking(); |
148
|
1 |
|
$request->name = $name; |
149
|
1 |
|
$request->commercialRegisterID = $commercialRegisterID; |
150
|
1 |
|
$request->postalCode = $postalCode; |
151
|
1 |
|
$request->houseNumber = $houseNumber; |
152
|
|
|
|
153
|
|
|
/** @var Response\SearchUndertakingResponse $response */ |
|
|
|
|
154
|
1 |
|
$response = $this->process($request); |
155
|
|
|
|
156
|
1 |
|
return $response->result->publicatieLijst; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get insolvency case. |
161
|
|
|
* |
162
|
|
|
* @param string $publicationNumber the publication number of the case. |
163
|
|
|
* @param bool $includeReports set to true to include reports. |
|
|
|
|
164
|
|
|
* |
165
|
|
|
* @return Insolvente |
166
|
|
|
* @throws Exception |
167
|
|
|
*/ |
168
|
7 |
|
public function getCase(string $publicationNumber, bool $includeReports = false): Insolvente |
169
|
|
|
{ |
170
|
7 |
|
$request = $includeReports ? new Request\GetCaseWithReports() : new Request\GetCase(); |
171
|
7 |
|
$request->publicationNumber = $publicationNumber; |
172
|
|
|
|
173
|
|
|
/** @var Response\GetCaseResponse $response */ |
|
|
|
|
174
|
7 |
|
$response = $this->process($request); |
175
|
|
|
|
176
|
7 |
|
return $response->result->inspubWebserviceInsolvente->insolvente; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Get a report for an insolvency. |
181
|
|
|
* |
182
|
|
|
* @param string $reportId the report identification number. |
183
|
|
|
* |
184
|
|
|
* @return Document |
185
|
|
|
* @throws Exception |
186
|
|
|
*/ |
187
|
3 |
|
public function getReport(string $reportId): Document |
188
|
|
|
{ |
189
|
3 |
|
$request = new GetReport(); |
190
|
3 |
|
$request->reportId = $reportId; |
191
|
|
|
|
192
|
|
|
/** @var GetReportResponse $response */ |
|
|
|
|
193
|
3 |
|
$response = $this->process($request); |
194
|
|
|
|
195
|
3 |
|
return $response->result->report; |
196
|
|
|
|
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Get the date when the latest publication is added. |
201
|
|
|
* |
202
|
|
|
* @return LastUpdate |
203
|
|
|
* @throws Exception |
204
|
|
|
*/ |
205
|
1 |
|
public function getLastUpdate(): LastUpdate |
206
|
|
|
{ |
207
|
|
|
/** @var Response\GetLastUpdateResponse $response */ |
|
|
|
|
208
|
1 |
|
$response = $this->process(new Request\GetLastUpdate()); |
209
|
|
|
|
210
|
1 |
|
return $response->result->lastUpdate; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Search for publications of a specific date. |
215
|
|
|
* |
216
|
|
|
* @param DateTime $date tne date of the publications to look up. |
|
|
|
|
217
|
|
|
* @param string $court the court (number) where the publications are registered. |
|
|
|
|
218
|
|
|
* @param string|null $pubType the type of publication. |
219
|
|
|
* |
220
|
|
|
* @return PublicatieLijst |
221
|
|
|
* @throws Exception |
222
|
|
|
*/ |
223
|
1 |
|
public function searchByDate(DateTime $date, string $court, string $pubType = null): PublicatieLijst |
224
|
|
|
{ |
225
|
1 |
|
$request = new Request\SearchByDate(); |
226
|
1 |
|
$request->date = $date; |
227
|
1 |
|
$request->court = $court; |
228
|
1 |
|
$request->pubType = $pubType; |
229
|
|
|
|
230
|
|
|
/** @var Response\SearchByDateResponse $response */ |
|
|
|
|
231
|
1 |
|
$response = $this->process($request); |
232
|
|
|
|
233
|
1 |
|
return $response->result->publicatieLijst; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Search for publications of the last mutated/added insolvencies for data replication. |
238
|
|
|
* |
239
|
|
|
* @param DateTime $modifyDate the modified date since. |
240
|
|
|
* |
241
|
|
|
* @return PublicatieLijst |
242
|
|
|
* @throws Exception |
243
|
|
|
*/ |
244
|
1 |
|
public function searchModifiedSince(DateTime $modifyDate): PublicatieLijst |
245
|
|
|
{ |
246
|
1 |
|
$request = new Request\SearchModifiedSince(); |
247
|
1 |
|
$request->modifyDate = $modifyDate; |
248
|
|
|
|
249
|
|
|
/** @var Response\SearchModifiedSinceResponse $response */ |
|
|
|
|
250
|
1 |
|
$response = $this->process($request); |
251
|
|
|
|
252
|
1 |
|
return $response->result->publicatieLijst; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Search for removed publications for data replication. |
257
|
|
|
* |
258
|
|
|
* @param DateTime $modifyDate the modified date since. |
259
|
|
|
* |
260
|
|
|
* @return VerwijderdePublicatieLijst |
261
|
|
|
* @throws Exception |
262
|
|
|
*/ |
263
|
1 |
|
public function searchRemovedSince(DateTime $modifyDate): VerwijderdePublicatieLijst |
264
|
|
|
{ |
265
|
1 |
|
$request = new Request\SearchRemovedSince(); |
266
|
1 |
|
$request->modifyDate = $modifyDate; |
267
|
|
|
|
268
|
|
|
/** @var Response\SearchRemovedSinceResponse $response */ |
|
|
|
|
269
|
1 |
|
$response = $this->process($request); |
270
|
|
|
|
271
|
1 |
|
return $response->result->verwijderdePublicatieLijst; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Search for added and modified reposts in a given time period. |
276
|
|
|
* |
277
|
|
|
* @param DateTime $datetimeFrom the start date. |
|
|
|
|
278
|
|
|
* @param DateTime|null $datetimeTo the end date. |
|
|
|
|
279
|
|
|
* |
280
|
|
|
* @return BeschikbareVerslagen |
281
|
|
|
* @throws Exception |
282
|
|
|
*/ |
283
|
1 |
|
public function searchReportsSince(DateTime $datetimeFrom, DateTime $datetimeTo = null): BeschikbareVerslagen |
284
|
|
|
{ |
285
|
1 |
|
$request = new Request\SearchReportsSince(); |
286
|
1 |
|
$request->datetimeFrom = $datetimeFrom; |
287
|
1 |
|
$request->datetimeTo = $datetimeTo ?? new DateTime(); |
288
|
|
|
|
289
|
|
|
/** @var Response\SearchReportsSinceResponse $response */ |
|
|
|
|
290
|
1 |
|
$response = $this->process($request); |
291
|
|
|
|
292
|
1 |
|
return $response->result->beschikbareVerslagen; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
|
|
|
|
296
|
|
|
* @param string $request |
|
|
|
|
297
|
|
|
* @return SoapHandler|object |
|
|
|
|
298
|
|
|
* @internal |
|
|
|
|
299
|
|
|
*/ |
300
|
|
|
public function getHandler(string $request) |
301
|
|
|
{ |
302
|
|
|
if (is_a($request, SoapRequest::class, true)) { |
303
|
|
|
return new SoapHandler($this->config, $this->getRequestHandler(), $this->requestFactory, $this->serializer); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
return new GetReportHandler($this->config, $this->getRequestHandler(false), $this->requestFactory); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Process a request. |
311
|
|
|
* |
312
|
|
|
* @param Request|GetReport $request |
|
|
|
|
313
|
|
|
* |
314
|
|
|
* @return Response|GetReportResponse |
315
|
|
|
* @throws Exception |
316
|
|
|
*/ |
317
|
11 |
|
protected function process($request) |
318
|
|
|
{ |
319
|
11 |
|
if (!$request instanceof Request && !$request instanceof GetReport) { |
|
|
|
|
320
|
|
|
throw new \TypeError('Invalid request'); |
321
|
|
|
} |
322
|
|
|
|
323
|
11 |
|
return $this->commandBus->handle($request); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Get http client. |
328
|
|
|
* |
329
|
|
|
* @param bool $forSoap |
|
|
|
|
330
|
|
|
* @return HttpClient |
|
|
|
|
331
|
|
|
*/ |
332
|
|
|
protected function getRequestHandler(bool $forSoap = true): RequestHandler |
333
|
|
|
{ |
334
|
|
|
$middleware = [ |
335
|
|
|
new HttpExceptionMiddleware(), |
336
|
|
|
]; |
337
|
|
|
|
338
|
|
|
if ($forSoap) { |
339
|
|
|
$middleware[] = new SoapActionMiddleware(); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
return new RequestHandler($this->client, ...$middleware); |
|
|
|
|
343
|
|
|
} |
344
|
|
|
} |
345
|
|
|
|