OAuth
Kohana_OAuth

Class Contents

Class declared in MODPATH/oauth/classes/oauth.php on line 3.

Properties

public static $version
string(3) "1.0"

Methods

public static normalize_params( )
Kohana_OAuth

Source Code
public static function normalize_params(array $params = NULL)
{
	if ( ! $params)
	{
		// Nothing to do
		return '';
	}

	// Encode the parameter keys and values
	$keys   = OAuth::urlencode(array_keys($params));
	$values = OAuth::urlencode(array_values($params));

	// Recombine the parameters
	$params = array_combine($keys, $values);

	// OAuth Spec 9.1.1 (1)
	// "Parameters are sorted by name, using lexicographical byte value ordering."
	uksort($params, 'strcmp');

	// Create a new query string
	$query = array();

	foreach ($params as $name => $value)
	{
		if (is_array($value))
		{
			// OAuth Spec 9.1.1 (1)
			// "If two or more parameters share the same name, they are sorted by their value."
			$value = natsort($value);

			foreach ($value as $duplicate)
			{
				$query[] = $name.'='.$duplicate;
			}
		}
		else
		{
			$query[] = $name.'='.$value;
		}
	}

	return implode('&', $query);
}

public static parse_params( )
Kohana_OAuth

Source Code
public static function parse_params($params)
{
	// Split the parameters by &
	$params = explode('&', trim($params));

	// Create an array of parsed parameters
	$parsed = array();

	foreach ($params as $param)
	{
		// Split the parameter into name and value
		list($name, $value) = explode('=', $param, 2);

		// Decode the name and value
		$name  = OAuth::urldecode($name);
		$value = OAuth::urldecode($value);

		if (isset($parsed[$name]))
		{
			if ( ! is_array($parsed[$name]))
			{
				// Convert the parameter to an array
				$parsed[$name] = array($parsed[$name]);
			}

			// Add a new duplicate parameter
			$parsed[$name][] = $value;
		}
		else
		{
			// Add a new parameter
			$parsed[$name] = $value;
		}
	}

	return $parsed;
}

public static parse_url( )
Kohana_OAuth

Source Code
public static function parse_url($url)
{
	if ($query = parse_url($url, PHP_URL_QUERY))
	{
		// Remove the query string from the URL
		list($url) = explode('?', $url, 2);

		// Parse the query string as request parameters
		$params = OAuth::parse_params($query);
	}
	else
	{
		// No parameters are present
		$params = array();
	}

	return array($url, $params);
}

public static urldecode( )
Kohana_OAuth

Source Code
public static function urldecode($input)
{
	if (is_array($input))
	{
		// Decode the values of the array
		return array_map(array('OAuth', 'urldecode'), $input);
	}

	// Decode the input
	return rawurldecode($input);
}

public static urlencode( )
Kohana_OAuth

Source Code
public static function urlencode($input)
{
	if (is_array($input))
	{
		// Encode the values of the array
		return array_map(array('OAuth', 'urlencode'), $input);
	}

	// Encode the input
	$input = rawurlencode($input);

	if (version_compare(PHP_VERSION, '<', '5.3'))
	{
		// rawurlencode() is RFC3986 compliant in PHP 5.3
		// the only difference is the encoding of tilde
		$input = str_replace('%7E', '~', $input);
	}

	return $input;
}