Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php
Строк: 116
<?php

namespace IlluminateAuthMiddleware;

use 
Closure;
use 
IlluminateAuthAuthenticationException;
use 
IlluminateContractsAuthFactory as Auth;
use 
IlluminateContractsAuthMiddlewareAuthenticatesRequests;
use 
IlluminateHttpRequest;

class 
Authenticate implements AuthenticatesRequests
{
    
/**
     * The authentication factory instance.
     *
     * @var IlluminateContractsAuthFactory
     */
    
protected $auth;

    
/**
     * The callback that should be used to generate the authentication redirect path.
     *
     * @var callable
     */
    
protected static $redirectToCallback;

    
/**
     * Create a new middleware instance.
     *
     * @param  IlluminateContractsAuthFactory  $auth
     */
    
public function __construct(Auth $auth)
    {
        
$this->auth $auth;
    }

    
/**
     * Specify the guards for the middleware.
     *
     * @param  string  $guard
     * @param  string  $others
     * @return string
     */
    
public static function using($guard, ...$others)
    {
        return static::class.
':'.implode(',', [$guard, ...$others]);
    }

    
/**
     * Handle an incoming request.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  Closure  $next
     * @param  string  ...$guards
     * @return mixed
     *
     * @throws IlluminateAuthAuthenticationException
     */
    
public function handle($requestClosure $next, ...$guards)
    {
        
$this->authenticate($request$guards);

        return 
$next($request);
    }

    
/**
     * Determine if the user is logged in to any of the given guards.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  array  $guards
     * @return void
     *
     * @throws IlluminateAuthAuthenticationException
     */
    
protected function authenticate($request, array $guards)
    {
        if (empty(
$guards)) {
            
$guards = [null];
        }

        foreach (
$guards as $guard) {
            if (
$this->auth->guard($guard)->check()) {
                return 
$this->auth->shouldUse($guard);
            }
        }

        
$this->unauthenticated($request$guards);
    }

    
/**
     * Handle an unauthenticated user.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  array  $guards
     * @return never
     *
     * @throws IlluminateAuthAuthenticationException
     */
    
protected function unauthenticated($request, array $guards)
    {
        throw new 
AuthenticationException(
            
'Unauthenticated.',
            
$guards,
            
$request->expectsJson() ? null $this->redirectTo($request),
        );
    }

    
/**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  IlluminateHttpRequest  $request
     * @return string|null
     */
    
protected function redirectTo(Request $request)
    {
        if (static::
$redirectToCallback) {
            return 
call_user_func(static::$redirectToCallback$request);
        }
    }

    
/**
     * Specify the callback that should be used to generate the redirect path.
     *
     * @param  callable  $redirectToCallback
     * @return void
     */
    
public static function redirectUsing(callable $redirectToCallback)
    {
        static::
$redirectToCallback $redirectToCallback;
    }
}
Онлайн: 2
Реклама