Source for file GETMethodRequestHandler.class.php

Documentation is available at GETMethodRequestHandler.class.php

  1. <?php
  2.  
  3. /**
  4. * @package harmoni.architecture.request
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: GETMethodRequestHandler.class.php,v 1.15 2007/09/04 20:25:31 adamfranco Exp $
  10. */
  11. require_once(HARMONI."architecture/request/RequestHandler.interface.php");
  12. require_once(HARMONI."architecture/request/URLWriter.abstract.php");
  13.  
  14. /**
  15. * The job of a RequestHandler is twofold:
  16. *
  17. * 1) handle incoming request data -- could be from $_REQUEST-type arrays,
  18. * could be from session variables, etc.
  19. * 2) handle the production of URLs with given contextual data/query using an
  20. * associated URLWriter class.
  21. *
  22. * @package harmoni.architecture.request
  23. *
  24. * @copyright Copyright &copy; 2005, Middlebury College
  25. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  26. *
  27. * @version $Id: GETMethodRequestHandler.class.php,v 1.15 2007/09/04 20:25:31 adamfranco Exp $
  28. */
  29.  
  30. class GETMethodRequestHandler extends RequestHandler {
  31. /**
  32. * Returns an associative array of key=value pairs corresponding to the request
  33. * data from the browser. This could just be the data from $_REQUEST, in the
  34. * simplest case.
  35. *
  36. * @return array
  37. * @access public
  38. */
  39. function getRequestVariables() {
  40. return array_merge($_GET, $_POST);
  41. }
  42. /**
  43. * Returns an associative array of file upload data. This will usually come from
  44. * the $_FILES superglobal.
  45. *
  46. * @return array
  47. * @access public
  48. */
  49. function getFileVariables() {
  50. return $_FILES;
  51. }
  52. /**
  53. * Returns a new {@link URLWriter} object corresponding to this RequestHandler.
  54. *
  55. * @return ref object URLWriter
  56. * @access public
  57. */
  58. function createURLWriter() {
  59. $writer = new GETMethodURLWriter();
  60. return $writer;
  61. }
  62. /**
  63. * Returns a dotted-pair string representing the module and action requested
  64. * by the end user ("module.action" format).
  65. *
  66. * @return string
  67. * @access public
  68. */
  69. function getRequestedModuleAction() {
  70. if (isset($_REQUEST["module"]))
  71. $mod = preg_replace('/[^a-zA-Z0-9_\-]/i', '', $_REQUEST["module"]);
  72. else
  73. $mod = NULL;
  74. if (isset($_REQUEST["action"]))
  75. $act = preg_replace('/[^a-zA-Z0-9_\-]/i', '', $_REQUEST["action"]);
  76. else
  77. $act = NULL;
  78. return $mod .".". $act;
  79. }
  80. }
  81.  
  82.  
  83. /**
  84. * The purpose of a URLWriter is to generate URLs from contextual data. This
  85. * data would be the current/target module and action, any contextual name=value
  86. * pairs specified by the code, and any additional query data.
  87. *
  88. * @package harmoni.architecture.request
  89. *
  90. * @copyright Copyright &copy; 2005, Middlebury College
  91. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  92. *
  93. * @version $Id: GETMethodRequestHandler.class.php,v 1.15 2007/09/04 20:25:31 adamfranco Exp $
  94. */
  95.  
  96. class GETMethodURLWriter
  97. extends URLWriter
  98. {
  99. /**
  100. * The following function has many forms, and due to PHP's lack of
  101. * method overloading they are all contained within the same class
  102. * method.
  103. *
  104. * write()
  105. * write(array $vars)
  106. * write(string $key1, string $value1, [string $key2, string $value2, [...]])
  107. *
  108. * @access public
  109. * @return string The URL.
  110. */
  111. function write(/* variable-length argument list*/) {
  112. if (!defined("MYURL")) {
  113. throwError( new Error("GETMethodURLWriter requires that 'MYURL' is defined and set to the full URL of the main index PHP script of this Harmoni program!", "GETMethodRequestHandler", true));
  114. }
  115. $num = func_num_args();
  116. $args = func_get_args();
  117. if ($num > 1 && $num % 2 == 0) {
  118. for($i = 0; $i < $num; $i+=2) {
  119. $this->_vars[RequestContext::name($args[$i])] = $args[$i+1];
  120. }
  121. } else if ($num == 1 && is_array($args[0])) {
  122. $this->setValues($args[0]);
  123. }
  124. $url = MYURL;
  125. $pairs = array();
  126. $harmoni = Harmoni::instance();
  127. if (!$harmoni->config->get("sessionUseOnlyCookies") && defined("SID") && SID)
  128. $pairs[] = strip_tags(SID);
  129. $pairs[] = "module=".$this->_module;
  130. $pairs[] = "action=".$this->_action;
  131. foreach ($this->_vars as $key=>$val) {
  132. if (is_object($val)) {
  133. throwError( new Error("Expecting string for key '$key', got '$val'.", "GETMethodRequestHandler", true));
  134. }
  135. $pairs[] = $key . "=" . urlencode($val);
  136. }
  137. $url .= "?" . implode("&amp;", $pairs);
  138. return $url;
  139. }
  140. }
  141.  
  142. ?>

Documentation generated on Wed, 19 Sep 2007 10:23:24 -0400 by phpDocumentor 1.3.0RC3