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 */ 16*8c7c53b0SAndreas Gohrclass ActionException extends \Exception 17*8c7c53b0SAndreas 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 */ 3458528803SAndreas Gohr public function __construct($newaction = null, $message = '') { 3558528803SAndreas Gohr global $INPUT; 3664ab5140SAndreas Gohr parent::__construct($message); 3758528803SAndreas Gohr if(is_null($newaction)) { 3858528803SAndreas Gohr if(strtolower($INPUT->server->str('REQUEST_METHOD')) == 'post') { 3958528803SAndreas Gohr $newaction = 'redirect'; 4058528803SAndreas Gohr } else { 4158528803SAndreas Gohr $newaction = 'show'; 4258528803SAndreas Gohr } 4358528803SAndreas Gohr } 4458528803SAndreas Gohr 4564ab5140SAndreas Gohr $this->newaction = $newaction; 4664ab5140SAndreas Gohr } 4764ab5140SAndreas Gohr 48e8aa6739SAndreas Gohr /** 49e8aa6739SAndreas Gohr * Returns the action to use next 50e8aa6739SAndreas Gohr * 51e8aa6739SAndreas Gohr * @return string 52e8aa6739SAndreas Gohr */ 5364ab5140SAndreas Gohr public function getNewAction() { 5464ab5140SAndreas Gohr return $this->newaction; 5564ab5140SAndreas Gohr } 5681f9e22bSAndreas Gohr 5781f9e22bSAndreas Gohr /** 5881f9e22bSAndreas Gohr * Should this Exception's message be shown to the user? 5981f9e22bSAndreas Gohr * 6081f9e22bSAndreas Gohr * @param null|bool $set when null is given, the current setting is not changed 6181f9e22bSAndreas Gohr * @return bool 6281f9e22bSAndreas Gohr */ 6381f9e22bSAndreas Gohr public function displayToUser($set = null) { 6481f9e22bSAndreas Gohr if(!is_null($set)) $this->displayToUser = $set; 6581f9e22bSAndreas Gohr return $set; 6681f9e22bSAndreas Gohr } 6764ab5140SAndreas Gohr} 68