1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of RussianPost SDK package. |
5
|
|
|
* |
6
|
|
|
* © Appwilio (http://appwilio.com), JhaoDa (https://github.com/jhaoda) |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Appwilio\RussianPostSDK\Dispatching; |
15
|
|
|
|
16
|
|
|
use Psr\Log\NullLogger; |
17
|
|
|
use Psr\Log\LoggerInterface; |
18
|
|
|
use Psr\Log\LoggerAwareInterface; |
19
|
|
|
use GuzzleHttp\ClientInterface; |
20
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Http\ApiClient; |
21
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Http\Authentication; |
22
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Exceptions\UnknownEndpoint; |
23
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Orders\Orders; |
24
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Services\Services; |
25
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Settings\Settings; |
26
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Documents\Documents; |
27
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Endpoints\PostOffices\PostOffices; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class DispatchingClient. |
31
|
|
|
* |
32
|
|
|
* @property-read Orders $orders |
33
|
|
|
* @property-read Documents $documents |
34
|
|
|
* @property-read Services $services |
35
|
|
|
* @property-read Settings $settings |
36
|
|
|
* @property-read PostOffices $postoffices |
37
|
|
|
*/ |
38
|
|
|
final class DispatchingClient implements LoggerAwareInterface |
39
|
|
|
{ |
40
|
|
|
private const ENDPOINTS = [ |
41
|
|
|
'orders' => Orders::class, |
42
|
|
|
'services' => Services::class, |
43
|
|
|
'settings' => Settings::class, |
44
|
|
|
'documents' => Documents::class, |
45
|
|
|
'postoffices' => PostOffices::class, |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
/** @var ApiClient */ |
49
|
|
|
private $client; |
50
|
|
|
|
51
|
3 |
|
public function __construct(string $login, string $password, string $token, ClientInterface $httpClient) |
52
|
|
|
{ |
53
|
3 |
|
$this->client = new ApiClient(new Authentication($login, $password, $token), $httpClient, new NullLogger()); |
54
|
3 |
|
} |
55
|
|
|
|
56
|
2 |
|
public function __get(string $property) |
57
|
|
|
{ |
58
|
2 |
|
if (isset(self::ENDPOINTS[$property])) { |
59
|
1 |
|
$class = self::ENDPOINTS[$property]; |
60
|
|
|
|
61
|
1 |
|
return new $class($this->client); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
throw new UnknownEndpoint($property); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
public function setLogger(LoggerInterface $logger) |
68
|
|
|
{ |
69
|
1 |
|
$this->client->setLogger($logger); |
70
|
1 |
|
} |
71
|
|
|
} |
72
|
|
|
|