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 Appwilio\RussianPostSDK\Tracking\PacketAccessClient; |
21
|
|
|
use Appwilio\RussianPostSDK\Tracking\SingleAccessClient; |
22
|
|
|
use Appwilio\RussianPostSDK\Dispatching\DispatchingClient; |
23
|
|
|
|
24
|
|
|
class LaravelServiceProvider extends ServiceProvider |
25
|
|
|
{ |
26
|
|
|
protected $defer = true; |
27
|
|
|
|
28
|
1 |
|
public function register() |
29
|
|
|
{ |
30
|
|
|
$this->app->singleton(SingleAccessClient::class, static function (Container $app) { |
31
|
|
|
$config = $app['config']['services.russianpost.tracking']; |
32
|
|
|
|
33
|
|
|
return $this->setLoggerToClient( |
|
|
|
|
34
|
|
|
new SingleAccessClient($config['login'], $config['password']) |
35
|
|
|
); |
36
|
1 |
|
}); |
37
|
|
|
|
38
|
|
|
$this->app->singleton(PacketAccessClient::class, static function (Container $app) { |
39
|
|
|
$config = $app['config']['services.russianpost.tracking']; |
40
|
|
|
|
41
|
|
|
return $this->setLoggerToClient( |
|
|
|
|
42
|
|
|
new PacketAccessClient($config['login'], $config['password']) |
43
|
|
|
); |
44
|
1 |
|
}); |
45
|
|
|
|
46
|
|
|
$this->app->singleton(DispatchingClient::class, static function (Container $app) { |
47
|
|
|
$config = $app['config']['services.russianpost.dispatching']; |
48
|
|
|
|
49
|
|
|
$client = new DispatchingClient( |
50
|
|
|
$config['login'], $config['password'], $config['token'], new GuzzleClient() |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$this->setLoggerToClient($client); |
54
|
|
|
|
55
|
|
|
return $client; |
56
|
1 |
|
}); |
57
|
1 |
|
} |
58
|
|
|
|
59
|
1 |
|
public function provides(): array |
60
|
|
|
{ |
61
|
|
|
return [ |
62
|
1 |
|
DispatchingClient::class, |
63
|
|
|
SingleAccessClient::class, |
64
|
|
|
PacketAccessClient::class, |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function setLoggerToClient(LoggerAwareInterface $client) |
69
|
|
|
{ |
70
|
|
|
if ($this->app->bound('appwilio.russianpost.logger')) { |
71
|
|
|
$client->setLogger($this->app['appwilio.russianpost.logger']); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.