Issue #3483: parent_id not always available as index
[civicrm-core.git] / CRM / Extension / Browser.php
index b808ce4b2ce382cd9b9e74cb59f9b5d1f19f843c..42fe8fa574772944e13b65e3305dc4aa49fd5927 100644 (file)
@@ -40,6 +40,25 @@ class CRM_Extension_Browser {
   // timeout for when the connection or the server is slow
   const CHECK_TIMEOUT = 5;
 
+  /**
+   * @var GuzzleHttp\Client
+   */
+  protected $guzzleClient;
+
+  /**
+   * @return \GuzzleHttp\Client
+   */
+  public function getGuzzleClient(): \GuzzleHttp\Client {
+    return $this->guzzleClient ?? new \GuzzleHttp\Client();
+  }
+
+  /**
+   * @param \GuzzleHttp\Client $guzzleClient
+   */
+  public function setGuzzleClient(\GuzzleHttp\Client $guzzleClient) {
+    $this->guzzleClient = $guzzleClient;
+  }
+
   /**
    * @param string $repoUrl
    *   URL of the remote repository.
@@ -230,7 +249,7 @@ class CRM_Extension_Browser {
     $filename = $this->cacheDir . DIRECTORY_SEPARATOR . self::CACHE_JSON_FILE . '.' . md5($this->getRepositoryUrl());
     $url = $this->getRepositoryUrl() . $this->indexPath;
 
-    $client = new GuzzleHttp\Client();
+    $client = $this->getGuzzleClient();
     $response = $client->request('GET', $url, ['sink' => $filename, 'timeout' => \Civi::settings()->get('http_timeout')]);
     restore_error_handler();