ActionException.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace dokuwiki\Action\Exception;
  3. /**
  4. * Class ActionException
  5. *
  6. * This exception and its subclasses signal that the current action should be
  7. * aborted and a different action should be used instead. The new action can
  8. * be given as parameter in the constructor. Defaults to 'show'
  9. *
  10. * The message will NOT be shown to the enduser
  11. *
  12. * @package dokuwiki\Action\Exception
  13. */
  14. class ActionException extends \Exception {
  15. /** @var string the new action */
  16. protected $newaction;
  17. /** @var bool should the exception's message be shown to the user? */
  18. protected $displayToUser = false;
  19. /**
  20. * ActionException constructor.
  21. *
  22. * When no new action is given 'show' is assumed. For requests that originated in a POST,
  23. * a 'redirect' is used which will cause a redirect to the 'show' action.
  24. *
  25. * @param string|null $newaction the action that should be used next
  26. * @param string $message optional message, will not be shown except for some dub classes
  27. */
  28. public function __construct($newaction = null, $message = '') {
  29. global $INPUT;
  30. parent::__construct($message);
  31. if(is_null($newaction)) {
  32. if(strtolower($INPUT->server->str('REQUEST_METHOD')) == 'post') {
  33. $newaction = 'redirect';
  34. } else {
  35. $newaction = 'show';
  36. }
  37. }
  38. $this->newaction = $newaction;
  39. }
  40. /**
  41. * Returns the action to use next
  42. *
  43. * @return string
  44. */
  45. public function getNewAction() {
  46. return $this->newaction;
  47. }
  48. /**
  49. * Should this Exception's message be shown to the user?
  50. *
  51. * @param null|bool $set when null is given, the current setting is not changed
  52. * @return bool
  53. */
  54. public function displayToUser($set = null) {
  55. if(!is_null($set)) $this->displayToUser = $set;
  56. return $set;
  57. }
  58. }