namespace Symfony\Component\BrowserKit;
use Symfony\Component\DomCrawler\Crawler;
-use Symfony\Component\DomCrawler\Link;
use Symfony\Component\DomCrawler\Form;
+use Symfony\Component\DomCrawler\Link;
use Symfony\Component\Process\PhpProcess;
/**
private $maxRedirects = -1;
private $redirectCount = 0;
+ private $redirects = array();
private $isMainRequest = true;
/**
- * Constructor.
- *
* @param array $server The server parameters (equivalent of $_SERVER)
* @param History $history A History instance to store the browser history
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
}
/**
- * Sets the maximum number of requests that crawler can follow.
+ * Sets the maximum number of redirects that crawler can follow.
*
* @param int $maxRedirects
*/
}
/**
- * Returns the maximum number of requests that crawler can follow.
+ * Returns the maximum number of redirects that crawler can follow.
*
* @return int
*/
/**
* Clicks on a given link.
*
- * @param Link $link A Link instance
- *
* @return Crawler
*/
public function click(Link $link)
}
if ($this->followRedirects && $this->redirect) {
+ $this->redirects[serialize($this->history->current())] = true;
+
return $this->crawler = $this->followRedirect();
}
*/
protected function doRequestInProcess($request)
{
+ $deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec');
+ putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile);
+ $_ENV['SYMFONY_DEPRECATIONS_SERIALIZE'] = $deprecationsFile;
$process = new PhpProcess($this->getScript($request), null, null);
$process->run();
+ if (file_exists($deprecationsFile)) {
+ $deprecations = file_get_contents($deprecationsFile);
+ unlink($deprecationsFile);
+ foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) {
+ if ($deprecation[0]) {
+ @trigger_error($deprecation[1], E_USER_DEPRECATED);
+ } else {
+ @trigger_error($deprecation[1], E_USER_DEPRECATED);
+ }
+ }
+ }
+
if (!$process->isSuccessful() || !preg_match('/^O\:\d+\:/', $process->getOutput())) {
throw new \RuntimeException(sprintf('OUTPUT: %s ERROR OUTPUT: %s', $process->getOutput(), $process->getErrorOutput()));
}
*/
public function back()
{
- return $this->requestFromRequest($this->history->back(), false);
+ do {
+ $request = $this->history->back();
+ } while (array_key_exists(serialize($request), $this->redirects));
+
+ return $this->requestFromRequest($request, false);
}
/**
*/
public function forward()
{
- return $this->requestFromRequest($this->history->forward(), false);
+ do {
+ $request = $this->history->forward();
+ } while (array_key_exists(serialize($request), $this->redirects));
+
+ return $this->requestFromRequest($request, false);
}
/**
if (-1 !== $this->maxRedirects) {
if ($this->redirectCount > $this->maxRedirects) {
+ $this->redirectCount = 0;
throw new \LogicException(sprintf('The maximum number (%d) of redirections was reached.', $this->maxRedirects));
}
}
$request = $this->internalRequest;
- if (in_array($this->internalResponse->getStatus(), array(302, 303))) {
+ if (\in_array($this->internalResponse->getStatus(), array(301, 302, 303))) {
$method = 'GET';
$files = array();
$content = null;