diff options
author | ahriman <ahriman@falte.red> | 2018-12-03 19:22:25 -0500 |
---|---|---|
committer | ahriman <ahriman@falte.red> | 2018-12-03 19:22:25 -0500 |
commit | 0ae8cbf5c0b1a198b963490985b7738392ebcb97 (patch) | |
tree | b2c77ae72c6b717e2b97492065196ac5ffb2d9e2 /wiki/inc/Action/Exception/ActionException.php | |
parent | f57f6cc5a2d159f90168d292437dc4bd8cd7f934 (diff) | |
download | site-0ae8cbf5c0b1a198b963490985b7738392ebcb97.tar.gz |
installed dokuwiki, added to navbar, updated news
Diffstat (limited to 'wiki/inc/Action/Exception/ActionException.php')
-rw-r--r-- | wiki/inc/Action/Exception/ActionException.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/wiki/inc/Action/Exception/ActionException.php b/wiki/inc/Action/Exception/ActionException.php new file mode 100644 index 0000000..381584c --- /dev/null +++ b/wiki/inc/Action/Exception/ActionException.php @@ -0,0 +1,66 @@ +<?php + +namespace dokuwiki\Action\Exception; + +/** + * Class ActionException + * + * This exception and its subclasses signal that the current action should be + * aborted and a different action should be used instead. The new action can + * be given as parameter in the constructor. Defaults to 'show' + * + * The message will NOT be shown to the enduser + * + * @package dokuwiki\Action\Exception + */ +class ActionException extends \Exception { + + /** @var string the new action */ + protected $newaction; + + /** @var bool should the exception's message be shown to the user? */ + protected $displayToUser = false; + + /** + * ActionException constructor. + * + * When no new action is given 'show' is assumed. For requests that originated in a POST, + * a 'redirect' is used which will cause a redirect to the 'show' action. + * + * @param string|null $newaction the action that should be used next + * @param string $message optional message, will not be shown except for some dub classes + */ + public function __construct($newaction = null, $message = '') { + global $INPUT; + parent::__construct($message); + if(is_null($newaction)) { + if(strtolower($INPUT->server->str('REQUEST_METHOD')) == 'post') { + $newaction = 'redirect'; + } else { + $newaction = 'show'; + } + } + + $this->newaction = $newaction; + } + + /** + * Returns the action to use next + * + * @return string + */ + public function getNewAction() { + return $this->newaction; + } + + /** + * Should this Exception's message be shown to the user? + * + * @param null|bool $set when null is given, the current setting is not changed + * @return bool + */ + public function displayToUser($set = null) { + if(!is_null($set)) $this->displayToUser = $set; + return $set; + } +} |