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