Test Failed
Push — master ( bd0a28...ba32c2 )
by Php Easy Api
05:04
created

ConfigProvider::provider()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Resta\Authenticate;
4
5
class ConfigProvider
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $driverDefaultNamespace = "\Resta\Authenticate\Driver";
11
12
    /**
13
     * @var string $store
14
     */
15
    protected $store = 'session';
16
17
    /**
18
     * @var null|mixed
19
     */
20
    protected $config;
21
22
    /**
23
     * @var string
24
     */
25
    protected $driver;
26
27
    /**
28
     * ConfigProvider constructor.
29
     */
30
    public function __construct()
31
    {
32
        $this->config();
33
34
        if($this->guard=="default"){
35
            $this->setAuthenticateNeeds();
36
        }
37
38
        $this->table();
39
40
        $this->deviceTokenTable();
41
    }
42
43
    /**
44
     * get authenticate config values
45
     *
46
     * @return void|mixed
47
     */
48
    public function config()
49
    {
50
        $this->config = config('authenticate');
51
52
        return $this->config;
53
    }
54
55
    /**
56
     * auth client query
57
     *
58
     * @return string
59
     */
60
    public function getAddToWhere()
61
    {
62
        if(isset($this->config['guard'][$this->guard]['addToWhere'])){
63
            return $this->config['guard'][$this->guard]['addToWhere'];
64
        }
65
        return null;
66
    }
67
68
    /**
69
     * get config token
70
     *
71
     * @return string
72
     */
73
    public function getConfigToken()
74
    {
75
        if(isset($this->config['guard'][$this->guard]['token'])){
76
            return $this->config['guard'][$this->guard]['token'];
77
        }
78
        return null;
79
    }
80
81
    /**
82
     * get credentials
83
     *
84
     * @return string
85
     */
86
    public function getCredentials()
87
    {
88
        return $this->config['guard'][$this->guard]['credentials'];
89
    }
90
91
    /**
92
     * get driver builder namespace
93
     *
94
     * @return string
95
     */
96
    public function getDriverBuilderNamespace()
97
    {
98
        return $this->driverDefaultNamespace.'\\'.$this->getDriver().'\\UserBuilder';
99
    }
100
101
    /**
102
     * get driver for authenticate
103
     *
104
     * @return string
105
     */
106
    public function getDriver()
107
    {
108
        return 'Eloquent';
109
    }
110
111
    /**
112
     * get driver namespace
113
     *
114
     * @return string
115
     */
116
    public function getDriverNamespace()
117
    {
118
        return $this->driverDefaultNamespace.'\\'.$this->getDriver().'\\User';
119
    }
120
121
    /**
122
     * get expire for authenticate
123
     *
124
     * @return mixed
125
     */
126
    public function getExpire()
127
    {
128
        return $this->config['guard'][$this->guard]['expire'];
129
    }
130
131
    /**
132
     * get http for authenticate
133
     *
134
     * @return string
135
     */
136
    public function getHttp()
137
    {
138
        return $this->config['guard'][$this->guard]['http'];
139
    }
140
141
    /**
142
     * get request for authenticate
143
     *
144
     * @return string
145
     */
146
    public function getRequest()
147
    {
148
        return ucfirst($this->config['guard'][$this->guard]['request']);
149
    }
150
151
    /**
152
     * get token key for authenticate
153
     *
154
     * @return string
155
     */
156
    public function getTokenKey()
157
    {
158
        return $this->config['guard'][$this->guard]['key'];
159
    }
160
161
    /**
162
     * get provider for authenticate
163
     *
164
     * @param $key
165
     * @return mixed|null
166
     */
167
    public function provider($key)
168
    {
169
        if(app()->has('authenticate.'.$key) && is_callable($provider = app()->get('authenticate.'.$key))){
170
            return $provider;
171
        }
172
173
        return null;
174
    }
175
176
    /**
177
     * set authenticate needs
178
     *
179
     * @return void|mixed
180
     */
181
    protected function setAuthenticateNeeds()
182
    {
183
        $this->getDriver();
184
    }
185
186
    /**
187
     * store for authenticate
188
     *
189
     * @param $store
190
     * @return $this
191
     */
192
    public function store($store)
193
    {
194
        $this->store = $store;
195
196
        return $this;
197
    }
198
199
    /**
200
     * table name for authenticate
201
     *
202
     * @return string
203
     */
204
    public function table()
205
    {
206
        $table = $this->config['guard'][$this->guard]['table'];
207
208
        app()->register('authenticateTable',$table);
209
    }
210
211
    /**
212
     * table name for authenticate
213
     *
214
     * @return string
215
     */
216
    public function deviceTokenTable()
217
    {
218
        if(isset($this->config['guard'][$this->guard]['deviceTokenRegister'])){
219
            $table = $this->config['guard'][$this->guard]['deviceTokenRegister'];
220
221
            app()->register('authenticateDeviceTokenTable',$table);
222
        }
223
        else{
224
            app()->register('authenticateDeviceTokenTable','device_tokens');
225
        }
226
227
    }
228
229
}