|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SergeyNezbritskiy\NovaPoshta\Models; |
|
4
|
|
|
|
|
5
|
|
|
use SergeyNezbritskiy\NovaPoshta\Connection; |
|
6
|
|
|
use SergeyNezbritskiy\NovaPoshta\ModelInterface; |
|
7
|
|
|
use SergeyNezbritskiy\NovaPoshta\NovaPoshtaApiException; |
|
8
|
|
|
|
|
9
|
|
|
class Address implements ModelInterface |
|
10
|
|
|
{ |
|
11
|
|
|
private const MODEL_NAME = 'Address'; |
|
12
|
|
|
private Connection $connection; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param Connection $connection |
|
16
|
|
|
*/ |
|
17
|
3 |
|
public function __construct(Connection $connection) |
|
18
|
|
|
{ |
|
19
|
3 |
|
$this->connection = $connection; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $cityName |
|
24
|
|
|
* @param int $page |
|
25
|
|
|
* @param int $limit |
|
26
|
|
|
* @return array |
|
27
|
|
|
* @throws NovaPoshtaApiException |
|
28
|
|
|
*/ |
|
29
|
1 |
|
public function searchSettlements(string $cityName, int $page = 1, int $limit = PHP_INT_MAX): array |
|
30
|
|
|
{ |
|
31
|
1 |
|
$params = array_filter([ |
|
32
|
1 |
|
'CityName' => $cityName, |
|
33
|
1 |
|
'Page' => $page, |
|
34
|
1 |
|
'Limit' => $limit, |
|
35
|
1 |
|
]); |
|
36
|
1 |
|
$result = $this->connection->post(self::MODEL_NAME, 'searchSettlements', $params); |
|
37
|
|
|
return array_shift($result); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param string $streetName |
|
42
|
|
|
* @param string $settlementRef |
|
43
|
|
|
* @param int $limit |
|
44
|
|
|
* @return array |
|
45
|
|
|
* @throws NovaPoshtaApiException |
|
46
|
|
|
*/ |
|
47
|
1 |
|
public function searchSettlementStreets(string $streetName, string $settlementRef, int $limit = null): array |
|
48
|
|
|
{ |
|
49
|
1 |
|
$params = array_filter([ |
|
50
|
1 |
|
'StreetName' => $streetName, |
|
51
|
1 |
|
'SettlementRef' => $settlementRef, |
|
52
|
1 |
|
'Limit' => $limit, |
|
53
|
1 |
|
]); |
|
54
|
1 |
|
$result = $this->connection->post(self::MODEL_NAME, 'searchSettlementStreets', $params); |
|
55
|
1 |
|
return array_shift($result); |
|
56
|
1 |
|
} |
|
57
|
1 |
|
|
|
58
|
1 |
|
/** |
|
59
|
|
|
* @param int $page |
|
60
|
|
|
* @param int $limit |
|
61
|
|
|
* @param string|null $search |
|
62
|
|
|
* @return array |
|
63
|
|
|
* @throws NovaPoshtaApiException |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getCities(int $page = 1, int $limit = PHP_INT_MAX, string $search = null): array |
|
66
|
|
|
{ |
|
67
|
|
|
$params = array_filter([ |
|
68
|
|
|
'Page' => $page, |
|
69
|
|
|
'Limit' => $limit, |
|
70
|
|
|
'FindByString' => $search, |
|
71
|
|
|
]); |
|
72
|
|
|
return $this->connection->post(self::MODEL_NAME, 'getCities', $params); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param array $filters Available filters are: CityName, CityRef, TypeOfWarehouseRef, WarehouseId |
|
77
|
|
|
* @param int $page |
|
78
|
|
|
* @param int $limit |
|
79
|
|
|
* @param string $lang |
|
80
|
|
|
* @return array |
|
81
|
|
|
* @throws NovaPoshtaApiException |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getWarehouses(array $filters = [], int $page = 1, int $limit = 1000, string $lang = 'UA'): array |
|
84
|
|
|
{ |
|
85
|
|
|
$params = array_filter([ |
|
86
|
|
|
'CityName' => $filters['CityName'] ?? null, |
|
87
|
|
|
'CityRef' => $filters['CityRef'] ?? null, |
|
88
|
|
|
'TypeOfWarehouseRef' => $filters['TypeOfWarehouseRef'] ?? null, |
|
89
|
|
|
'WarehouseId' => $filters['WarehouseId'] ?? null, |
|
90
|
|
|
'Page' => $page, |
|
91
|
|
|
'Limit' => $limit, |
|
92
|
|
|
'Language' => $lang, |
|
93
|
|
|
]); |
|
94
|
|
|
return $this->connection->post(self::MODEL_NAME, 'getWarehouses', $params); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|