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 1881f9e22bSAndreas Gohr /** @var string the new action */ 1964ab5140SAndreas Gohr protected $newaction; 2064ab5140SAndreas Gohr 2181f9e22bSAndreas Gohr /** @var bool should the exception's message be shown to the user? */ 2281f9e22bSAndreas Gohr protected $displayToUser = false; 2381f9e22bSAndreas Gohr 24e8aa6739SAndreas Gohr /** 25e8aa6739SAndreas Gohr * ActionException constructor. 26e8aa6739SAndreas Gohr * 27*58528803SAndreas Gohr * When no new action is given 'show' is assumed. For requests that originated in a POST, 28*58528803SAndreas Gohr * a 'redirect' is used which will cause a redirect to the 'show' action. 29*58528803SAndreas Gohr * 30*58528803SAndreas Gohr * @param string|null $newaction the action that should be used next 31e8aa6739SAndreas Gohr * @param string $message optional message, will not be shown except for some dub classes 32e8aa6739SAndreas Gohr */ 33*58528803SAndreas Gohr public function __construct($newaction = null, $message = '') { 34*58528803SAndreas Gohr global $INPUT; 3564ab5140SAndreas Gohr parent::__construct($message); 36*58528803SAndreas Gohr if(is_null($newaction)) { 37*58528803SAndreas Gohr if(strtolower($INPUT->server->str('REQUEST_METHOD')) == 'post') { 38*58528803SAndreas Gohr $newaction = 'redirect'; 39*58528803SAndreas Gohr } else { 40*58528803SAndreas Gohr $newaction = 'show'; 41*58528803SAndreas Gohr } 42*58528803SAndreas Gohr } 43*58528803SAndreas Gohr 4464ab5140SAndreas Gohr $this->newaction = $newaction; 4564ab5140SAndreas Gohr } 4664ab5140SAndreas Gohr 47e8aa6739SAndreas Gohr /** 48e8aa6739SAndreas Gohr * Returns the action to use next 49e8aa6739SAndreas Gohr * 50e8aa6739SAndreas Gohr * @return string 51e8aa6739SAndreas Gohr */ 5264ab5140SAndreas Gohr public function getNewAction() { 5364ab5140SAndreas Gohr return $this->newaction; 5464ab5140SAndreas Gohr } 5581f9e22bSAndreas Gohr 5681f9e22bSAndreas Gohr /** 5781f9e22bSAndreas Gohr * Should this Exception's message be shown to the user? 5881f9e22bSAndreas Gohr * 5981f9e22bSAndreas Gohr * @param null|bool $set when null is given, the current setting is not changed 6081f9e22bSAndreas Gohr * @return bool 6181f9e22bSAndreas Gohr */ 6281f9e22bSAndreas Gohr public function displayToUser($set = null) { 6381f9e22bSAndreas Gohr if(!is_null($set)) $this->displayToUser = $set; 6481f9e22bSAndreas Gohr return $set; 6581f9e22bSAndreas Gohr } 6664ab5140SAndreas Gohr} 67