Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f321c80

Browse filesBrowse files
committed
[BrowserKit] Emulate back/forward browser navigation
1 parent 549af73 commit f321c80
Copy full SHA for f321c80

File tree

1 file changed

+24
-2
lines changed
Filter options

1 file changed

+24
-2
lines changed

‎src/Symfony/Component/BrowserKit/Client.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/Client.php
+24-2Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ abstract class Client
3838
protected $crawler;
3939
protected $insulated = false;
4040
protected $redirect;
41+
protected $redirects = array();
4142
protected $followRedirects = true;
43+
protected $browserNavigation = false;
4244

4345
private $maxRedirects = -1;
4446
private $redirectCount = 0;
@@ -78,6 +80,16 @@ public function isFollowingRedirects()
7880
return $this->followRedirects;
7981
}
8082

83+
/**
84+
* Sets whether to emulate back/forward browser navigation (skip redirects).
85+
*
86+
* @param bool $browserNavigation Whether to emulate browser navigation
87+
*/
88+
public function browserNavigation($browserNavigation = true)
89+
{
90+
$this->browserNavigation = (bool) $browserNavigation;
91+
}
92+
8193
/**
8294
* Sets the maximum number of requests that crawler can follow.
8395
*
@@ -328,6 +340,8 @@ public function request($method, $uri, array $parameters = array(), array $files
328340
}
329341

330342
if ($this->followRedirects && $this->redirect) {
343+
$this->redirects[spl_object_hash($this->history->current())] = true;
344+
331345
return $this->crawler = $this->followRedirect();
332346
}
333347

@@ -430,7 +444,11 @@ protected function createCrawlerFromContent($uri, $content, $type)
430444
*/
431445
public function back()
432446
{
433-
return $this->requestFromRequest($this->history->back(), false);
447+
do {
448+
$request = $this->history->back();
449+
} while ($this->browserNavigation && array_key_exists(spl_object_hash($request), $this->redirects));
450+
451+
return $this->requestFromRequest($request, false);
434452
}
435453

436454
/**
@@ -440,7 +458,11 @@ public function back()
440458
*/
441459
public function forward()
442460
{
443-
return $this->requestFromRequest($this->history->forward(), false);
461+
do {
462+
$request = $this->history->forward();
463+
} while ($this->browserNavigation && array_key_exists(spl_object_hash($request), $this->redirects));
464+
465+
return $this->requestFromRequest($request, false);
444466
}
445467

446468
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.