|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TarfinLabs\Parasut; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
use TarfinLabs\Parasut\API\ClientGateway; |
|
7
|
|
|
use TarfinLabs\Parasut\API\HttpClientGateway; |
|
8
|
|
|
|
|
9
|
|
|
class ParasutServiceProvider extends ServiceProvider |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Bootstrap the application services. |
|
13
|
|
|
*/ |
|
14
|
11 |
|
public function boot(): void |
|
15
|
|
|
{ |
|
16
|
11 |
|
if ($this->app->runningInConsole()) { |
|
17
|
11 |
|
$this->publishConfigs(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
11 |
|
$this->loadFactories(); |
|
21
|
11 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Register the application services. |
|
25
|
|
|
*/ |
|
26
|
11 |
|
public function register(): void |
|
27
|
|
|
{ |
|
28
|
11 |
|
$this->mergeConfigs(); |
|
29
|
|
|
|
|
30
|
|
|
// Register the main class to use with the facade |
|
31
|
11 |
|
$this->app->singleton(ClientGateway::class, fn () => new HttpClientGateway( |
|
32
|
11 |
|
config('parasut.grant_type'), |
|
33
|
11 |
|
config('parasut.client_id'), |
|
34
|
11 |
|
config('parasut.client_secret'), |
|
35
|
11 |
|
config('parasut.username'), |
|
36
|
11 |
|
config('parasut.password'), |
|
37
|
11 |
|
config('parasut.redirect_uri'), |
|
38
|
11 |
|
)); |
|
39
|
11 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Merge the configs. |
|
43
|
|
|
*/ |
|
44
|
11 |
|
protected function mergeConfigs(): void |
|
45
|
|
|
{ |
|
46
|
|
|
// Automatically apply the package configuration |
|
47
|
11 |
|
$this->mergeConfigFrom(__DIR__.'/../config/parasut.php', 'parasut'); |
|
48
|
11 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Publish the configs. |
|
52
|
|
|
*/ |
|
53
|
11 |
|
protected function publishConfigs(): void |
|
54
|
|
|
{ |
|
55
|
11 |
|
$this->publishes([ |
|
56
|
11 |
|
__DIR__.'/../config/parasut.php' => config_path('parasut.php'), |
|
57
|
11 |
|
], 'parasut-config'); |
|
58
|
11 |
|
} |
|
59
|
|
|
|
|
60
|
11 |
|
protected function loadFactories(): void |
|
61
|
|
|
{ |
|
62
|
11 |
|
$this->loadFactoriesFrom(__DIR__.'/Factories'); |
|
63
|
11 |
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|