| 1 |
|
<?php |
| 2 |
|
/** |
| 3 |
|
* Xyster Framework |
| 4 |
|
* |
| 5 |
|
* This source file is subject to the new BSD license that is bundled |
| 6 |
|
* with this package in the file LICENSE.txt. |
| 7 |
|
* It is also available through the world-wide-web at this URL: |
| 8 |
|
* http://www.opensource.org/licenses/bsd-license.php |
| 9 |
|
* |
| 10 |
|
* @category Xyster |
| 11 |
|
* @package Xyster_Validate |
| 12 |
|
* @copyright Copyright LibreWorks, LLC (http://libreworks.net) |
| 13 |
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| 14 |
|
* @version $Id: Error.php 418 2010-10-18 21:40:08Z jonathanhawk $ |
| 15 |
|
*/ |
| 16 |
|
namespace Xyster\Validate; |
| 17 |
|
/** |
| 18 |
|
* A simple DTO for errors |
| 19 |
|
* |
| 20 |
|
* @category Xyster |
| 21 |
|
* @package Xyster_Validate |
| 22 |
|
* @copyright Copyright LibreWorks, LLC (http://libreworks.net) |
| 23 |
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| 24 |
|
*/ |
| 25 |
|
class Error |
| 26 |
|
{ |
| 27 |
|
/** |
| 28 |
|
* @var string |
| 29 |
|
*/ |
| 30 |
|
protected $_message; |
| 31 |
|
|
| 32 |
|
/** |
| 33 |
|
* @var string |
| 34 |
|
*/ |
| 35 |
|
protected $_field; |
| 36 |
|
|
| 37 |
|
/** |
| 38 |
|
* Creates a new error |
| 39 |
|
* |
| 40 |
|
* @param string $message |
| 41 |
|
* @param string $field |
| 42 |
|
* @param int $code |
| 43 |
|
*/ |
| 44 |
|
public function __construct( $message, $field = null ) |
| 45 |
|
{ |
| 46 |
7 |
$this->_message = $message; |
| 47 |
7 |
$this->_field = $field; |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
/** |
| 51 |
|
* Gets the message associated with the error |
| 52 |
|
* |
| 53 |
|
* @return string |
| 54 |
|
*/ |
| 55 |
|
public function getMessage() |
| 56 |
|
{ |
| 57 |
1 |
return $this->_message; |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
/** |
| 61 |
|
* Gets the field of the error, usually a field or property name |
| 62 |
|
* |
| 63 |
|
*/ |
| 64 |
|
public function getField() |
| 65 |
|
{ |
| 66 |
7 |
return $this->_field; |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
/** |
| 70 |
|
* Returns the string value of the object |
| 71 |
|
* |
| 72 |
|
* @return string |
| 73 |
|
*/ |
| 74 |
|
public function __toString() |
| 75 |
|
{ |
| 76 |
1 |
return ( $this->_field ) ? |
| 77 |
1 |
$this->_field . ': ' . $this->_message : $this->_message; |
| 78 |
|
} |
| 79 |
1 |
} |