Test Setup Failed
Push — master ( 2de497...80630f )
by Php Easy Api
03:45
created

ConfigProvider   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 221
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 221
rs 10
c 0
b 0
f 0
wmc 23

16 Methods

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