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

namespace IlluminateRouting;

use 
IlluminateHttpRedirectResponse;
use 
IlluminateSessionStore as SessionStore;
use 
IlluminateSupportTraitsMacroable;

class 
Redirector
{
    use 
Macroable;

    
/**
     * The URL generator instance.
     *
     * @var IlluminateRoutingUrlGenerator
     */
    
protected $generator;

    
/**
     * The session store instance.
     *
     * @var IlluminateSessionStore
     */
    
protected $session;

    
/**
     * Create a new Redirector instance.
     *
     * @param  IlluminateRoutingUrlGenerator  $generator
     * @return void
     */
    
public function __construct(UrlGenerator $generator)
    {
        
$this->generator $generator;
    }

    
/**
     * Create a new redirect response to the previous location.
     *
     * @param  int  $status
     * @param  array  $headers
     * @param  mixed  $fallback
     * @return IlluminateHttpRedirectResponse
     */
    
public function back($status 302$headers = [], $fallback false)
    {
        return 
$this->createRedirect($this->generator->previous($fallback), $status$headers);
    }

    
/**
     * Create a new redirect response to the current URI.
     *
     * @param  int  $status
     * @param  array  $headers
     * @return IlluminateHttpRedirectResponse
     */
    
public function refresh($status 302$headers = [])
    {
        return 
$this->to($this->generator->getRequest()->path(), $status$headers);
    }

    
/**
     * Create a new redirect response, while putting the current URL in the session.
     *
     * @param  string  $path
     * @param  int  $status
     * @param  array  $headers
     * @param  bool|null  $secure
     * @return IlluminateHttpRedirectResponse
     */
    
public function guest($path$status 302$headers = [], $secure null)
    {
        
$request $this->generator->getRequest();

        
$intended $request->isMethod('GET') && $request->route() && ! $request->expectsJson()
                        ? 
$this->generator->full()
                        : 
$this->generator->previous();

        if (
$intended) {
            
$this->setIntendedUrl($intended);
        }

        return 
$this->to($path$status$headers$secure);
    }

    
/**
     * Create a new redirect response to the previously intended location.
     *
     * @param  mixed  $default
     * @param  int  $status
     * @param  array  $headers
     * @param  bool|null  $secure
     * @return IlluminateHttpRedirectResponse
     */
    
public function intended($default '/'$status 302$headers = [], $secure null)
    {
        
$path $this->session->pull('url.intended'$default);

        return 
$this->to($path$status$headers$secure);
    }

    
/**
     * Create a new redirect response to the given path.
     *
     * @param  string  $path
     * @param  int  $status
     * @param  array  $headers
     * @param  bool|null  $secure
     * @return IlluminateHttpRedirectResponse
     */
    
public function to($path$status 302$headers = [], $secure null)
    {
        return 
$this->createRedirect($this->generator->to($path, [], $secure), $status$headers);
    }

    
/**
     * Create a new redirect response to an external URL (no validation).
     *
     * @param  string  $path
     * @param  int  $status
     * @param  array  $headers
     * @return IlluminateHttpRedirectResponse
     */
    
public function away($path$status 302$headers = [])
    {
        return 
$this->createRedirect($path$status$headers);
    }

    
/**
     * Create a new redirect response to the given HTTPS path.
     *
     * @param  string  $path
     * @param  int  $status
     * @param  array  $headers
     * @return IlluminateHttpRedirectResponse
     */
    
public function secure($path$status 302$headers = [])
    {
        return 
$this->to($path$status$headerstrue);
    }

    
/**
     * Create a new redirect response to a named route.
     *
     * @param  string  $route
     * @param  mixed  $parameters
     * @param  int  $status
     * @param  array  $headers
     * @return IlluminateHttpRedirectResponse
     */
    
public function route($route$parameters = [], $status 302$headers = [])
    {
        return 
$this->to($this->generator->route($route$parameters), $status$headers);
    }

    
/**
     * Create a new redirect response to a signed named route.
     *
     * @param  string  $route
     * @param  mixed  $parameters
     * @param  DateTimeInterface|DateInterval|int|null  $expiration
     * @param  int  $status
     * @param  array  $headers
     * @return IlluminateHttpRedirectResponse
     */
    
public function signedRoute($route$parameters = [], $expiration null$status 302$headers = [])
    {
        return 
$this->to($this->generator->signedRoute($route$parameters$expiration), $status$headers);
    }

    
/**
     * Create a new redirect response to a signed named route.
     *
     * @param  string  $route
     * @param  DateTimeInterface|DateInterval|int|null  $expiration
     * @param  mixed  $parameters
     * @param  int  $status
     * @param  array  $headers
     * @return IlluminateHttpRedirectResponse
     */
    
public function temporarySignedRoute($route$expiration$parameters = [], $status 302$headers = [])
    {
        return 
$this->to($this->generator->temporarySignedRoute($route$expiration$parameters), $status$headers);
    }

    
/**
     * Create a new redirect response to a controller action.
     *
     * @param  string|array  $action
     * @param  mixed  $parameters
     * @param  int  $status
     * @param  array  $headers
     * @return IlluminateHttpRedirectResponse
     */
    
public function action($action$parameters = [], $status 302$headers = [])
    {
        return 
$this->to($this->generator->action($action$parameters), $status$headers);
    }

    
/**
     * Create a new redirect response.
     *
     * @param  string  $path
     * @param  int  $status
     * @param  array  $headers
     * @return IlluminateHttpRedirectResponse
     */
    
protected function createRedirect($path$status$headers)
    {
        return 
tap(new RedirectResponse($path$status$headers), function ($redirect) {
            if (isset(
$this->session)) {
                
$redirect->setSession($this->session);
            }

            
$redirect->setRequest($this->generator->getRequest());
        });
    }

    
/**
     * Get the URL generator instance.
     *
     * @return IlluminateRoutingUrlGenerator
     */
    
public function getUrlGenerator()
    {
        return 
$this->generator;
    }

    
/**
     * Set the active session store.
     *
     * @param  IlluminateSessionStore  $session
     * @return void
     */
    
public function setSession(SessionStore $session)
    {
        
$this->session $session;
    }

    
/**
     * Get the "intended" URL from the session.
     *
     * @return string|null
     */
    
public function getIntendedUrl()
    {
        return 
$this->session->get('url.intended');
    }

    
/**
     * Set the "intended" URL in the session.
     *
     * @param  string  $url
     * @return $this
     */
    
public function setIntendedUrl($url)
    {
        
$this->session->put('url.intended'$url);

        return 
$this;
    }
}
Онлайн: 0
Реклама