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.
 
 
 
 
 

70 lines
1.9 KiB

  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. {
  16. /** @var string the new action */
  17. protected $newaction;
  18. /** @var bool should the exception's message be shown to the user? */
  19. protected $displayToUser = false;
  20. /**
  21. * ActionException constructor.
  22. *
  23. * When no new action is given 'show' is assumed. For requests that originated in a POST,
  24. * a 'redirect' is used which will cause a redirect to the 'show' action.
  25. *
  26. * @param string|null $newaction the action that should be used next
  27. * @param string $message optional message, will not be shown except for some dub classes
  28. */
  29. public function __construct($newaction = null, $message = '')
  30. {
  31. global $INPUT;
  32. parent::__construct($message);
  33. if (is_null($newaction)) {
  34. if (strtolower($INPUT->server->str('REQUEST_METHOD')) == 'post') {
  35. $newaction = 'redirect';
  36. } else {
  37. $newaction = 'show';
  38. }
  39. }
  40. $this->newaction = $newaction;
  41. }
  42. /**
  43. * Returns the action to use next
  44. *
  45. * @return string
  46. */
  47. public function getNewAction()
  48. {
  49. return $this->newaction;
  50. }
  51. /**
  52. * Should this Exception's message be shown to the user?
  53. *
  54. * @param null|bool $set when null is given, the current setting is not changed
  55. * @return bool
  56. */
  57. public function displayToUser($set = null)
  58. {
  59. if (!is_null($set)) $this->displayToUser = $set;
  60. return $set;
  61. }
  62. }