comparison vendor/symfony/browser-kit/Client.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 5fb285c0d0e3
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
40 protected $redirect; 40 protected $redirect;
41 protected $followRedirects = true; 41 protected $followRedirects = true;
42 42
43 private $maxRedirects = -1; 43 private $maxRedirects = -1;
44 private $redirectCount = 0; 44 private $redirectCount = 0;
45 private $redirects = array();
45 private $isMainRequest = true; 46 private $isMainRequest = true;
46 47
47 /** 48 /**
48 * Constructor.
49 *
50 * @param array $server The server parameters (equivalent of $_SERVER) 49 * @param array $server The server parameters (equivalent of $_SERVER)
51 * @param History $history A History instance to store the browser history 50 * @param History $history A History instance to store the browser history
52 * @param CookieJar $cookieJar A CookieJar instance to store the cookies 51 * @param CookieJar $cookieJar A CookieJar instance to store the cookies
53 */ 52 */
54 public function __construct(array $server = array(), History $history = null, CookieJar $cookieJar = null) 53 public function __construct(array $server = array(), History $history = null, CookieJar $cookieJar = null)
231 return $this->request; 230 return $this->request;
232 } 231 }
233 232
234 /** 233 /**
235 * Clicks on a given link. 234 * Clicks on a given link.
236 *
237 * @param Link $link A Link instance
238 * 235 *
239 * @return Crawler 236 * @return Crawler
240 */ 237 */
241 public function click(Link $link) 238 public function click(Link $link)
242 { 239 {
326 } else { 323 } else {
327 $this->redirect = null; 324 $this->redirect = null;
328 } 325 }
329 326
330 if ($this->followRedirects && $this->redirect) { 327 if ($this->followRedirects && $this->redirect) {
328 $this->redirects[serialize($this->history->current())] = true;
329
331 return $this->crawler = $this->followRedirect(); 330 return $this->crawler = $this->followRedirect();
332 } 331 }
333 332
334 return $this->crawler = $this->createCrawlerFromContent($this->internalRequest->getUri(), $this->internalResponse->getContent(), $this->internalResponse->getHeader('Content-Type')); 333 return $this->crawler = $this->createCrawlerFromContent($this->internalRequest->getUri(), $this->internalResponse->getContent(), $this->internalResponse->getHeader('Content-Type'));
335 } 334 }
343 * 342 *
344 * @throws \RuntimeException When processing returns exit code 343 * @throws \RuntimeException When processing returns exit code
345 */ 344 */
346 protected function doRequestInProcess($request) 345 protected function doRequestInProcess($request)
347 { 346 {
347 $deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec');
348 putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile);
349 $_ENV['SYMFONY_DEPRECATIONS_SERIALIZE'] = $deprecationsFile;
348 $process = new PhpProcess($this->getScript($request), null, null); 350 $process = new PhpProcess($this->getScript($request), null, null);
349 $process->run(); 351 $process->run();
352
353 if (file_exists($deprecationsFile)) {
354 $deprecations = file_get_contents($deprecationsFile);
355 unlink($deprecationsFile);
356 foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) {
357 if ($deprecation[0]) {
358 trigger_error($deprecation[1], E_USER_DEPRECATED);
359 } else {
360 @trigger_error($deprecation[1], E_USER_DEPRECATED);
361 }
362 }
363 }
350 364
351 if (!$process->isSuccessful() || !preg_match('/^O\:\d+\:/', $process->getOutput())) { 365 if (!$process->isSuccessful() || !preg_match('/^O\:\d+\:/', $process->getOutput())) {
352 throw new \RuntimeException(sprintf('OUTPUT: %s ERROR OUTPUT: %s', $process->getOutput(), $process->getErrorOutput())); 366 throw new \RuntimeException(sprintf('OUTPUT: %s ERROR OUTPUT: %s', $process->getOutput(), $process->getErrorOutput()));
353 } 367 }
354 368
428 * 442 *
429 * @return Crawler 443 * @return Crawler
430 */ 444 */
431 public function back() 445 public function back()
432 { 446 {
433 return $this->requestFromRequest($this->history->back(), false); 447 do {
448 $request = $this->history->back();
449 } while (array_key_exists(serialize($request), $this->redirects));
450
451 return $this->requestFromRequest($request, false);
434 } 452 }
435 453
436 /** 454 /**
437 * Goes forward in the browser history. 455 * Goes forward in the browser history.
438 * 456 *
439 * @return Crawler 457 * @return Crawler
440 */ 458 */
441 public function forward() 459 public function forward()
442 { 460 {
443 return $this->requestFromRequest($this->history->forward(), false); 461 do {
462 $request = $this->history->forward();
463 } while (array_key_exists(serialize($request), $this->redirects));
464
465 return $this->requestFromRequest($request, false);
444 } 466 }
445 467
446 /** 468 /**
447 * Reloads the current browser. 469 * Reloads the current browser.
448 * 470 *
466 throw new \LogicException('The request was not redirected.'); 488 throw new \LogicException('The request was not redirected.');
467 } 489 }
468 490
469 if (-1 !== $this->maxRedirects) { 491 if (-1 !== $this->maxRedirects) {
470 if ($this->redirectCount > $this->maxRedirects) { 492 if ($this->redirectCount > $this->maxRedirects) {
493 $this->redirectCount = 0;
471 throw new \LogicException(sprintf('The maximum number (%d) of redirections was reached.', $this->maxRedirects)); 494 throw new \LogicException(sprintf('The maximum number (%d) of redirections was reached.', $this->maxRedirects));
472 } 495 }
473 } 496 }
474 497
475 $request = $this->internalRequest; 498 $request = $this->internalRequest;
476 499
477 if (in_array($this->internalResponse->getStatus(), array(302, 303))) { 500 if (in_array($this->internalResponse->getStatus(), array(301, 302, 303))) {
478 $method = 'GET'; 501 $method = 'GET';
479 $files = array(); 502 $files = array();
480 $content = null; 503 $content = null;
481 } else { 504 } else {
482 $method = $request->getMethod(); 505 $method = $request->getMethod();