ValidationException.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\validation;
12 
13 /**
14  * ValidationException signals an exception in validation.
15  *
16  * @author ingo herwig <ingo@wemove.com>
17  */
18 class ValidationException extends \Exception {
19 
20  private $field = null;
21  private $value = null;
22 
23  /**
24  * Constructor
25  * @param $field The name of the field
26  * @param $value The value of the field
27  * @param $message The error message
28  * @param $code The error code
29  * @param $previous The previous Exception
30  */
31  public function __construct($field, $value, $message="", $code=0, \Exception $previous=null) {
32  parent::__construct($message, $code, $previous);
33  $this->field = $field;
34  $this->value = $value;
35  }
36 
37  /**
38  * Get the name of the field
39  * @return String
40  */
41  public function getField() {
42  return $this->field;
43  }
44 
45  /**
46  * Get the value of the field
47  * @return String
48  */
49  public function getValue() {
50  return $this->value;
51  }
52 
53  /**
54  * Get a string representation of the exception
55  * @return String
56  */
57  public function __toString() {
58  $msg = '';
59  if ($this->field != null) {
60  $msg .= 'Invalid value ('.$this->value.') for '.$this->field.': ';
61  }
62  return $msg.$this->getMessage();
63  }
64 }
65 ?>
ValidationException signals an exception in validation.
__toString()
Get a string representation of the exception.
__construct($field, $value, $message="", $code=0, \Exception $previous=null)
Constructor.