Source for file FlatFileActionSource.class.php

Documentation is available at FlatFileActionSource.class.php

  1. <?php
  2.  
  3.  
  4. require_once HARMONI."actionHandler/ActionSource.abstract.php";
  5.  
  6. /**
  7. * The FlatFileActionSource class allows one to execute Harmoni actions (see {@link ActionHandler}) which are contained within
  8. * flat files. Modules exist as folders on the file system, and actions exist as PHP source files within those folders. They may
  9. * be organized like so: <p>
  10. * basepath/user/login.act.php
  11. * basepath/user/logout.act.php
  12. * basepath/main/welcome.act.php
  13. * <p>
  14. * In this example, the base path would be "basepath/", and the actions file extension would be ".act.php".
  15. *
  16. * @package harmoni.actions.sources
  17. *
  18. * @copyright Copyright &copy; 2005, Middlebury College
  19. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  20. *
  21. * @version $Id: FlatFileActionSource.class.php,v 1.7 2007/09/04 20:25:29 adamfranco Exp $
  22. */
  23. class FlatFileActionSource extends ActionSource{
  24.  
  25. /**
  26. * @var string $_basePath The base path on the filesystem to look for module folders.
  27. * @access private
  28. ***/
  29. var $_basePath;
  30. /**
  31. * @var string $_fileExtension The extension to add onto action names to locate their associated files.
  32. * @access private
  33. ***/
  34. var $_fileExtension;
  35. /**
  36. * Constructor
  37. * @param string $basePath The base path on the filesystem which contains the module folders.
  38. * @param string $fileExtension The extension to add onto action names to find the files, such that
  39. * the action "welcome" might look for a file named "welcome.act.php" with a file extension of ".act.php".
  40. * @return void
  41. * @access public
  42. */
  43. function FlatFileActionSource($basePath, $fileExtension=".php") {
  44. // $this->_basePath = ereg_replace(DIRECTORY_SEPARATOR."$", "", $basePath);
  45. $this->_basePath = $basePath;
  46. $this->_fileExtension = $fileExtension;
  47. }
  48. /**
  49. * Checks to see if a given modules/action pair exists for execution within this source.
  50. * @param string $module
  51. * @param string $action
  52. * @access public
  53. * @return boolean
  54. */
  55. function actionExists($module, $action)
  56. {
  57. $fullPath = $this->_mkFullPath($module, $action);
  58. return file_exists($fullPath);
  59. }
  60. /**
  61. * Makes a full pathname to an action file.
  62. * @access private
  63. * @return string
  64. */
  65. function _mkFullPath($module, $action)
  66. {
  67. return $this->_basePath . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . $action . $this->_fileExtension;
  68. }
  69. /**
  70. * Executes the specified action in the specified module, using the Harmoni object as a base.
  71. * @param string $module The module in which to execute.
  72. * @param string $action The specific action to execute.
  73. * @param ref object $harmoni A reference to a {@link Harmoni} object.
  74. * @access public
  75. * @return ref mixed A {@link Layout} or TRUE/FALSE
  76. */
  77. function executeAction($module, $action, $harmoni)
  78. {
  79. $fullPath = $this->_mkFullPath($module, $action);
  80. if (!$this->actionExists($module, $action)) {
  81. throwError( new Error("FlatFileActionSource::executeAction($module, $action) - could not proceed because the file to include does not exist!", "ActionHandler", true));
  82. }
  83. $result = include($fullPath);
  84. return $result;
  85. }
  86. }

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