xref: /dokuwiki/inc/Action/Exception/ActionException.php (revision 81f9e22b2e291e7d7b0156600c1f0dd4591fd4f8)
164ab5140SAndreas Gohr<?php
264ab5140SAndreas Gohr
364ab5140SAndreas Gohrnamespace dokuwiki\Action\Exception;
464ab5140SAndreas Gohr
5e8aa6739SAndreas Gohr/**
6e8aa6739SAndreas Gohr * Class ActionException
7e8aa6739SAndreas Gohr *
8e8aa6739SAndreas Gohr * This exception and its subclasses signal that the current action should be
9e8aa6739SAndreas Gohr * aborted and a different action should be used instead. The new action can
10e8aa6739SAndreas Gohr * be given as parameter in the constructor. Defaults to 'show'
11e8aa6739SAndreas Gohr *
12e8aa6739SAndreas Gohr * The message will NOT be shown to the enduser
13e8aa6739SAndreas Gohr *
14e8aa6739SAndreas Gohr * @package dokuwiki\Action\Exception
15e8aa6739SAndreas Gohr */
1664ab5140SAndreas Gohrclass ActionException extends \Exception {
1764ab5140SAndreas Gohr
18*81f9e22bSAndreas Gohr    /** @var string the new action */
1964ab5140SAndreas Gohr    protected $newaction;
2064ab5140SAndreas Gohr
21*81f9e22bSAndreas Gohr    /** @var bool should the exception's message be shown to the user? */
22*81f9e22bSAndreas Gohr    protected $displayToUser = false;
23*81f9e22bSAndreas Gohr
24e8aa6739SAndreas Gohr    /**
25e8aa6739SAndreas Gohr     * ActionException constructor.
26e8aa6739SAndreas Gohr     *
27e8aa6739SAndreas Gohr     * @param string $newaction the action that should be used next
28e8aa6739SAndreas Gohr     * @param string $message optional message, will not be shown except for some dub classes
29e8aa6739SAndreas Gohr     */
3064ab5140SAndreas Gohr    public function __construct($newaction = 'show', $message = '') {
3164ab5140SAndreas Gohr        parent::__construct($message);
3264ab5140SAndreas Gohr        $this->newaction = $newaction;
3364ab5140SAndreas Gohr    }
3464ab5140SAndreas Gohr
35e8aa6739SAndreas Gohr    /**
36e8aa6739SAndreas Gohr     * Returns the action to use next
37e8aa6739SAndreas Gohr     *
38e8aa6739SAndreas Gohr     * @return string
39e8aa6739SAndreas Gohr     */
4064ab5140SAndreas Gohr    public function getNewAction() {
4164ab5140SAndreas Gohr        return $this->newaction;
4264ab5140SAndreas Gohr    }
43*81f9e22bSAndreas Gohr
44*81f9e22bSAndreas Gohr    /**
45*81f9e22bSAndreas Gohr     * Should this Exception's message be shown to the user?
46*81f9e22bSAndreas Gohr     *
47*81f9e22bSAndreas Gohr     * @param null|bool $set when null is given, the current setting is not changed
48*81f9e22bSAndreas Gohr     * @return bool
49*81f9e22bSAndreas Gohr     */
50*81f9e22bSAndreas Gohr    public function displayToUser($set = null) {
51*81f9e22bSAndreas Gohr        if(!is_null($set)) $this->displayToUser = $set;
52*81f9e22bSAndreas Gohr        return $set;
53*81f9e22bSAndreas Gohr    }
5464ab5140SAndreas Gohr}
55