Merge pull request #14077 from pradpnayak/AutoComplete
[civicrm-core.git] / CRM / Cxn / CiviCxnHttp.php
index da03e65167f34aaa35137277bd781344e8525ab6..f8acdb9704322a09d78b7654508c1ce11f93732e 100644 (file)
@@ -22,11 +22,11 @@ class CRM_Cxn_CiviCxnHttp extends \Civi\Cxn\Rpc\Http\PhpHttp {
    */
   public static function singleton($fresh = FALSE) {
     if (self::$singleton === NULL || $fresh) {
-      $cache = CRM_Utils_Cache::create(array(
+      $cache = CRM_Utils_Cache::create([
         'name' => 'CiviCxnHttp',
-        'type' => Civi::settings()->get('debug_enabled') ? 'ArrayCache' : array('SqlGroup', 'ArrayCache'),
+        'type' => Civi::settings()->get('debug_enabled') ? 'ArrayCache' : ['SqlGroup', 'ArrayCache'],
         'prefetch' => FALSE,
-      ));
+      ]);
 
       self::$singleton = new CRM_Cxn_CiviCxnHttp($cache);
     }
@@ -50,11 +50,11 @@ class CRM_Cxn_CiviCxnHttp extends \Civi\Cxn\Rpc\Http\PhpHttp {
    * @return array
    *   array($headers, $blob, $code)
    */
-  public function send($verb, $url, $blob, $headers = array()) {
+  public function send($verb, $url, $blob, $headers = []) {
     $lowVerb = strtolower($verb);
 
     if ($lowVerb === 'get' && $this->cache) {
-      $cachePath = 'get/' . md5($url);
+      $cachePath = 'get_' . md5($url);
       $cacheLine = $this->cache->get($cachePath);
       if ($cacheLine && $cacheLine['expires'] > CRM_Utils_Time::getTimeRaw()) {
         return $cacheLine['data'];
@@ -66,12 +66,12 @@ class CRM_Cxn_CiviCxnHttp extends \Civi\Cxn\Rpc\Http\PhpHttp {
     if ($lowVerb === 'get' && $this->cache) {
       $expires = CRM_Utils_Http::parseExpiration($result[0]);
       if ($expires !== NULL) {
-        $cachePath = 'get/' . md5($url);
-        $cacheLine = array(
+        $cachePath = 'get_' . md5($url);
+        $cacheLine = [
           'url' => $url,
           'expires' => $expires,
           'data' => $result,
-        );
+        ];
         $this->cache->set($cachePath, $cacheLine);
       }
     }
@@ -79,12 +79,23 @@ class CRM_Cxn_CiviCxnHttp extends \Civi\Cxn\Rpc\Http\PhpHttp {
     return $result;
   }
 
+  /**
+   * Create stream options.
+   *
+   * @param string $verb
+   * @param string $url
+   * @param string $blob
+   * @param array $headers
+   *
+   * @return array
+   * @throws \Exception
+   */
   protected function createStreamOpts($verb, $url, $blob, $headers) {
     $result = parent::createStreamOpts($verb, $url, $blob, $headers);
 
-    $caConfig = CA_Config_Stream::probe(array(
+    $caConfig = CA_Config_Stream::probe([
       'verify_peer' => (bool) Civi::settings()->get('verifySSL'),
-    ));
+    ]);
     if ($caConfig->isEnableSSL()) {
       $result['ssl'] = $caConfig->toStreamOptions();
     }
@@ -95,4 +106,11 @@ class CRM_Cxn_CiviCxnHttp extends \Civi\Cxn\Rpc\Http\PhpHttp {
     return $result;
   }
 
+  /**
+   * @return \CRM_Utils_Cache_Interface|null
+   */
+  public function getCache() {
+    return $this->cache;
+  }
+
 }