You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

94 lines
2.2 KiB

  1. <?php
  2. namespace dokuwiki\Action;
  3. use dokuwiki\Action\Exception\ActionException;
  4. use dokuwiki\Action\Exception\FatalException;
  5. /**
  6. * Class AbstractAction
  7. *
  8. * Base class for all actions
  9. *
  10. * @package dokuwiki\Action
  11. */
  12. abstract class AbstractAction
  13. {
  14. /** @var string holds the name of the action (lowercase class name, no namespace) */
  15. protected $actionname;
  16. /**
  17. * AbstractAction constructor.
  18. *
  19. * @param string $actionname the name of this action (see getActionName() for caveats)
  20. */
  21. public function __construct($actionname = '')
  22. {
  23. if ($actionname !== '') {
  24. $this->actionname = $actionname;
  25. } else {
  26. // http://stackoverflow.com/a/27457689/172068
  27. $this->actionname = strtolower(substr(strrchr(get_class($this), '\\'), 1));
  28. }
  29. }
  30. /**
  31. * Return the minimum permission needed
  32. *
  33. * This needs to return one of the AUTH_* constants. It will be checked against
  34. * the current user and page after checkPermissions() ran through. If it fails,
  35. * the user will be shown the Denied action.
  36. *
  37. * @return int
  38. */
  39. abstract public function minimumPermission();
  40. /**
  41. * Check conditions are met to run this action
  42. *
  43. * @throws ActionException
  44. * @return void
  45. */
  46. public function checkPreconditions()
  47. {
  48. }
  49. /**
  50. * Process data
  51. *
  52. * This runs before any output is sent to the browser.
  53. *
  54. * Throw an Exception if a different action should be run after this step.
  55. *
  56. * @throws ActionException
  57. * @return void
  58. */
  59. public function preProcess()
  60. {
  61. }
  62. /**
  63. * Output whatever content is wanted within tpl_content();
  64. *
  65. * @fixme we may want to return a Ui class here
  66. * @throws FatalException
  67. */
  68. public function tplContent()
  69. {
  70. throw new FatalException('No content for Action ' . $this->actionname);
  71. }
  72. /**
  73. * Returns the name of this action
  74. *
  75. * This is usually the lowercased class name, but may differ for some actions.
  76. * eg. the export_ modes or for the Plugin action.
  77. *
  78. * @return string
  79. */
  80. public function getActionName()
  81. {
  82. return $this->actionname;
  83. }
  84. }