1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of RussianPost SDK package. |
5
|
|
|
* |
6
|
|
|
* © Appwilio (http://appwilio.com), greabock (https://github.com/greabock), 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; |
15
|
|
|
|
16
|
|
|
use Psr\Log\LoggerAwareInterface; |
17
|
|
|
use GuzzleHttp\Client as GuzzleClient; |
18
|
|
|
use Illuminate\Support\ServiceProvider; |
19
|
|
|
use Illuminate\Contracts\Container\Container; |
20
|
|
|
use Illuminate\Contracts\Support\DeferrableProvider; |
21
|
|
|
use Appwilio\RussianPostSDK\Tracking\PacketAccessClient; |
22
|
|
|
use Appwilio\RussianPostSDK\Tracking\SingleAccessClient; |
23
|
|
|
use Appwilio\RussianPostSDK\Dispatching\DispatchingClient; |
24
|
|
|
|
25
|
|
|
class LaravelServiceProvider extends ServiceProvider implements DeferrableProvider |
26
|
|
|
{ |
27
|
1 |
|
public function register(): void |
28
|
|
|
{ |
29
|
|
|
$this->app->singleton(SingleAccessClient::class, function (Container $app) { |
30
|
|
|
$config = $app['config']['services.russianpost.tracking']; |
31
|
|
|
|
32
|
|
|
return $this->setLoggerToClient( |
33
|
|
|
new SingleAccessClient($config['login'], $config['password']) |
34
|
|
|
); |
35
|
1 |
|
}); |
36
|
|
|
|
37
|
|
|
$this->app->singleton(PacketAccessClient::class, function (Container $app) { |
38
|
|
|
$config = $app['config']['services.russianpost.tracking']; |
39
|
|
|
|
40
|
|
|
return $this->setLoggerToClient( |
41
|
|
|
new PacketAccessClient($config['login'], $config['password']) |
42
|
|
|
); |
43
|
1 |
|
}); |
44
|
|
|
|
45
|
|
|
$this->app->singleton(DispatchingClient::class, function (Container $app) { |
46
|
|
|
$config = $app['config']['services.russianpost.dispatching']; |
47
|
|
|
|
48
|
|
|
$client = new DispatchingClient( |
49
|
|
|
$config['login'], $config['password'], $config['token'], new GuzzleClient($config['guzzle'] ?? []) |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
return $this->setLoggerToClient($client); |
53
|
1 |
|
}); |
54
|
1 |
|
} |
55
|
|
|
|
56
|
1 |
|
public function provides(): array |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
1 |
|
DispatchingClient::class, |
60
|
|
|
SingleAccessClient::class, |
61
|
|
|
PacketAccessClient::class, |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function setLoggerToClient(LoggerAwareInterface $client) |
66
|
|
|
{ |
67
|
|
|
if ($this->app->bound('appwilio.russianpost.logger')) { |
68
|
|
|
$client->setLogger($this->app['appwilio.russianpost.logger']); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $client; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|