Skip to content

Commit

Permalink
[9.x] Add getIntendedUrl method to redirector (#43938)
Browse files Browse the repository at this point in the history
* [9.x] Add  method to redirector

* Update Redirector.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
iamgergo and taylorotwell authored Aug 31, 2022
1 parent 3f1b0a2 commit 7dd2905
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
36 changes: 23 additions & 13 deletions src/Illuminate/Routing/Redirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,6 @@ public function intended($default = '/', $status = 302, $headers = [], $secure =
return $this->to($path, $status, $headers, $secure);
}

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

return $this;
}

/**
* Create a new redirect response to the given path.
*
Expand Down Expand Up @@ -263,4 +250,27 @@ 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;
}
}
5 changes: 4 additions & 1 deletion tests/Routing/RoutingRedirectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,14 @@ public function testTemporarySignedRoute()
$this->assertSame('http://foo.com/bar?signature=secret', $response->getTargetUrl());
}

public function testItSetsValidIntendedUrl()
public function testItSetsAndGetsValidIntendedUrl()
{
$this->session->shouldReceive('put')->once()->with('url.intended', 'http://foo.com/bar');
$this->session->shouldReceive('get')->andReturn('http://foo.com/bar');

$result = $this->redirect->setIntendedUrl('http://foo.com/bar');
$this->assertInstanceOf(Redirector::class, $result);

$this->assertSame('http://foo.com/bar', $this->redirect->getIntendedUrl());
}
}

0 comments on commit 7dd2905

Please sign in to comment.