← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1714: [core, gpc] Merge AnewtGPC into AnewtRequest

 

------------------------------------------------------------
revno: 1714
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Sun 2009-08-02 12:57:53 +0200
message:
  [core,gpc] Merge AnewtGPC into AnewtRequest
              
  The gpc module is now gone since all methods have been moved
  to AnewtRequest. Both classes operated on request-specific
  data anyway. Also updated all other code referencing this
  module and some docs.
removed:
  gpc/
  gpc/gpc.lib.php
  gpc/main.lib.php
modified:
  core/module.doc.xml
  core/request.lib.php
  doc/manual/examples/core-request.php
  image/image.test.php
  textile/textile.test.php
  xml/dom.test.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/module.doc.xml'
--- core/module.doc.xml	2009-04-12 22:38:28 +0000
+++ core/module.doc.xml	2009-08-02 10:57:53 +0000
@@ -8,10 +8,10 @@
 	<anewt:subtitle>Core functions and classes</anewt:subtitle>
 
 	<anewt:classes>
+		<anewt:class>AnewtException</anewt:class>
+		<anewt:class>AnewtRequest</anewt:class>
+		<anewt:class>AnewtURL</anewt:class>
 		<anewt:class>Container</anewt:class>
-		<anewt:class>Request</anewt:class>
-		<anewt:class>URL</anewt:class>
-		<anewt:class>XML</anewt:class>
 	</anewt:classes>
 
 
@@ -246,18 +246,21 @@
 
 	<anewt:section>
 
-		<anewt:title>The <anewt:classref>Request</anewt:classref> class</anewt:title>
+		<anewt:title>The <anewt:classref>AnewtRequest</anewt:classref> class</anewt:title>
 
-		<p>The <anewt:classref>Request</anewt:classref> class provides several
+		<p>The <anewt:classref>AnewtRequest</anewt:classref> class provides several
 			static methods to retrieve information about the current request.
 			The relative and canonical (full) URL's for the current request
 			can be retrieved using the
-			<anewt:functionref>Request::relative_url()</anewt:functionref> and
-			<anewt:functionref>Request::canonical_url()</anewt:functionref> methods. Furthermore, the
+			<anewt:functionref>AnewtRequest::relative_url()</anewt:functionref> and
+			<anewt:functionref>AnewtRequest::canonical_url()</anewt:functionref> methods. Furthermore, the
 			request type can easily be determined by calling the
-			<anewt:functionref>Request::method()</anewt:functionref>,
-			<anewt:functionref>Request::is_get()</anewt:functionref> and
-			<anewt:functionref>Request::is_post()</anewt:functionref> methods.</p>
+			<anewt:functionref>AnewtRequest::method()</anewt:functionref>,
+			<anewt:functionref>AnewtRequest::is_get()</anewt:functionref> and
+			<anewt:functionref>AnewtRequest::is_post()</anewt:functionref>
+			methods. In addition, several methods to extract GET, POST or
+			cookie data (with type-safety) are available.
+			</p>
 
 		<anewt:example src="core-request">
 			<anewt:title>Retrieving request information</anewt:title>

=== modified file 'core/request.lib.php'
--- core/request.lib.php	2009-08-02 10:54:09 +0000
+++ core/request.lib.php	2009-08-02 10:57:53 +0000
@@ -244,8 +244,9 @@
 	/** \{
 	 * \name GET, POST, and cookie methods
 	 *
-	 * These methods allow you to find out FIXME and extract \c GET and \c POST
-	 * parameters and cookie values.
+	 * These methods allow you to find out the request method of the current
+	 * request, and offers various type-safe methods to extract values from \c
+	 * GET and \c POST parameters and cookies.
 	 */
 
 	/**
@@ -304,7 +305,159 @@
 		return AnewtRequest::method() === 'POST';
 	}
 
-	/* TODO: merge AnewtGPC here */
+
+	/* Integers */
+
+	/**
+	 * Get an integer from the GET request data.
+	 *
+	 * \param $key The name of the integer.
+	 * \param $default The default value to return if no valid integer was
+	 * found. If you omit this parameter, null is used.
+	 *
+	 * \return A valid integer or the default value.
+	 */
+	public static function get_int($key, $default=null)
+	{
+		return array_get_int($_GET, $key, $default);
+	}
+
+	/**
+	 * Gets 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
+	 * found. If you omit this parameter, null is used.
+	 *
+	 * \return A valid integer or the default value.
+	 */
+	public static function post_int($key, $default=null)
+	{
+		return array_get_int($_POST, $key, $default);
+	}
+
+	/**
+	 * Gets 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
+	 * found. If you omit this parameter, null is used.
+	 *
+	 * \return A valid integer or the default value.
+	 */
+	public static function cookie_int($key, $default=null)
+	{
+		return array_get_int($_COOKIE, $key, $default);
+	}
+
+
+	/* Strings */
+
+	/**
+	 * Gets 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
+	 * you omit this parameter, null is used.
+	 *
+	 * \return A string or the default value.
+	 */
+	public static function get_string($key, $default=null)
+	{
+		return array_get_default($_GET, $key, $default);
+	}
+
+	/**
+	 * Gets 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
+	 * you omit this parameter, null is used.
+	 *
+	 * \return A string or the default value.
+	 */
+	public static function post_string($key, $default=null)
+	{
+		return array_get_default($_POST, $key, $default);
+	}
+
+	/**
+	 * Gets 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
+	 * you omit this parameter, null is used.
+	 *
+	 * \return A string or the default value.
+	 */
+	public static function cookie_string($key, $default=null)
+	{
+		return array_get_default($_COOKIE, $key, $default);
+	}
+
+
+	/* Booleans */
+
+
+	/**
+	 * Gets a boolean value from the GET data.
+	 *
+	 * \param $key
+	 *   The name of the boolean.
+	 *
+	 * \param $default
+	 *   The default value to return if no valid boolean was found. If you omit
+	 *   this parameter, null is used.
+	 *
+	 * \return
+	 *   A string or the default value.
+	 *
+	 * \see array_get_bool
+	 */
+	public static function get_bool($key, $default=null)
+	{
+		return array_get_bool($_GET, $key, $default);
+	}
+
+	/**
+	 * Gets a boolean value from the POST data.
+	 *
+	 * \param $key
+	 *   The name of the boolean.
+	 *
+	 * \param $default
+	 *   The default value to return if no valid boolean was found. If you omit
+	 *   this parameter, null is used.
+	 *
+	 * \return
+	 *   A string or the default value.
+	 *
+	 * \see array_get_bool
+	 */
+	public static function post_bool($key, $default=null)
+	{
+		return array_get_bool($_POST, $key, $default);
+	}
+
+	/**
+	 * Gets a boolean value from the COOKIE data.
+	 *
+	 * \param $key
+	 *   The name of the boolean.
+	 *
+	 * \param $default
+	 *   The default value to return if no valid boolean was found. If you omit
+	 *   this parameter, null is used.
+	 *
+	 * \return
+	 *   A string or the default value.
+	 *
+	 * \see array_get_bool
+	 */
+	public static function cookie_bool($key, $default=null)
+	{
+		return array_get_bool($_COOKIE, $key, $default);
+	}
 
 	/** \} */
 }

=== modified file 'doc/manual/examples/core-request.php'
--- doc/manual/examples/core-request.php	2006-08-25 15:27:59 +0000
+++ doc/manual/examples/core-request.php	2009-08-02 10:57:53 +0000
@@ -1,15 +1,15 @@
 // Get the url of the current request. The shorter
-// Request::url() method does exactly the same as
-// Request::relative_url(), but saves you a bit of typing.
+// AnewtRequest::url() method does exactly the same as
+// AnewtRequest::relative_url(), but saves you a bit of typing.
 // Example result: /path/to/page
-$url = Request::url();
-$url = Request::relative_url();
+$url = AnewtRequest::url();
+$url = AnewtRequest::relative_url();
 
 // This yields the canonical url. Example:
 // http://example.com/path/to/page
-$url = Request::canonical_url();
+$url = AnewtRequest::canonical_url();
 
 // Find out the request method:
-$method = Request::method();    // "GET" or "POST"
-$somevar = Request::is_get();   // true or false
-$somevar = Request::is_post();  // true or false
+$method = AnewtRequest::method();    // "GET" or "POST"
+$somevar = AnewtRequest::is_get();   // true or false
+$somevar = AnewtRequest::is_post();  // true or false

=== removed directory 'gpc'
=== removed file 'gpc/gpc.lib.php'
--- gpc/gpc.lib.php	2008-11-14 20:49:16 +0000
+++ gpc/gpc.lib.php	1970-01-01 00:00:00 +0000
@@ -1,184 +0,0 @@
-<?php
-
-/*
- * Anewt, Almost No Effort Web Toolkit, gpc module
- *
- * This code is copyrighted and distributed under the terms of the GNU LGPL.
- * See the README file for more information.
- */
-
-
-/* TODO: revise documentation */
-
-/**
- * This class allows you to get type-safe data from GET, POST and COOKIE values.
- * All methods are static.
- */
-class AnewtGPC
-{
-	/* All methods are static... */
-
-	/**
-	 * Constructor throws an error. All methods are static and should not be
-	 * called on object instances.
-	 */
-	private function __construct()
-	{
-		throw new Exception('The AnewtGPC class only provides static methods.');
-	}
-
-	/* Integers */
-
-	/**
-	 * Get an integer from the GET request data.
-	 *
-	 * \param $key The name of the integer.
-	 * \param $default The default value to return if no valid integer was
-	 * found. If you omit this parameter, null is used.
-	 *
-	 * \return A valid integer or the default value.
-	 */
-	public static function get_int($key, $default=null)
-	{
-		return array_get_int($_GET, $key, $default);
-	}
-
-	/**
-	 * Gets 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
-	 * found. If you omit this parameter, null is used.
-	 *
-	 * \return A valid integer or the default value.
-	 */
-	public static function post_int($key, $default=null)
-	{
-		return array_get_int($_POST, $key, $default);
-	}
-
-	/**
-	 * Gets 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
-	 * found. If you omit this parameter, null is used.
-	 *
-	 * \return A valid integer or the default value.
-	 */
-	public static function cookie_int($key, $default=null)
-	{
-		return array_get_int($_COOKIE, $key, $default);
-	}
-
-
-	/* Strings */
-
-	/**
-	 * Gets 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
-	 * you omit this parameter, null is used.
-	 *
-	 * \return A string or the default value.
-	 */
-	public static function get_string($key, $default=null)
-	{
-		return array_get_default($_GET, $key, $default);
-	}
-
-	/**
-	 * Gets 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
-	 * you omit this parameter, null is used.
-	 *
-	 * \return A string or the default value.
-	 */
-	public static function post_string($key, $default=null)
-	{
-		return array_get_default($_POST, $key, $default);
-	}
-
-	/**
-	 * Gets 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
-	 * you omit this parameter, null is used.
-	 *
-	 * \return A string or the default value.
-	 */
-	public static function cookie_string($key, $default=null)
-	{
-		return array_get_default($_COOKIE, $key, $default);
-	}
-
-
-	/* Booleans */
-
-
-	/**
-	 * Gets a boolean value from the GET data.
-	 *
-	 * \param $key
-	 *   The name of the boolean.
-	 *
-	 * \param $default
-	 *   The default value to return if no valid boolean was found. If you omit
-	 *   this parameter, null is used.
-	 *
-	 * \return
-	 *   A string or the default value.
-	 *
-	 * \see array_get_bool
-	 */
-	public static function get_bool($key, $default=null)
-	{
-		return array_get_bool($_GET, $key, $default);
-	}
-
-	/**
-	 * Gets a boolean value from the POST data.
-	 *
-	 * \param $key
-	 *   The name of the boolean.
-	 *
-	 * \param $default
-	 *   The default value to return if no valid boolean was found. If you omit
-	 *   this parameter, null is used.
-	 *
-	 * \return
-	 *   A string or the default value.
-	 *
-	 * \see array_get_bool
-	 */
-	public static function post_bool($key, $default=null)
-	{
-		return array_get_bool($_POST, $key, $default);
-	}
-
-	/**
-	 * Gets a boolean value from the COOKIE data.
-	 *
-	 * \param $key
-	 *   The name of the boolean.
-	 *
-	 * \param $default
-	 *   The default value to return if no valid boolean was found. If you omit
-	 *   this parameter, null is used.
-	 *
-	 * \return
-	 *   A string or the default value.
-	 *
-	 * \see array_get_bool
-	 */
-	public static function cookie_bool($key, $default=null)
-	{
-		return array_get_bool($_COOKIE, $key, $default);
-	}
-}
-
-?>

=== removed file 'gpc/main.lib.php'
--- gpc/main.lib.php	2008-10-30 17:23:57 +0000
+++ gpc/main.lib.php	1970-01-01 00:00:00 +0000
@@ -1,13 +0,0 @@
-<?php
-
-/*
- * Anewt, Almost No Effort Web Toolkit, gpc module
- *
- * This code is copyrighted and distributed under the terms of the GNU LGPL.
- * See the README file for more information.
- */
-
-
-anewt_include('gpc/gpc');
-
-?>

=== modified file 'image/image.test.php'
--- image/image.test.php	2009-08-02 10:55:41 +0000
+++ image/image.test.php	2009-08-02 10:57:53 +0000
@@ -3,7 +3,6 @@
 error_reporting(E_ALL | E_STRICT);
 require_once '../anewt.lib.php';
 
-anewt_include('gpc');
 anewt_include('image');
 
 class AnewtImageTestCases {
@@ -207,7 +206,7 @@
 }
 
 
-$test = AnewtGPC::get_string('test');
+$test = AnewtRequest::get_string('test');
 
 if (is_null($test))
 {
@@ -219,7 +218,7 @@
 	$p->append(ax_h1('Choose a test'));
 	foreach (get_class_methods('AnewtImageTestCases') as $name)
 	{
-		$url = URL::unparse(
+		$url = AnewtURL::build(
 			AnewtRequest::relative_url(),
 			array('test' => $name));
 		$p->append(ax_p(ax_a_href(sprintf('Test: %s', $name), $url)));

=== modified file 'textile/textile.test.php'
--- textile/textile.test.php	2009-08-02 10:55:41 +0000
+++ textile/textile.test.php	2009-08-02 10:57:53 +0000
@@ -5,13 +5,12 @@
 
 define('ANEWT_TEXTILE_DEVELOPMENT', 1);
 
-anewt_include('gpc');
 anewt_include('page');
 
 $p = new AnewtPage();
 $p->set('title', 'Textile formatting test');
 
-if (AnewtGPC::get_bool('debug'))
+if (AnewtRequest::get_bool('debug'))
 {
 	header('Content-type: text/plain');
 	$p->set('content_type', 'text/plain');

=== modified file 'xml/dom.test.php'
--- xml/dom.test.php	2009-02-16 17:28:46 +0000
+++ xml/dom.test.php	2009-08-02 10:57:53 +0000
@@ -4,11 +4,10 @@
 require_once dirname(__FILE__) . '/../anewt.lib.php';
 
 anewt_include('xml/dom');
-anewt_include('gpc');
 
 $doc = new AnewtXMLDomDocument();
 
-if (AnewtGPC::get_bool('debug'))
+if (AnewtRequest::get_bool('debug'))
 	$doc->set_content_type('text/plain');
 
 $root = $doc->create_element('Toplevel', array('foo' => 'bar', 'bar' => '&baz'));