Extbase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Validation / PropertyError.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * @package Extbase
30 * @subpackage Validation
31 * @version $Id: Error.php 1811 2009-01-28 12:04:49Z robert $
32 */
33
34 /**
35 * This object holds validation errors for one property.
36 *
37 * @package Extbase
38 * @subpackage Validation
39 * @version $Id: Error.php 1811 2009-01-28 12:04:49Z robert $
40 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
41 * @scope prototype
42 */
43 class Tx_Extbase_Validation_PropertyError extends Tx_Extbase_Validation_Error {
44
45 /**
46 * @var string The default (english) error message.
47 */
48 protected $message = 'Validation errors for property "%s"';
49
50 /**
51 * @var string The error code
52 */
53 protected $code = 1242859509;
54
55 /**
56 * @var string The property name
57 */
58 protected $propertyName;
59
60 /**
61 * @var array An array of Tx_Extbase_Validation_Error for the property
62 */
63 protected $errors = array();
64
65 /**
66 * Create a new property error with the given property name
67 *
68 * @param string $propertyName The property name
69 */
70 public function __construct($propertyName) {
71 $this->propertyName = $propertyName;
72 $this->message = sprintf($this->message, $propertyName);
73 }
74
75 /**
76 * Add errors
77 *
78 * @param array $errors Array of Tx_Extbase_Validation_Error for the property
79 * @return void
80 */
81 public function addErrors($errors) {
82 $this->errors = array_merge($this->errors, $errors);
83 }
84
85 /**
86 * Get all errors for the property
87 *
88 * @return array An array of Tx_Extbase_Validation_Error objects or an empty array if no errors occured for the property
89 */
90 public function getErrors() {
91 return $this->errors;
92 }
93
94 /**
95 * Get the property name
96 * @return string The property name for this error
97 */
98 public function getPropertyName() {
99 return $this->propertyName;
100 }
101 }
102
103 ?>