Source for file ClassesActionSource.class.php

Documentation is available at ClassesActionSource.class.php

  1. <?php
  2.  
  3. require_once (HARMONI."actionHandler/ActionSource.abstract.php");
  4.  
  5. /**
  6. * The ClassesActionSource looks for actions as classes located within include files.
  7. * The classes each have a special method as defined by {@link ACTIONS_CLASSES_METHOD}
  8. * which is called in order to execute the action.
  9. *
  10. * @package harmoni.actions.sources
  11. *
  12. * @copyright Copyright &copy; 2005, Middlebury College
  13. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  14. *
  15. * @version $Id: ClassesActionSource.class.php,v 1.11 2007/09/04 20:25:29 adamfranco Exp $
  16. */
  17. class ClassesActionSource
  18. extends ActionSource
  19. {
  20.  
  21. /**
  22. * @var string $_basePath The base path on the filesystem to look for module
  23. * folders.
  24. * @access private
  25. ***/
  26. var $_basePath;
  27. /**
  28. * @var string $_fileExtension The extension to add onto action names to locate
  29. * their associated files.
  30. * @access private
  31. ***/
  32. var $_fileExtension;
  33. /**
  34. * @var string $_classNameSuffix Suffix to append to the name of classes
  35. * @access private
  36. */
  37. var $_classNameSuffix;
  38. /**
  39. * Constructor
  40. * @param string $basePath The base path on the filesystem which contains the
  41. * module folders.
  42. * @param string $fileExtension The extension to add onto action names to find
  43. * the files, such that the action "welcome" might look for a file named
  44. * "welcome.class.php" with a file extension of ".class.php".
  45. * @param optional string $classNameSuffix A string to append to the names of
  46. * action classes to prevent namespace conflicts with libraries/other
  47. * classes. For example, with a suffix of 'Action', an action 'welcome'
  48. * would correspond to a class named 'welcomeAction'.
  49. *
  50. * @return void
  51. * @access public
  52. */
  53. function ClassesActionSource($basePath, $fileExtension, $classNameSuffix = '') {
  54. $this->_basePath = ereg_replace(DIRECTORY_SEPARATOR."$", "", $basePath);
  55. $this->_fileExtension = $fileExtension;
  56. $this->_classNameSuffix = $classNameSuffix;
  57. }
  58. /**
  59. * Checks to see if a given modules/action pair exists for execution within this source.
  60. * @param string $module
  61. * @param string $action
  62. * @access public
  63. * @return boolean
  64. */
  65. function actionExists($module, $action)
  66. {
  67. $fullPath = $this->_mkFullPath($module, $action);
  68. return file_exists($fullPath);
  69. }
  70. /**
  71. * Makes a full pathname to an action file.
  72. * @access private
  73. * @return string
  74. */
  75. function _mkFullPath($module, $action)
  76. {
  77. return $this->_basePath . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . $action . $this->_fileExtension;
  78. }
  79. /**
  80. * Executes the specified action in the specified module, using the Harmoni object as a base.
  81. * @param string $module The module in which to execute.
  82. * @param string $action The specific action to execute.
  83. * @param ref object $harmoni A reference to a {@link Harmoni} object.
  84. * @access public
  85. * @return ref mixed A {@link Layout} or TRUE/FALSE
  86. */
  87. function executeAction($module, $action, $harmoni)
  88. {
  89. $fullPath = $this->_mkFullPath($module, $action);
  90. if (!$this->actionExists($module, $action)) {
  91. throwError( new Error("ClassesActionSource::executeAction($module, $action) - could not proceed because the file to include does not exist!", "ActionHandler", true));
  92. }
  93. include_once($fullPath);
  94. $actionClassname = $action.$this->_classNameSuffix;
  95. if (!class_exists($actionClassname)) {
  96. throwError( new Error("ClassesActionSource::executeAction($module, $action) - could not proceed because the class name '$action' is not defined!","ActionHandler", true));
  97. }
  98. $class = new $actionClassname;
  99. $method = ACTIONS_CLASSES_METHOD;
  100. if (!method_exists($class, $method)) {
  101. throwError( new Error("ClassesActionSource::executeAction($module, $action) - could not proceed because the method '$method()' is not defined in the class '$action'!","ActionHandler", true));
  102. }
  103. $result =$class->$method($harmoni);
  104. return $result;
  105. }
  106. }

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