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