Source for file URLWriter.abstract.php

Documentation is available at URLWriter.abstract.php

  1. <?php
  2.  
  3. /**
  4. * The purpose of a URLWriter is to generate URLs from contextual data. This
  5. * data would be the current/target module and action, any contextual name=value
  6. * pairs specified by the code, and any additional query data.
  7. *
  8. * @package harmoni.architecture.request
  9. *
  10. * @copyright Copyright &copy; 2005, Middlebury College
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  12. *
  13. * @version $Id: URLWriter.abstract.php,v 1.7 2007/09/04 20:25:31 adamfranco Exp $
  14. */
  15.  
  16. class URLWriter
  17. extends SObject
  18. {
  19.  
  20. var $_module;
  21. var $_action;
  22. var $_vars;
  23. function URLWriter() {
  24. $this->_vars = array();
  25. $this->_module = "";
  26. $this->_action = "";
  27. }
  28.  
  29. /**
  30. * Sets the module and action to request in this URL.
  31. * @param string $module
  32. * @param string $action
  33. * @return void
  34. * @access public
  35. */
  36. function setModuleAction($module, $action) {
  37. $this->_module = $module;
  38. $this->_action = $action;
  39. }
  40. /**
  41. * Takes an associative array of name/value pairs and sets the internal data
  42. * to those values. The method is used internally by the {@link RequestContext}
  43. * only and should not be called otherwise.
  44. * @param array $array
  45. * @access private
  46. * @return void
  47. */
  48. function batchSetValues($array) {
  49. foreach ($array as $key=>$val) {
  50. if (!in_array($key, array("module", "action")))
  51. $this->_vars[$key] = $val;
  52. }
  53. }
  54.  
  55. /**
  56. * Takes an associative array of name/value pairs and sets the internal
  57. * data to those values, replacing any values that already exist.
  58. * @param array $array An associative array.
  59. * @return void
  60. * @access public
  61. */
  62. function setValues($array) {
  63. foreach ($array as $key=>$val) {
  64. $this->setValue($key, $val);
  65. }
  66. }
  67. /**
  68. * Sets a single value in the internal data.
  69. * @param string $key
  70. * @param string $value
  71. * @return void
  72. * @access public
  73. */
  74. function setValue($key, $value) {
  75. $key = RequestContext::name($key);
  76. $this->_vars[$key] = $value;
  77. }
  78. /**
  79. * Calls {@link RequestContext::locationHeader} with this URL.
  80. *
  81. * @return void
  82. ***/
  83. function redirectBrowser()
  84. {
  85. $harmoni = Harmoni::instance();
  86. $harmoni->request->locationHeader($this->write());
  87. }
  88. /**
  89. * The following function has many forms, and due to PHP's lack of
  90. * method overloading they are all contained within the same class
  91. * method. Any keys/names for paremeters should be translated into
  92. * their contextual equivalents by contacting the {@link RequestContext}
  93. * object.
  94. *
  95. * write()
  96. * write(array $vars)
  97. * write(string $key1, string $value1, [string $key2, string $value2, [...]])
  98. *
  99. * @access public
  100. * @return string The URL.
  101. */
  102. function write(/* variable-length argument list*/) {
  103. throwError(new Error("Method <b>".__FUNCTION__."()</b> declared in abstract class <b> ".__CLASS__."</b> has not been overloaded in a child class.","RequestHandler",true));
  104. }
  105. }
  106.  
  107. ?>

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