|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Part of the Saudi Address API PHP package. |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the MIT. |
|
9
|
|
|
* |
|
10
|
|
|
* This source file is subject to the MIT License that is |
|
11
|
|
|
* bundled with this package in the LICENSE file. |
|
12
|
|
|
* |
|
13
|
|
|
* @package Saudi Address |
|
14
|
|
|
* @version 1.3 |
|
15
|
|
|
* @author Ali Alharthi |
|
16
|
|
|
* @license MIT |
|
17
|
|
|
* @copyright (c) 2020, Ali Alharthi |
|
18
|
|
|
* @link https://aalharthi.sa |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AliAlharthi\SaudiAddress\Providers; |
|
22
|
|
|
|
|
23
|
|
|
use AliAlharthi\SaudiAddress\Config; |
|
24
|
|
|
use AliAlharthi\SaudiAddress\SaudiAddress; |
|
25
|
|
|
use AliAlharthi\SaudiAddress\ConfigInterface; |
|
26
|
|
|
use Illuminate\Support\ServiceProvider; |
|
27
|
|
|
|
|
28
|
|
|
class SaudiAddressServiceProvider extends ServiceProvider |
|
29
|
|
|
{ |
|
30
|
|
|
public function register() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->registerSaudiAddress(); |
|
33
|
|
|
$this->registerConfig(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function provides() |
|
37
|
|
|
{ |
|
38
|
|
|
return [ |
|
39
|
|
|
'saudiaddress', |
|
40
|
|
|
'saudiaddress.config', |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Register the Saudi National Address API class. |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function registerSaudiAddress() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->app->singleton('saudiaddress', function ($app) { |
|
52
|
|
|
$config = $app['config']->get('services.saudiaddress'); |
|
53
|
|
|
|
|
54
|
|
|
$apiKey = $config['api_key'] ?? null; |
|
55
|
|
|
|
|
56
|
|
|
$apiSubscription = $config['api_subscription'] ?? null; |
|
57
|
|
|
|
|
58
|
|
|
$cache = $config['cache'] ?? null; |
|
59
|
|
|
|
|
60
|
|
|
return new SaudiAddress($apiKey, $apiSubscription, $cache); |
|
61
|
|
|
}); |
|
62
|
|
|
|
|
63
|
|
|
$this->app->alias('saudiaddress', SaudiAddress::class); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Register the config class. |
|
68
|
|
|
* |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function registerConfig() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->app->singleton('saudiaddress.config', function ($app) { |
|
74
|
|
|
return $app['saudiaddress']->getConfig(); |
|
75
|
|
|
}); |
|
76
|
|
|
|
|
77
|
|
|
$this->app->alias('saudiaddress.config', Config::class); |
|
78
|
|
|
|
|
79
|
|
|
$this->app->alias('saudiaddress.config', ConfigInterface::class); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|