← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1772: [core] Implement AnewtRequest::{get, post, cookie}_value()

 

------------------------------------------------------------
revno: 1772
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Sun 2010-03-21 15:18:41 +0100
message:
  [core] Implement AnewtRequest::{get,post,cookie}_value()
  
  This will get any value from the request as-is. This is what
  AnewtRequest::{get,post,cookie}_string() used to do as well,
  but now those functions actually check for string values.
  
  The _value() methods are useful for extracting e.g. arrays
  from the request environment (PHP automatically converts
  parameters with their name ending in [] into arrays).
modified:
  core/request.lib.php


--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws

Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription.
=== modified file 'core/request.lib.php'
--- core/request.lib.php	2010-02-24 22:14:12 +0000
+++ core/request.lib.php	2010-03-21 14:18:41 +0000
@@ -318,6 +318,51 @@
 		return array_get_default($_SERVER, 'HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest';
 	}
 
+	/* Any value (not converted) */
+
+	/**
+	 * Get a value from the GET request data.
+	 *
+	 * \param $key The name of the value.
+	 * \param $default The default value to return if no value was found
+	 * (defaults to <code>null</code>.
+	 *
+	 * \return The value or the default value.
+	 */
+	public static function get_value($key, $default=null)
+	{
+		return array_get_default($_GET, $key, $default);
+	}
+
+	/**
+	 * Get a value from the POST request data.
+	 *
+	 * \param $key The name of the value.
+	 * \param $default The default value to return if no value was found
+	 * (defaults to <code>null</code>.
+	 *
+	 * \return The value or the default value.
+	 */
+	public static function post_value($key, $default=null)
+	{
+		return array_get_default($_POST, $key, $default);
+	}
+
+	/**
+	 * Get a value from the COOKIE data.
+	 *
+	 * \param $key The name of the value.
+	 * \param $default The default value to return if no value was found
+	 * (defaults to <code>null</code>.
+	 *
+	 * \return The value or the default value.
+	 */
+	public static function cookie_value($key, $default=null)
+	{
+		return array_get_default($_COOKIE, $key, $default);
+	}
+
+
 	/* Integers */
 
 	/**
@@ -335,7 +380,7 @@
 	}
 
 	/**
-	 * Gets an integer from the POST request data.
+	 * Get an integer from the POST request data.
 	 *
 	 * \param $key The name of the integer.
 	 * \param $default The default value to return if no valid integer was
@@ -349,7 +394,7 @@
 	}
 
 	/**
-	 * Gets an integer from the COOKIE data.
+	 * Get an integer from the COOKIE data.
 	 *
 	 * \param $key The name of the integer.
 	 * \param $default The default value to return if no valid integer was
@@ -366,7 +411,7 @@
 	/* Strings */
 
 	/**
-	 * Gets a string from the GET request data.
+	 * Get a string from the GET request data.
 	 *
 	 * \param $key The name of the string.
 	 * \param $default The default value to return if no string was found. If
@@ -376,11 +421,16 @@
 	 */
 	public static function get_string($key, $default=null)
 	{
-		return array_get_default($_GET, $key, $default);
+		$value = array_get_default($_GET, $key, $default);
+
+		if (!is_string($value))
+			return $default;
+
+		return $value;
 	}
 
 	/**
-	 * Gets a string from the POST request data.
+	 * Get a string from the POST request data.
 	 *
 	 * \param $key The name of the string.
 	 * \param $default The default value to return if no string was found. If
@@ -390,11 +440,16 @@
 	 */
 	public static function post_string($key, $default=null)
 	{
-		return array_get_default($_POST, $key, $default);
+		$value = array_get_default($_POST, $key, $default);
+
+		if (!is_string($value))
+			return $default;
+
+		return $value;
 	}
 
 	/**
-	 * Gets a string from the COOKIE data.
+	 * Get a string from the COOKIE data.
 	 *
 	 * \param $key The name of the string.
 	 * \param $default The default value to return if no string was found. If
@@ -404,7 +459,12 @@
 	 */
 	public static function cookie_string($key, $default=null)
 	{
-		return array_get_default($_COOKIE, $key, $default);
+		$value = array_get_default($_COOKIE, $key, $default);
+
+		if (!is_string($value))
+			return $default;
+
+		return $value;
 	}
 
 
@@ -412,7 +472,7 @@
 
 
 	/**
-	 * Gets a boolean value from the GET data.
+	 * Get a boolean value from the GET data.
 	 *
 	 * \param $key
 	 *   The name of the boolean.
@@ -432,7 +492,7 @@
 	}
 
 	/**
-	 * Gets a boolean value from the POST data.
+	 * Get a boolean value from the POST data.
 	 *
 	 * \param $key
 	 *   The name of the boolean.
@@ -452,7 +512,7 @@
 	}
 
 	/**
-	 * Gets a boolean value from the COOKIE data.
+	 * Get a boolean value from the COOKIE data.
 	 *
 	 * \param $key
 	 *   The name of the boolean.