7
7
use AlexGeno \PhoneVerification \Manager \Initiator ;
8
8
use AlexGeno \PhoneVerification \Sender \I as ISender ;
9
9
use AlexGeno \PhoneVerification \Storage \I as IStorage ;
10
+ use AlexGeno \PhoneVerification \Storage \MongoDb ;
11
+ use AlexGeno \PhoneVerification \Storage \Redis ;
10
12
use AlexGeno \PhoneVerificationLaravel \Commands \Complete ;
11
13
use AlexGeno \PhoneVerificationLaravel \Commands \Initiate ;
12
14
use AlexGeno \PhoneVerificationLaravel \Notifications \Otp ;
13
- use Illuminate \Support \Facades \DB ;
14
- use Illuminate \Support \Facades \Redis ;
15
+ use Illuminate \Contracts \Foundation \Application ;
15
16
use Illuminate \Support \ServiceProvider ;
16
17
17
18
class PhoneVerificationServiceProvider extends ServiceProvider
@@ -21,12 +22,12 @@ class PhoneVerificationServiceProvider extends ServiceProvider
21
22
*/
22
23
public function register ()
23
24
{
24
- $ this ->registerConfig ();
25
25
$ this ->registerStorage ();
26
26
$ this ->registerSender ();
27
27
$ this ->registerOtp ();
28
28
$ this ->registerManager ();
29
29
$ this ->registerPhoneVerification ();
30
+ $ this ->registerConfig ();
30
31
}
31
32
32
33
/**
@@ -36,7 +37,7 @@ public function register()
36
37
*/
37
38
protected function registerPhoneVerification ()
38
39
{
39
- $ this ->app ->singleton (PhoneVerification::class, function ($ container ) {
40
+ $ this ->app ->singleton (PhoneVerification::class, function (Application $ container ) {
40
41
return new PhoneVerification ();
41
42
});
42
43
}
@@ -45,30 +46,28 @@ protected function registerPhoneVerification()
45
46
* Return the Redis storage instance.
46
47
*
47
48
* @param array<mixed> $config ['settings' => [...], 'connection' => string]
48
- * @return \AlexGeno\PhoneVerification\Storage\Redis
49
49
*/
50
- protected function redisStorage (array $ config )
50
+ protected function redisStorage (array $ config ): Redis
51
51
{
52
- $ connection = Redis:: connection ($ config ['connection ' ]);
52
+ $ connection = $ this -> app -> make ( ' redis ' )-> connection ($ config ['connection ' ]);
53
53
54
- return new \ AlexGeno \ PhoneVerification \ Storage \ Redis ($ connection ->client (), $ config ['settings ' ]);
54
+ return new Redis ($ connection ->client (), $ config ['settings ' ]);
55
55
}
56
56
57
57
/**
58
58
* Return the Mongodb storage instance.
59
59
*
60
60
* @param array<mixed> $config ['settings' => [...], 'connection' => string]
61
- * @return \AlexGeno\PhoneVerification\Storage\MongoDb
62
61
*/
63
- protected function mongodbStorage (array $ config )
62
+ protected function mongodbStorage (array $ config ): MongoDb
64
63
{
65
64
/**
66
65
* @var \Jenssegers\Mongodb\Connection
67
66
*/
68
- $ connection = DB :: connection ($ config ['connection ' ]);
67
+ $ connection = $ this -> app -> make ( ' db ' )-> connection ($ config ['connection ' ]);
69
68
$ config ['settings ' ]['db ' ] = $ connection ->getDatabaseName ();
70
69
71
- return new \ AlexGeno \ PhoneVerification \ Storage \ MongoDb ($ connection ->getMongoClient (), $ config );
70
+ return new MongoDb ($ connection ->getMongoClient (), $ config );
72
71
}
73
72
74
73
/**
@@ -80,7 +79,7 @@ protected function mongodbStorage(array $config)
80
79
*/
81
80
protected function registerStorage ()
82
81
{
83
- $ this ->app ->bind (IStorage::class, function ($ container ) {
82
+ $ this ->app ->bind (IStorage::class, function (Application $ container ) {
84
83
$ config = config ('phone-verification.storage ' );
85
84
$ driver = $ config ['driver ' ];
86
85
$ method = $ driver .'Storage ' ;
@@ -104,7 +103,7 @@ protected function registerSender()
104
103
{
105
104
$ this ->app ->when (Sender::class)->needs ('$driver ' )->giveConfig ('phone-verification.sender.driver ' );
106
105
$ this ->app ->when (Sender::class)->needs ('$toLog ' )->giveConfig ('phone-verification.sender.to_log ' );
107
- $ this ->app ->bind (ISender::class, function ($ container ) {
106
+ $ this ->app ->bind (ISender::class, function (Application $ container ) {
108
107
return $ container ->make (Sender::class);
109
108
});
110
109
}
@@ -126,7 +125,7 @@ protected function registerOtp()
126
125
*
127
126
* @return array<mixed>
128
127
*/
129
- protected function managerConfig ()
128
+ protected function managerConfig (): array
130
129
{
131
130
$ config = config ('phone-verification.manager ' );
132
131
// load translated messages
@@ -152,12 +151,12 @@ protected function managerConfig()
152
151
protected function registerManager ()
153
152
{
154
153
// a sender and a storage for initiation process
155
- $ this ->app ->bind (Initiator::class, function ($ container ) {
154
+ $ this ->app ->bind (Initiator::class, function (Application $ container ) {
156
155
return (new Manager ($ container ->make (IStorage::class), $ this ->managerConfig ()))
157
156
->sender ($ container ->make (ISender::class));
158
157
});
159
158
// only a storage for completion process
160
- $ this ->app ->bind (Completer::class, function ($ container ) {
159
+ $ this ->app ->bind (Completer::class, function (Application $ container ) {
161
160
return new Manager ($ container ->make (IStorage::class), $ this ->managerConfig ());
162
161
});
163
162
}
0 commit comments