1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TERYT-API |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 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
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Created by Marcin Pudełek <[email protected]> |
18
|
|
|
* Date: 07.09.2017 |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace mrcnpdlk\Teryt\Model; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
use mrcnpdlk\Teryt\Exception; |
25
|
|
|
use mrcnpdlk\Teryt\NativeApi; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class Province |
29
|
|
|
* |
30
|
|
|
* @package mrcnpdlk\Teryt\Model |
31
|
|
|
*/ |
32
|
|
|
class Province extends EntityAbstract |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Dwuznakowy symbol województwa |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
public $id; |
40
|
|
|
/** |
41
|
|
|
* Nazwa województwa |
42
|
|
|
* |
43
|
|
|
* @var static |
44
|
|
|
*/ |
45
|
|
|
public $name; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Province constructor. |
49
|
|
|
* |
50
|
|
|
* @param string $id Dwuznakowy symbol województwa |
51
|
|
|
* |
52
|
|
|
* @return $this |
53
|
|
|
* @throws Exception\NotFound |
54
|
|
|
*/ |
55
|
1 |
|
public function find(string $id) |
56
|
|
|
{ |
57
|
1 |
|
foreach (NativeApi::getInstance()->PobierzListeWojewodztw() as $w) { |
58
|
1 |
|
if ($w->provinceId === $id) { |
59
|
1 |
|
$this->id = $w->provinceId; |
60
|
1 |
|
$this->name = $w->name; |
|
|
|
|
61
|
|
|
} |
62
|
|
|
} |
63
|
1 |
|
if (!$this->id) { |
64
|
|
|
throw new Exception\NotFound(sprintf('Province [id:%s] not exists', $id)); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Pełnokontekstowe wyszukiwanie powiatów w województwie |
73
|
|
|
* |
74
|
|
|
* @param string|null $phrase Szukana fraza, gdy NULL zwraca wszystkie powiaty w województwie |
75
|
|
|
* |
76
|
|
|
* @return \mrcnpdlk\Teryt\Model\District[] |
77
|
|
|
* @throws \Exception |
78
|
|
|
*/ |
79
|
|
|
public function searchDistricts(string $phrase = null) |
80
|
|
|
{ |
81
|
|
|
try { |
82
|
|
|
$answer = []; |
83
|
|
|
if ($phrase) { |
|
|
|
|
84
|
|
|
$tList = NativeApi::getInstance()->WyszukajJednostkeWRejestrze($phrase, NativeApi::CATEGORY_POW_ALL); |
85
|
|
|
foreach ($tList as $p) { |
86
|
|
|
if ($p->provinceId === $this->id) { |
87
|
|
|
$answer[] = (new District())->find($p->provinceId . $p->districtId); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} else { |
91
|
|
|
$tList = NativeApi::getInstance()->PobierzListePowiatow($this->id); |
92
|
|
|
foreach ($tList as $p) { |
93
|
|
|
$answer[] = (new District())->find($p->provinceId . $p->districtId); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $answer; |
98
|
|
|
|
99
|
|
|
} catch (Exception\NotFound $e) { |
100
|
|
|
return []; |
101
|
|
|
} catch (\Exception $e) { |
102
|
|
|
throw $e; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..