Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Auth;
4
 
5
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
6
use Illuminate\Contracts\Auth\UserProvider;
7
 
8
/**
9
 * These methods are typically the same across all guards.
10
 */
11
trait GuardHelpers
12
{
13
    /**
14
     * The currently authenticated user.
15
     *
16
     * @var \Illuminate\Contracts\Auth\Authenticatable
17
     */
18
    protected $user;
19
 
20
    /**
21
     * The user provider implementation.
22
     *
23
     * @var \Illuminate\Contracts\Auth\UserProvider
24
     */
25
    protected $provider;
26
 
27
    /**
28
     * Determine if the current user is authenticated. If not, throw an exception.
29
     *
30
     * @return \Illuminate\Contracts\Auth\Authenticatable
31
     *
32
     * @throws \Illuminate\Auth\AuthenticationException
33
     */
34
    public function authenticate()
35
    {
36
        if (! is_null($user = $this->user())) {
37
            return $user;
38
        }
39
 
40
        throw new AuthenticationException;
41
    }
42
 
43
    /**
44
     * Determine if the guard has a user instance.
45
     *
46
     * @return bool
47
     */
48
    public function hasUser()
49
    {
50
        return ! is_null($this->user);
51
    }
52
 
53
    /**
54
     * Determine if the current user is authenticated.
55
     *
56
     * @return bool
57
     */
58
    public function check()
59
    {
60
        return ! is_null($this->user());
61
    }
62
 
63
    /**
64
     * Determine if the current user is a guest.
65
     *
66
     * @return bool
67
     */
68
    public function guest()
69
    {
70
        return ! $this->check();
71
    }
72
 
73
    /**
74
     * Get the ID for the currently authenticated user.
75
     *
76
     * @return int|string|null
77
     */
78
    public function id()
79
    {
80
        if ($this->user()) {
81
            return $this->user()->getAuthIdentifier();
82
        }
83
    }
84
 
85
    /**
86
     * Set the current user.
87
     *
88
     * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
89
     * @return $this
90
     */
91
    public function setUser(AuthenticatableContract $user)
92
    {
93
        $this->user = $user;
94
 
95
        return $this;
96
    }
97
 
98
    /**
99
     * Forget the current user.
100
     *
101
     * @return $this
102
     */
103
    public function forgetUser()
104
    {
105
        $this->user = null;
106
 
107
        return $this;
108
    }
109
 
110
    /**
111
     * Get the user provider used by the guard.
112
     *
113
     * @return \Illuminate\Contracts\Auth\UserProvider
114
     */
115
    public function getProvider()
116
    {
117
        return $this->provider;
118
    }
119
 
120
    /**
121
     * Set the user provider used by the guard.
122
     *
123
     * @param  \Illuminate\Contracts\Auth\UserProvider  $provider
124
     * @return void
125
     */
126
    public function setProvider(UserProvider $provider)
127
    {
128
        $this->provider = $provider;
129
    }
130
}