You are here

public static function Helpers::parseStrMultiple in Search API Federated Solr 8.3

Same name and namespace in other branches
  1. 8.2 src/Utility/Helpers.php \Drupal\search_api_federated_solr\Utility\Helpers::parseStrMultiple()
  2. 4.x src/Utility/Helpers.php \Drupal\search_api_federated_solr\Utility\Helpers::parseStrMultiple()

Parses a querystring with support for multiple keys not using array[] syntax. @see: http://php.net/manual/en/function.parse-str.php#76792

Parameters

$str: The querystring from the request object.

Return value

array Array of querystring params and their values.

1 call to Helpers::parseStrMultiple()
SolrProxyController::getResultsJson in src/Controller/SolrProxyController.php
Uses the selected index server's backend connector to execute a select query on the index based on request qs params passed from the app.

File

src/Utility/Helpers.php, line 109

Class

Helpers
Contains helper methods for the Search API Federated Solr module.

Namespace

Drupal\search_api_federated_solr\Utility

Code

public static function parseStrMultiple($str) {

  # result array
  $arr = [];

  # split on outer delimiter
  $pairs = explode('&', $str);

  # loop through each pair
  foreach ($pairs as $i) {

    # split into name and value
    list($name, $value) = explode('=', $i, 2);

    # if name already exists
    if (isset($arr[$name])) {

      # stick multiple values into an array
      if (is_array($arr[$name])) {
        $arr[$name][] = $value;
      }
      else {
        $arr[$name] = array(
          $arr[$name],
          $value,
        );
      }
    }
    else {
      $arr[$name] = $value;
    }
  }

  # return result array
  return $arr;
}