githubtrue/backend/vendor/illuminate/auth/GuardHelpers.php @ cb15593b
1 |
<?php
|
---|---|
2 |
|
3 |
namespace Illuminate\Auth; |
4 |
|
5 |
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
6 |
|
7 |
/**
|
8 |
* These methods are typically the same across all guards.
|
9 |
*/
|
10 |
trait GuardHelpers |
11 |
{
|
12 |
/**
|
13 |
* The currently authenticated user.
|
14 |
*
|
15 |
* @var \Illuminate\Contracts\Auth\Authenticatable
|
16 |
*/
|
17 |
protected $user; |
18 |
|
19 |
/**
|
20 |
* The user provider implementation.
|
21 |
*
|
22 |
* @var \Illuminate\Contracts\Auth\UserProvider
|
23 |
*/
|
24 |
protected $provider; |
25 |
|
26 |
/**
|
27 |
* Determine if the current user is authenticated.
|
28 |
*
|
29 |
* @return \Illuminate\Contracts\Auth\Authenticatable
|
30 |
*
|
31 |
* @throws \Illuminate\Auth\AuthenticationException
|
32 |
*/
|
33 |
public function authenticate() |
34 |
{
|
35 |
if (! is_null($user = $this->user())) { |
36 |
return $user; |
37 |
}
|
38 |
|
39 |
throw new AuthenticationException($this); |
40 |
}
|
41 |
|
42 |
/**
|
43 |
* Determine if the current user is authenticated.
|
44 |
*
|
45 |
* @return bool
|
46 |
*/
|
47 |
public function check() |
48 |
{
|
49 |
return ! is_null($this->user()); |
50 |
}
|
51 |
|
52 |
/**
|
53 |
* Determine if the current user is a guest.
|
54 |
*
|
55 |
* @return bool
|
56 |
*/
|
57 |
public function guest() |
58 |
{
|
59 |
return ! $this->check(); |
60 |
}
|
61 |
|
62 |
/**
|
63 |
* Get the ID for the currently authenticated user.
|
64 |
*
|
65 |
* @return int|null
|
66 |
*/
|
67 |
public function id() |
68 |
{
|
69 |
if ($this->user()) { |
70 |
return $this->user()->getAuthIdentifier(); |
71 |
}
|
72 |
}
|
73 |
|
74 |
/**
|
75 |
* Set the current user.
|
76 |
*
|
77 |
* @param \Illuminate\Contracts\Auth\Authenticatable $user
|
78 |
* @return $this
|
79 |
*/
|
80 |
public function setUser(AuthenticatableContract $user) |
81 |
{
|
82 |
$this->user = $user; |
83 |
|
84 |
return $this; |
85 |
}
|
86 |
}
|