You are here

public static function OAuthUtil::parse_parameters in OAuth 1.0 6.3

Same name and namespace in other branches
  1. 7.3 lib/OAuth.php \OAuthUtil::parse_parameters()
2 calls to OAuthUtil::parse_parameters()
OAuthRequest::from_request in lib/OAuth.php
attempt to build up a request from what was passed to the server
OAuthRequest::__construct in lib/OAuth.php

File

lib/OAuth.php, line 854
OAuth 1.0 server and client library.

Class

OAuthUtil

Code

public static function parse_parameters($input) {
  if (!isset($input) || !$input) {
    return array();
  }
  $pairs = explode('&', $input);
  $parsed_parameters = array();
  foreach ($pairs as $pair) {
    $split = explode('=', $pair, 2);
    $parameter = OAuthUtil::urldecode_rfc3986($split[0]);
    $value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : '';
    if (isset($parsed_parameters[$parameter])) {

      // We have already recieved parameter(s) with this name, so add to the list
      // of parameters with this name
      if (is_scalar($parsed_parameters[$parameter])) {

        // This is the first duplicate, so transform scalar (string) into an array
        // so we can add the duplicates
        $parsed_parameters[$parameter] = array(
          $parsed_parameters[$parameter],
        );
      }
      $parsed_parameters[$parameter][] = $value;
    }
    else {
      $parsed_parameters[$parameter] = $value;
    }
  }
  return $parsed_parameters;
}