123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
-
- namespace Illuminate\Auth;
-
- use Illuminate\Contracts\Auth\UserProvider;
- use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
-
- /**
- * These methods are typically the same across all guards.
- */
- trait GuardHelpers
- {
- /**
- * The currently authenticated user.
- *
- * @var \Illuminate\Contracts\Auth\Authenticatable
- */
- protected $user;
-
- /**
- * The user provider implementation.
- *
- * @var \Illuminate\Contracts\Auth\UserProvider
- */
- protected $provider;
-
- /**
- * Determine if the current user is authenticated.
- *
- * @return \Illuminate\Contracts\Auth\Authenticatable
- *
- * @throws \Illuminate\Auth\AuthenticationException
- */
- public function authenticate()
- {
- if (! is_null($user = $this->user())) {
- return $user;
- }
-
- throw new AuthenticationException;
- }
-
- /**
- * Determine if the guard has a user instance.
- *
- * @return bool
- */
- public function hasUser()
- {
- return ! is_null($this->user);
- }
-
- /**
- * Determine if the current user is authenticated.
- *
- * @return bool
- */
- public function check()
- {
- return ! is_null($this->user());
- }
-
- /**
- * Determine if the current user is a guest.
- *
- * @return bool
- */
- public function guest()
- {
- return ! $this->check();
- }
-
- /**
- * Get the ID for the currently authenticated user.
- *
- * @return int|null
- */
- public function id()
- {
- if ($this->user()) {
- return $this->user()->getAuthIdentifier();
- }
- }
-
- /**
- * Set the current user.
- *
- * @param \Illuminate\Contracts\Auth\Authenticatable $user
- * @return $this
- */
- public function setUser(AuthenticatableContract $user)
- {
- $this->user = $user;
-
- return $this;
- }
-
- /**
- * Get the user provider used by the guard.
- *
- * @return \Illuminate\Contracts\Auth\UserProvider
- */
- public function getProvider()
- {
- return $this->provider;
- }
-
- /**
- * Set the user provider used by the guard.
- *
- * @param \Illuminate\Contracts\Auth\UserProvider $provider
- * @return void
- */
- public function setProvider(UserProvider $provider)
- {
- $this->provider = $provider;
- }
- }
|