You are here

public function OAuthRequest::get_signable_parameters in OAuth 1.0 6

Same name and namespace in other branches
  1. 6.3 lib/OAuth.php \OAuthRequest::get_signable_parameters()
  2. 7.3 lib/OAuth.php \OAuthRequest::get_signable_parameters()

Returns the normalized parameters of the request

This will be all (except oauth_signature) parameters, sorted first by key, and if duplicate keys, then by value.

The returned string will be all the key=value pairs concated by &.

Return value

string

1 call to OAuthRequest::get_signable_parameters()
OAuthRequest::get_signature_base_string in ./OAuth.php
Returns the base string of this request

File

./OAuth.php, line 259

Class

OAuthRequest

Code

public function get_signable_parameters() {

  /*{{{*/

  // Grab all parameters
  $params = $this->parameters;

  // Remove oauth_signature if present
  if (isset($params['oauth_signature'])) {
    unset($params['oauth_signature']);
  }

  // Urlencode both keys and values
  $keys = array_map(array(
    'OAuthUtil',
    'urlencodeRFC3986',
  ), array_keys($params));
  $values = array_map(array(
    'OAuthUtil',
    'urlencodeRFC3986',
  ), array_values($params));
  $params = array_combine($keys, $values);

  // Sort by keys (natsort)
  uksort($params, 'strnatcmp');

  // Generate key=value pairs
  $pairs = array();
  foreach ($params as $key => $value) {
    if (is_array($value)) {

      // If the value is an array, it's because there are multiple
      // with the same key, sort them, then add all the pairs
      natsort($value);
      foreach ($value as $v2) {
        $pairs[] = $key . '=' . $v2;
      }
    }
    else {
      $pairs[] = $key . '=' . $value;
    }
  }

  // Return the pairs, concated with &
  return implode('&', $pairs);
}