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 4c8af71

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

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
@@ -42,6 +42,8 @@ abstract class Client
4242

4343
private $maxRedirects = -1;
4444
private $redirectCount = 0;
45+
private $redirects = array();
46+
private $browserNavigation = false;
4547
private $isMainRequest = true;
4648

4749
/**
@@ -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.