Permalink
Browse files

Merge branch '3.0/develop' into 3.1/develop

  • Loading branch information...
2 parents a3dfdef + 4f1696c commit bc79b8aa4c1b57a901be0500c64d2e7b34107c40 @shadowhand shadowhand committed Jan 10, 2011
Showing with 66 additions and 35 deletions.
  1. +65 −34 classes/kohana/oauth/request.php
  2. +1 −1 config/userguide.php
View
99 classes/kohana/oauth/request.php
@@ -60,6 +60,11 @@ public static function factory($type, $method, $url = NULL, array $params = NULL
protected $params = array();
/**
+ * @var array upload parameters
+ */
+ protected $upload = array();
+
+ /**
* @var array required parameters
*/
protected $required = array();
@@ -181,7 +186,7 @@ public function base_string()
$url = $this->url;
// Get the request parameters
- $params = $this->params;
+ $params = array_diff_key($this->params, $this->upload);
// "oauth_signature" is never included in the base string!
unset($params['oauth_signature']);
@@ -203,9 +208,6 @@ public function base_string()
* // Get the "oauth_consumer_key" value
* $key = $request->param('oauth_consumer_key');
*
- * // Remove "oauth_consumer_key"
- * $request->param('oauth_consumer_key', NULL);
- *
* @param string parameter name
* @param mixed parameter value
* @param boolean allow duplicates?
@@ -215,35 +217,27 @@ public function base_string()
*/
public function param($name, $value = NULL, $duplicate = FALSE)
{
- if (func_num_args() < 2)
+ if ($value === NULL)
{
// Get the parameter
return Arr::get($this->params, $name);
}
- if ($value === NULL)
+ if (isset($this->params[$name]) AND $duplicate)
{
- // Remove the parameter
- unset($this->params[$name]);
+ if ( ! is_array($this->params[$name]))
+ {
+ // Convert the parameter into an array
+ $this->params[$name] = array($this->params[$name]);
+ }
+
+ // Add the duplicate value
+ $this->params[$name][] = $value;
}
else
{
- if (isset($this->params[$name]) AND $duplicate)
- {
- if ( ! is_array($this->params[$name]))
- {
- // Convert the parameter into an array
- $this->params[$name] = array($this->params[$name]);
- }
-
- // Add the duplicate value
- $this->params[$name][] = $value;
- }
- else
- {
- // Set the parameter value
- $this->params[$name] = $value;
- }
+ // Set the parameter value
+ $this->params[$name] = $value;
}
return $this;
@@ -270,6 +264,38 @@ public function params(array $params, $duplicate = FALSE)
}
/**
+ * Upload getter and setter. Setting the value to `NULL` will remove it.
+ *
+ * // Set the "image" file path for uploading
+ * $request->upload('image', $file_path);
+ *
+ * // Get the "image" file path
+ * $key = $request->param('oauth_consumer_key');
+ *
+ * @param string upload name
+ * @param mixed upload file path
+ * @return mixed when getting
+ * @return $this when setting
+ * @uses OAuth_Request::param
+ */
+ public function upload($name, $value = NULL)
+ {
+ if ($value !== NULL)
+ {
+ // This is an upload parameter
+ $this->upload[$name] = TRUE;
+
+ // Get the mime type of the image
+ $mime = File::mime($value);
+
+ // Format the image path for CURL
+ $value = "@{$value};type={$mime}";
+ }
+
+ return $this->param($name, $value, FALSE);
+ }
+
+ /**
* Get and set required parameters.
*
* $request->required($field, $value);
@@ -283,6 +309,7 @@ public function required($param, $value = NULL)
{
if ($value === NULL)
{
+ // Get the current status
return ! empty($this->required[$param]);
}
@@ -326,16 +353,25 @@ public function as_header()
*
* [!!] This method implements [OAuth 1.0 Spec 5.2 (2,3)](http://oauth.net/core/1.0/#rfc.section.5.2).
*
- * @param boolean include oauth parameters
+ * @param boolean include oauth parameters?
+ * @param boolean return a normalized string?
* @return string
*/
- public function as_query($include_oauth = NULL)
+ public function as_query($include_oauth = NULL, $as_string = TRUE)
{
- if ($include_oauth !== TRUE AND $this->send_header)
+ if ($include_oauth === NULL)
{
// If we are sending a header, OAuth parameters should not be
// included in the query string.
+ $include_oauth = ! $this->send_header;
+ }
+ if ($include_oauth)
+ {
+ $params = $this->params;
+ }
+ else
+ {
$params = array();
foreach ($this->params as $name => $value)
{
@@ -346,12 +382,8 @@ public function as_query($include_oauth = NULL)
}
}
}
- else
- {
- $params = $this->params;
- }
- return OAuth::normalize_params($params);
+ return $as_string ? OAuth::normalize_params($params) : $params;
}
/**
@@ -422,7 +454,6 @@ public function check()
/**
* Execute the request and return a response.
*
- * @param string request type: GET, POST, etc (NULL for header)
* @param array additional cURL options
* @return string request response body
* @uses OAuth_Request::check
@@ -460,7 +491,7 @@ public function execute(array $options = NULL)
// Send the request as a POST
$options[CURLOPT_POST] = TRUE;
- if ($post = $this->as_query())
+ if ($post = $this->as_query(NULL, empty($this->upload)))
{
// Attach the post fields to the request
$options[CURLOPT_POSTFIELDS] = $post;
View
2 config/userguide.php
@@ -14,7 +14,7 @@
'name' => 'OAuth',
// A short description of this module, shown on the index page
- 'description' => 'Official OAuth module, used for open protocol authorization.',
+ 'description' => 'Open protocol authorization.',
// Copyright message, shown in the footer for this module
'copyright' => '&copy; 2008–2010 Kohana Team',

0 comments on commit bc79b8a

Please sign in to comment.