Test Setup Failed
Push — master ( 373408...f0f097 )
by Php Easy Api
03:20
created

AuthenticateProvider::getTokenSentByUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Resta\Authenticate;
4
5
use Resta\Authenticate\Resource\AuthCheckManager;
6
use Resta\Authenticate\Resource\AuthLoginManager;
7
use Resta\Authenticate\Resource\AuthLogoutManager;
8
9
class AuthenticateProvider extends ConfigProvider implements AuthenticateContract
10
{
11
    //get auth response,auth exception,auth token and auth basic
12
    use AuthenticateResponse,AuthenticateException,AuthenticateToken,AuthenticateBasic;
0 ignored issues
show
Bug introduced by
The trait Resta\Authenticate\AuthenticateToken requires the property $id which is not provided by Resta\Authenticate\AuthenticateProvider.
Loading history...
13
14
    /**
15
     * @var string
16
     */
17
    protected $guard = 'default';
18
19
    /**
20
     * check if the authenticated of user
21
     *
22
     * @return bool
23
     */
24
    public function check()
25
    {
26
        // header to determine whether
27
        // the token value is present and return a callback.
28
        return $this->checkTokenViaHeaders(function($token){
29
30
            // we send the user-supplied token value
31
            // to the authCheckManager object.
32
            new AuthCheckManager($this,$token);
33
34
            // as a result we send output according to
35
            // the boolean value from the checkResult method.
36
            return $this->getCheckResult();
37
        });
38
    }
39
40
    /**
41
     * authenticate guard adapter
42
     *
43
     * @param $guard
44
     * @return $this|mixed
45
     *
46
     */
47
    public function guard($guard)
48
    {
49
        $this->guard=$guard;
50
51
        $this->setAuthenticateNeeds();
52
53
        return $this;
54
    }
55
56
    /**
57
     * get id for the authenticated user
58
     *
59
     * @return bool
60
     */
61
    public function id()
62
    {
63
        // we obtain the id value obtained via
64
        // authenticate availability with the help of callback object.
65
        return $this->checkParamsViaAvailability('authId',function($id){
66
            return $id;
67
        });
68
    }
69
70
    /**
71
     * login for authenticate
72
     *
73
     * @param null|array $credentials
74
     * @param bool $objectReturn
75
     * @return $this|mixed
76
     */
77
    public function login($credentials=null,$objectReturn=false)
78
    {
79
        // we will determine whether
80
        // the http path is correct for this method.
81
        $this->checkProcessHttpMethod('login');
82
83
        // we invoke the login manager and the properties
84
        // that this class creates will inform us about user input.
85
        $loginManager = new AuthLoginManager($credentials,$this);
86
87
        // if you want to see the entire login manager object directly,
88
        // send true to the objectReturn parameter.
89
        if($objectReturn) return $loginManager;
90
91
        // the login value stored in the params property of the login manager object will return a builder object.
92
        // we will return the value of the login state as a boolean using the count method of this builder object.
93
        if($this->getModel()=="Default"){
94
            return $this->getResult();
95
        }
96
97
        return $loginManager->loginProcess();
98
99
    }
100
101
    /**
102
     * logout the authenticated user
103
     *
104
     * @return mixed|void
105
     */
106
    public function logout()
107
    {
108
        // we will determine whether
109
        // the http path is correct for this method.
110
        $this->checkProcessHttpMethod('logout');
111
112
        // header to determine whether
113
        // the token value is present and return a callback.
114
        return $this->checkTokenViaHeaders(function($token){
115
116
            // we send the user-supplied token value
117
            // to the authCheckManager object.
118
            new AuthLogoutManager($this,$token);
119
120
            // as a result we send output according to
121
            // the boolean value from the checkResult method.
122
            return $this->getLogoutResult();
123
        });
124
    }
125
126
    /**
127
     * get token the authanticated user
128
     *
129
     * @return bool
130
     */
131
    public function token()
132
    {
133
        // we obtain the token value obtained via
134
        // authenticate availability with the help of callback object.
135
        return $this->checkParamsViaAvailability('authToken',function($token){
136
            return $token;
137
        });
138
    }
139
140
    /**
141
     * get if exist the authenticated user
142
     *
143
     * @return bool
144
     */
145
    public function user()
146
    {
147
        // we obtain the user value obtained via
148
        // authenticate availability with the help of callback object.
149
        return $this->checkParamsViaAvailability('auth',function($user){
150
            return $user;
151
        });
152
    }
153
154
    /**
155
     * get user information the authenticated user
156
     *
157
     * @return bool
158
     */
159
    public function userData()
160
    {
161
        // we obtain the data value obtained via
162
        // authenticate availability with the help of callback object.
163
        return $this->checkParamsViaAvailability('data',function($data){
164
            return $data;
165
        });
166
    }
167
168
    /**
169
     * get token sent by user
170
     *
171
     * @return null|string
172
     */
173
    public function getTokenSentByUser()
174
    {
175
        //get headers
176
        $headers = headers();
177
178
        //get token key from config
179
        $tokenKey = $this->getTokenKey();
180
181
        return (isset($headers[$tokenKey])) ? $headers[$tokenKey][0] : null;
182
    }
183
}
184