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