Merge branch '3.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / exception / ValidateActionException.class.php
CommitLineData
158bd3ca
TD
1<?php
2namespace wcf\system\exception;
3631f7bd 3use wcf\system\WCF;
158bd3ca
TD
4
5/**
a79cfb56
AE
6 * Simple exception for AJAX-driven requests.
7 *
8 * @author Alexander Ebert
c839bd49 9 * @copyright 2001-2018 WoltLab GmbH
a79cfb56 10 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
e71525e4 11 * @package WoltLabSuite\Core\System\Exception
158bd3ca
TD
12 */
13class ValidateActionException extends \Exception {
3631f7bd
AE
14 /**
15 * error message
16 * @var string
17 */
18 protected $errorMessage = '';
19
20 /**
21 * erroneous field name
22 * @var string
23 */
24 protected $fieldName = '';
25
a79cfb56 26 /**
0fcfe5f6 27 * @inheritDoc
a79cfb56 28 */
058cbd6a 29 public function __construct($fieldName, $errorMessage = 'empty', array $variables = []) {
3631f7bd 30 $this->errorMessage = $errorMessage;
838e315b 31 if (mb_strpos($this->errorMessage, '.') === false) {
3d683a68 32 if (preg_match('~^[a-zA-Z0-9-_]+$~', $this->errorMessage)) {
7aeb62cb 33 $this->errorMessage = WCF::getLanguage()->getDynamicVariable('wcf.global.form.error.'.$this->errorMessage);
312bb4b3 34 }
3631f7bd
AE
35 }
36 else {
37 $this->errorMessage = WCF::getLanguage()->getDynamicVariable($this->errorMessage, $variables);
38 }
39
40 $this->fieldName = $fieldName;
058cbd6a 41 $this->message = WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.invalidParameter', ['fieldName' => $this->fieldName]);
3631f7bd
AE
42 }
43
44 /**
45 * Returns error message.
46 *
47 * @return string
48 */
49 public function getErrorMessage() {
50 return $this->errorMessage;
51 }
52
53 /**
54 * Returns erroneous field name.
55 *
56 * @return string
57 */
58 public function getFieldName() {
59 return $this->fieldName;
9f945556
AE
60 }
61
62 /**
0fcfe5f6 63 * @inheritDoc
9f945556
AE
64 */
65 public function __toString() {
66 return $this->message;
158bd3ca 67 }
dcb3a44c 68}