1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MOJEPANSTWO-API |
4
|
|
|
* |
5
|
|
|
* Copyright © 2017 pudelek.org.pl |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view source file |
10
|
|
|
* that is bundled with this package in the file LICENSE |
11
|
|
|
* |
12
|
|
|
* @author Marcin Pudełek <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare (strict_types=1); |
16
|
|
|
|
17
|
|
|
namespace mrcnpdlk\MojePanstwo; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
use mrcnpdlk\MojePanstwo\Model\Address\Commune; |
21
|
|
|
use mrcnpdlk\MojePanstwo\Model\Address\District; |
22
|
|
|
use mrcnpdlk\MojePanstwo\Model\Address\Province; |
23
|
|
|
use mrcnpdlk\MojePanstwo\Model\KrsEntity; |
24
|
|
|
use mrcnpdlk\MojePanstwo\Model\KrsEntityType; |
25
|
|
|
use mrcnpdlk\MojePanstwo\Model\KrsPerson; |
26
|
|
|
|
27
|
|
|
class Api |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var \mrcnpdlk\MojePanstwo\Api |
31
|
|
|
*/ |
32
|
|
|
protected static $instance; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \mrcnpdlk\MojePanstwo\Client |
36
|
|
|
*/ |
37
|
|
|
private $oClient; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Api constructor. |
41
|
|
|
* |
42
|
|
|
* @param \mrcnpdlk\MojePanstwo\Client $oClient |
43
|
|
|
*/ |
44
|
1 |
|
protected function __construct(Client $oClient) |
45
|
|
|
{ |
46
|
1 |
|
$this->oClient = $oClient; |
47
|
1 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param \mrcnpdlk\MojePanstwo\Client $oClient |
51
|
|
|
* |
52
|
|
|
* @return \mrcnpdlk\MojePanstwo\Api |
53
|
|
|
*/ |
54
|
11 |
|
public static function create(Client $oClient): Api |
55
|
|
|
{ |
56
|
11 |
|
if (null === static::$instance) { |
57
|
1 |
|
static::$instance = new static($oClient); |
58
|
|
|
} |
59
|
|
|
|
60
|
11 |
|
return static::$instance; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return \mrcnpdlk\MojePanstwo\Api |
65
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
66
|
|
|
*/ |
67
|
8 |
|
public static function getInstance(): Api |
68
|
|
|
{ |
69
|
8 |
|
if (null === static::$instance) { |
70
|
|
|
throw new Exception(sprintf('First call CREATE method!')); |
71
|
|
|
} |
72
|
|
|
|
73
|
8 |
|
return static::$instance; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return \mrcnpdlk\MojePanstwo\Client |
78
|
|
|
*/ |
79
|
9 |
|
public function getClient(): Client |
80
|
|
|
{ |
81
|
9 |
|
return $this->oClient; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param $id |
86
|
|
|
* |
87
|
|
|
* @return Commune |
88
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
89
|
|
|
*/ |
90
|
1 |
|
public function getCommune($id): Commune |
91
|
|
|
{ |
92
|
1 |
|
$qb = QueryBuilder::create(Commune::class); |
93
|
|
|
|
94
|
1 |
|
return $qb->find((string)$id); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param $id |
99
|
|
|
* |
100
|
|
|
* @return District |
101
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
102
|
|
|
*/ |
103
|
|
|
public function getDistrict($id): District |
104
|
|
|
{ |
105
|
|
|
$qb = QueryBuilder::create(District::class); |
106
|
|
|
|
107
|
|
|
return $qb->find((string)$id); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Return KRS Entity by ID (krs) |
112
|
|
|
* |
113
|
|
|
* @param string|int $krs ID or KRS number |
114
|
|
|
* |
115
|
|
|
* @param int $pullFlag Additional layers. E.i: KrsEntity::PULL_PKDS | KrsEntity::PULL_PERSON_REPRESENTATION |
116
|
|
|
* |
117
|
|
|
* @return \mrcnpdlk\MojePanstwo\Model\KrsEntity |
118
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
119
|
|
|
*/ |
120
|
|
|
public function getKrsEntity($krs, int $pullFlag = KrsEntity::PULL_NONE): KrsEntity |
121
|
|
|
{ |
122
|
|
|
$krs = (int)$krs; |
123
|
|
|
$qb = QueryBuilder::create(KrsEntity::class) |
124
|
|
|
->addLayer('jedynyAkcjonariusz') |
125
|
|
|
->addLayer('komitetZalozycielski') |
126
|
|
|
; |
127
|
|
|
if ($pullFlag & KrsEntity::PULL_COMPANIES) { |
128
|
|
|
$qb->addLayer('firmy'); |
129
|
|
|
} |
130
|
|
|
if ($pullFlag & KrsEntity::PULL_DEPARTMENTS) { |
131
|
|
|
$qb->addLayer('oddzialy'); |
132
|
|
|
} |
133
|
|
|
if ($pullFlag & KrsEntity::PULL_PARTNERS) { |
134
|
|
|
$qb->addLayer('wspolnicy'); |
135
|
|
|
} |
136
|
|
|
if ($pullFlag & KrsEntity::PULL_PKDS) { |
137
|
|
|
$qb->addLayer('dzialalnosci'); |
138
|
|
|
} |
139
|
|
|
if ($pullFlag & KrsEntity::PULL_SHARES) { |
140
|
|
|
$qb->addLayer('emisje_akcji'); |
141
|
|
|
} |
142
|
|
|
if ($pullFlag & KrsEntity::PULL_PERSON_REPRESENTATION) { |
143
|
|
|
$qb->addLayer('reprezentacja'); |
144
|
|
|
} |
145
|
|
|
if ($pullFlag & KrsEntity::PULL_PERSON_SUPERVISION) { |
146
|
|
|
$qb->addLayer('nadzor'); |
147
|
|
|
} |
148
|
|
|
if ($pullFlag & KrsEntity::PULL_PERSON_PROXY) { |
149
|
|
|
$qb->addLayer('prokurenci'); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return $qb->find((string)$krs); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Return KRS Entity Type |
157
|
|
|
* |
158
|
|
|
* @param $id |
159
|
|
|
* |
160
|
|
|
* @return \mrcnpdlk\MojePanstwo\Model\KrsEntityType |
161
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
162
|
|
|
*/ |
163
|
|
|
public function getKrsEntityType($id): KrsEntityType |
164
|
|
|
{ |
165
|
|
|
$qb = QueryBuilder::create(KrsEntityType::class); |
166
|
|
|
|
167
|
|
|
return $qb->find((string)$id); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param $id |
172
|
|
|
* |
173
|
|
|
* @return KrsPerson |
174
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
175
|
|
|
*/ |
176
|
|
|
public function getPerson($id): KrsPerson |
177
|
|
|
{ |
178
|
|
|
$qb = QueryBuilder::create(KrsPerson::class); |
179
|
|
|
|
180
|
|
|
return $qb->find((string)$id); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Return Province |
185
|
|
|
* |
186
|
|
|
* @param $id |
187
|
|
|
* |
188
|
|
|
* @return Province |
189
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
190
|
|
|
*/ |
191
|
1 |
|
public function getProvince($id): Province |
192
|
|
|
{ |
193
|
1 |
|
$qb = QueryBuilder::create(Province::class); |
194
|
|
|
|
195
|
1 |
|
return $qb->find((string)$id); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return \mrcnpdlk\MojePanstwo\QueryBuilder |
200
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
201
|
|
|
*/ |
202
|
1 |
|
public function searchCommune(): QueryBuilder |
203
|
|
|
{ |
204
|
1 |
|
return QueryBuilder::create(Commune::class); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return \mrcnpdlk\MojePanstwo\QueryBuilder |
209
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
210
|
|
|
*/ |
211
|
1 |
|
public function searchDistrict(): QueryBuilder |
212
|
|
|
{ |
213
|
1 |
|
return QueryBuilder::create(District::class); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Return QueryBuilder for searching KRS Entities |
218
|
|
|
* |
219
|
|
|
* @return \mrcnpdlk\MojePanstwo\QueryBuilder |
220
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
221
|
|
|
*/ |
222
|
1 |
|
public function searchKrsEntity(): QueryBuilder |
223
|
|
|
{ |
224
|
1 |
|
return QueryBuilder::create(KrsEntity::class); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Return QueryBuilder for searching KRS Entity Types |
229
|
|
|
* |
230
|
|
|
* @return \mrcnpdlk\MojePanstwo\QueryBuilder |
231
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
232
|
|
|
*/ |
233
|
1 |
|
public function searchKrsEntityType(): QueryBuilder |
234
|
|
|
{ |
235
|
1 |
|
return QueryBuilder::create(KrsEntityType::class); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Wyszukiwanie osoby w KRS |
240
|
|
|
* |
241
|
|
|
* @return \mrcnpdlk\MojePanstwo\QueryBuilder |
242
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
243
|
|
|
*/ |
244
|
1 |
|
public function searchKrsPerson(): QueryBuilder |
245
|
|
|
{ |
246
|
1 |
|
return QueryBuilder::create(KrsPerson::class); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @return \mrcnpdlk\MojePanstwo\QueryBuilder |
251
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
252
|
|
|
*/ |
253
|
1 |
|
public function searchProvince(): QueryBuilder |
254
|
|
|
{ |
255
|
1 |
|
return QueryBuilder::create(Province::class); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
} |
259
|
|
|
|