1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mvdnbrk\Laravel; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Support\DeferrableProvider; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Mvdnbrk\DhlParcel\Client; |
8
|
|
|
|
9
|
|
|
class DhlParcelServiceProvider extends ServiceProvider implements DeferrableProvider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Register the application services. |
13
|
|
|
* |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
12 |
|
public function register() |
17
|
|
|
{ |
18
|
12 |
|
$this->mergeConfigFrom(__DIR__.'/../config/dhlparcel.php', 'dhlparcel'); |
19
|
|
|
|
20
|
12 |
|
$this->registerDhlClient(); |
21
|
12 |
|
$this->registerDhlAdapter(); |
22
|
|
|
|
23
|
12 |
|
$this->registerPublishing(); |
24
|
12 |
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Register the DHL Parcel Client. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
12 |
|
protected function registerDhlClient() |
32
|
|
|
{ |
33
|
|
|
$this->app->singleton(Client::class, function () { |
34
|
12 |
|
return (new Client)->setUserId(config('dhlparcel.id'))->setApiKey(config('dhlparcel.secret')); |
35
|
12 |
|
}); |
36
|
|
|
|
37
|
12 |
|
$this->app->alias(Client::class, 'dhlparcel'); |
38
|
12 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Register the DHL Parcel Client Adapter. |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
12 |
|
protected function registerDhlAdapter() |
46
|
|
|
{ |
47
|
|
|
$this->app->singleton(DhlParcelClientAdapter::class, function () { |
48
|
8 |
|
return new DhlParcelClientAdapter(app('dhlparcel')); |
|
|
|
|
49
|
12 |
|
}); |
50
|
|
|
|
51
|
12 |
|
$this->app->alias(DhlParcelClientAdapter::class, 'dhlparcel.adapter'); |
52
|
12 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Register the package's publishable resources. |
56
|
|
|
* |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
12 |
|
protected function registerPublishing() |
60
|
|
|
{ |
61
|
12 |
|
if ($this->app->runningInConsole()) { |
62
|
12 |
|
$this->publishes([ |
63
|
12 |
|
__DIR__.'/../config/dhlparcel.php' => config_path('dhlparcel.php'), |
64
|
12 |
|
], 'dhlparcel-config'); |
65
|
|
|
} |
66
|
12 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the services provided by the provider. |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
4 |
|
public function provides() |
74
|
|
|
{ |
75
|
|
|
return [ |
76
|
4 |
|
'dhlparcel', |
77
|
|
|
'dhlparcel.adapter', |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|