Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / browser-kit / Client.php
index 286f2f98c45d1ac309de9f8ab8a7466ef28a390d..e9e0d1963f624a774dc06a584af3a6d0db46b6c7 100644 (file)
@@ -42,11 +42,10 @@ abstract class Client
 
     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
@@ -79,7 +78,7 @@ abstract class Client
     }
 
     /**
-     * Sets the maximum number of requests that crawler can follow.
+     * Sets the maximum number of redirects that crawler can follow.
      *
      * @param int $maxRedirects
      */
@@ -90,7 +89,7 @@ abstract class Client
     }
 
     /**
-     * Returns the maximum number of requests that crawler can follow.
+     * Returns the maximum number of redirects that crawler can follow.
      *
      * @return int
      */
@@ -234,8 +233,6 @@ abstract class Client
     /**
      * Clicks on a given link.
      *
-     * @param Link $link A Link instance
-     *
      * @return Crawler
      */
     public function click(Link $link)
@@ -328,6 +325,8 @@ abstract class Client
         }
 
         if ($this->followRedirects && $this->redirect) {
+            $this->redirects[serialize($this->history->current())] = true;
+
             return $this->crawler = $this->followRedirect();
         }
 
@@ -345,9 +344,24 @@ abstract class Client
      */
     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()));
         }
@@ -430,7 +444,11 @@ abstract class Client
      */
     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);
     }
 
     /**
@@ -440,7 +458,11 @@ abstract class Client
      */
     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);
     }
 
     /**
@@ -468,6 +490,7 @@ abstract class Client
 
         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));
             }
         }