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 */ 168c7c53b0SAndreas Gohrclass ActionException extends \Exception 178c7c53b0SAndreas Gohr{ 1864ab5140SAndreas Gohr 1981f9e22bSAndreas Gohr /** @var string the new action */ 2064ab5140SAndreas Gohr protected $newaction; 2164ab5140SAndreas Gohr 2281f9e22bSAndreas Gohr /** @var bool should the exception's message be shown to the user? */ 2381f9e22bSAndreas Gohr protected $displayToUser = false; 2481f9e22bSAndreas Gohr 25e8aa6739SAndreas Gohr /** 26e8aa6739SAndreas Gohr * ActionException constructor. 27e8aa6739SAndreas Gohr * 2858528803SAndreas Gohr * When no new action is given 'show' is assumed. For requests that originated in a POST, 2958528803SAndreas Gohr * a 'redirect' is used which will cause a redirect to the 'show' action. 3058528803SAndreas Gohr * 3158528803SAndreas Gohr * @param string|null $newaction the action that should be used next 32e8aa6739SAndreas Gohr * @param string $message optional message, will not be shown except for some dub classes 33e8aa6739SAndreas Gohr */ 34*d868eb89SAndreas Gohr public function __construct($newaction = null, $message = '') 35*d868eb89SAndreas Gohr { 3658528803SAndreas Gohr global $INPUT; 3764ab5140SAndreas Gohr parent::__construct($message); 3858528803SAndreas Gohr if(is_null($newaction)) { 3958528803SAndreas Gohr if(strtolower($INPUT->server->str('REQUEST_METHOD')) == 'post') { 4058528803SAndreas Gohr $newaction = 'redirect'; 4158528803SAndreas Gohr } else { 4258528803SAndreas Gohr $newaction = 'show'; 4358528803SAndreas Gohr } 4458528803SAndreas Gohr } 4558528803SAndreas Gohr 4664ab5140SAndreas Gohr $this->newaction = $newaction; 4764ab5140SAndreas Gohr } 4864ab5140SAndreas Gohr 49e8aa6739SAndreas Gohr /** 50e8aa6739SAndreas Gohr * Returns the action to use next 51e8aa6739SAndreas Gohr * 52e8aa6739SAndreas Gohr * @return string 53e8aa6739SAndreas Gohr */ 54*d868eb89SAndreas Gohr public function getNewAction() 55*d868eb89SAndreas Gohr { 5664ab5140SAndreas Gohr return $this->newaction; 5764ab5140SAndreas Gohr } 5881f9e22bSAndreas Gohr 5981f9e22bSAndreas Gohr /** 6081f9e22bSAndreas Gohr * Should this Exception's message be shown to the user? 6181f9e22bSAndreas Gohr * 6281f9e22bSAndreas Gohr * @param null|bool $set when null is given, the current setting is not changed 6381f9e22bSAndreas Gohr * @return bool 6481f9e22bSAndreas Gohr */ 65*d868eb89SAndreas Gohr public function displayToUser($set = null) 66*d868eb89SAndreas Gohr { 6781f9e22bSAndreas Gohr if(!is_null($set)) $this->displayToUser = $set; 6881f9e22bSAndreas Gohr return $set; 6981f9e22bSAndreas Gohr } 7064ab5140SAndreas Gohr} 71